-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamop_test.py
executable file
·102 lines (90 loc) · 3.19 KB
/
amop_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/python
import unittest
import Amop
class AmopTest(unittest.TestCase):
def test_option_price_call_american_binomial(self):
S = 100
K = 100
r = 0.10
sigma = 0.25
time = 1.0
steps = 100
test_val = Amop.option_price_call_american_binomial(S, K, r, sigma, time, steps)
self.assertEqual(str(round(test_val, 4)), "14.9505")
# Test 2
S = 72
K = 72
r = 0.05
sigma = 0.40
time = 0.5
steps = 200
test_val = Amop.option_price_call_american_binomial(S, K, r, sigma, time, steps)
self.assertEqual(str(round(test_val, 5)), "8.90719")
def test_option_price_put_american_binomial(self):
S = 100
K = 100
r = 0.10
sigma = 0.25
time = 1.0
steps = 100
test_val = Amop.option_price_put_american_binomial(S, K, r, sigma, time, steps)
self.assertEqual(str(round(test_val, 5)), "6.54691")
# Test 2
S = 72
K = 72
r = 0.05
sigma = 0.40
time = 0.5
steps = 200
test_val = Amop.option_price_put_american_binomial(S, K, r, sigma, time, steps)
self.assertEqual(str(round(test_val, 5)), "7.29582")
def test_option_price_call_american_discrete_dividends_binomial(self):
S = 100
K = 100
r = 0.10
sigma = 0.25
time = 1.0
steps = 100
dividend_times = [0.25, 0.75]
dividend_amounts = [2.5, 2.5]
test_val = Amop.option_price_call_american_discrete_dividends_binomial(S, K,
r, sigma, time, steps, dividend_times, dividend_amounts)
self.assertEqual(str(round(test_val, 4)), "12.0233")
def test_option_price_put_american_discrete_dividends_binomial(self):
S = 100
K = 100
r = 0.10
sigma = 0.25
time = 1.0
steps = 100
dividend_times = [0.25, 0.75]
dividend_amounts = [2.5, 2.5]
test_val = Amop.option_price_put_american_discrete_dividends_binomial(S, K,
r, sigma, time, steps, dividend_times, dividend_amounts)
self.assertEqual(str(round(test_val, 5)), "8.11801")
def test_option_price_call_american_proportional_dividends_binomial(self):
S = 100
K = 100
r = 0.10
sigma = 0.25
time = 1.0
steps = 100
dividend_times = [0.25, 0.75]
dividend_yields = [0.025, 0.025]
test_val = Amop.option_price_call_american_proportional_dividends_binomial(S,
K, r, sigma, time, steps, dividend_times, dividend_yields)
self.assertEqual(str(round(test_val, 4)), "11.8604")
def test_option_price_put_american_proportional_dividends_binomial(self):
S = 100
K = 100
r = 0.10
sigma = 0.25
time = 1.0
steps = 100
dividend_times = [0.25, 0.75]
dividend_yields = [0.025, 0.025]
test_val = Amop.option_price_put_american_proportional_dividends_binomial(S,
K, r, sigma, time, steps, dividend_times, dividend_yields)
self.assertEqual(str(round(test_val, 5)), "7.99971")
if __name__ == '__main__':
unittest.main()