-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmenu.py
More file actions
80 lines (78 loc) · 4.86 KB
/
Copy pathmenu.py
File metadata and controls
80 lines (78 loc) · 4.86 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
from black_scholes import BlackScholes
def display_menu():
print("Which Black-Scholes formula would you like to use?")
print("1. Call Option Price")
print("2. Put Option Price")
print("3. Probability Call Option in the Money")
print("4. Probability Put Option in the Money")
print("5. Call Option Implied Volatility")
print("6. Put Option Implied Volatility")
def process_choice(choice):
if choice == 1:
print("Recall: S = Stock Price, K = Strike Price, T = Time to Expiration (in years), r = Risk-Free Interest Rate, sigma = Volatility")
inputs = input("Enter S, K, T, r, sigma separated by spaces: ").split()
S = float(inputs[0])
K = float(inputs[1])
T = float(inputs[2])
r = float(inputs[3])
sigma = float(inputs[4])
call_price = BlackScholes.call_price(S, K, T, r, sigma)
print(f"Call Option Price: {call_price}")
print(f"The price of a call option is {call_price} for stock price {S}, strike price {K}, time to expiration {T} years, risk-free rate {r}, and volatility {sigma}.")
elif choice == 2:
print("Recall: S = Stock Price, K = Strike Price, T = Time to Expiration (in years), r = Risk-Free Interest Rate, sigma = Volatility")
inputs = input("Enter S, K, T, r, sigma separated by spaces: ").split()
S = float(inputs[0])
K = float(inputs[1])
T = float(inputs[2])
r = float(inputs[3])
sigma = float(inputs[4])
put_price = BlackScholes.put_price(S, K, T, r, sigma)
print(f"Put Option Price: {put_price}")
print(f"The price of a put option is {put_price} for stock price {S}, strike price {K}, time to expiration {T} years, risk-free rate {r}, and volatility {sigma}.")
elif choice == 3:
print("Recall: S = Stock Price, K = Strike Price, T = Time to Expiration (in years), r = Risk-Free Interest Rate, sigma = Volatility")
inputs = input("Enter S, K, T, r, sigma separated by spaces: ").split()
S = float(inputs[0])
K = float(inputs[1])
T = float(inputs[2])
r = float(inputs[3])
sigma = float(inputs[4])
prob_call = BlackScholes.call_in_the_money(S, K, T, r, sigma)
print(f"Probability Call Option in the Money: {prob_call}")
print(f"The probability that a call option will be in the money at expiration is {prob_call} for stock price {S}, strike price {K}, time to expiration {T} years, risk-free rate {r}, and volatility {sigma}.")
elif choice == 4:
print("Recall: S = Stock Price, K = Strike Price, T = Time to Expiration (in years), r = Risk-Free Interest Rate, sigma = Volatility")
inputs = input("Enter S, K, T, r, sigma separated by spaces: ").split()
S = float(inputs[0])
K = float(inputs[1])
T = float(inputs[2])
r = float(inputs[3])
sigma = float(inputs[4])
prob_put = BlackScholes.put_in_the_money(S, K, T, r, sigma)
print(f"Probability Put Option in the Money: {prob_put}")
print(f"The probability that a put option will be in the money at expiration is {prob_put} for stock price {S}, strike price {K}, time to expiration {T} years, risk-free rate {r}, and volatility {sigma}.")
elif choice == 5:
print("Recall: S = Stock Price, K = Strike Price, T = Time to Expiration (in years), r = Risk-Free Interest Rate, market_price = Market Price of Option")
inputs = input("Enter market_price, S, K, T, r separated by spaces: ").split()
market_price = float(inputs[0])
S = float(inputs[1])
K = float(inputs[2])
T = float(inputs[3])
r = float(inputs[4])
implied_vol = BlackScholes.call_implied_volatility(market_price, S, K, T, r)
print(f"Call Option Implied Volatility: {implied_vol}")
print(f"The implied volatility for a call option with market price {market_price}, stock price {S}, strike price {K}, time to expiration {T} years, and risk-free rate {r} is {implied_vol}.")
elif choice == 6:
print("Recall: S = Stock Price, K = Strike Price, T = Time to Expiration (in years), r = Risk-Free Interest Rate, market_price = Market Price of Option")
inputs = input("Enter market_price, S, K, T, r separated by spaces: ").split()
market_price = float(inputs[0])
S = float(inputs[1])
K = float(inputs[2])
T = float(inputs[3])
r = float(inputs[4])
implied_vol = BlackScholes.put_implied_volatility(market_price, S, K, T, r)
print(f"Put Option Implied Volatility: {implied_vol}")
print(f"The implied volatility for a put option with market price {market_price}, stock price {S}, strike price {K}, time to expiration {T} years, and risk-free rate {r} is {implied_vol}.")
else:
print("Invalid choice. Please select a valid formula number.")