-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.py
More file actions
105 lines (77 loc) · 2.45 KB
/
Copy pathmain.py
File metadata and controls
105 lines (77 loc) · 2.45 KB
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
103
104
105
# Import Black Scholes Model
from LeastSquaresMonteCarlo import LSMC
# Estimate Delta by drifting the random path
def estimate_delta(Model, dS):
price = Model.Price
# Shift the path
Model.randomWalk *= 1 + dS
# pricing
Model.pricing()
Delta = (Model.Price - price) / (Model.spot_price * dS)
print("")
print("-----------------------------")
print(f"Price of {Model.type} after {dS} shift: {Model.Price}")
print(f"Stdandard deviation after {dS} shift: {Model.std}")
print(f"Root Mean Sqaure Relative Error after {dS} shift: {Model.rmsre}")
print(f"Estimated Delta of {Model.type}: {Delta}")
print("-----------------------------")
print("")
# main function
def main():
# Determine the type of American Option
print("Enter the type of American Option, Put or Call")
while True:
type = input(">>> ").lower()
if type == "put" or type == "call" or type == "p" or type == "c":
type = type[0]
break
print("Enter Put or Call!!!")
# take in the input from user
print("")
print(
"Enter: spot price, strike price, time interval, interest(%), dividend(%), volatility(%), period, stimulations"
)
while True:
try:
(
spot,
strike,
time,
interest,
dividend,
volatility,
period,
simulations,
) = map(float, input(">>> ").split())
break
except:
print("WRONG FORMAT!!!")
Model = LSMC(
type, spot, strike, time, interest, dividend, volatility, period, simulations
)
# Calculating Price
Model.random_path()
Model.pricing()
type = "Put" if type == "p" else "Call"
print("")
print("-----------------------------")
print(f"Price of {type}: {Model.Price}")
print(f"Stdandard deviation: {Model.std}")
print(f"Root Mean Sqaure Relative Error: {Model.rmsre}")
print("-----------------------------")
print("")
print(Model.randomWalk[:, -1])
# Plot distribution
Model.plot()
print(
"Enter the dS (porportion) to shift the Random Path to estimate delta. Better to have 0 < dS <= 0.1"
)
while True:
try:
dS = float(input(">>> "))
break
except:
print("Invalid Input!!!")
estimate_delta(Model, dS)
if __name__ == "__main__":
main()