-
Notifications
You must be signed in to change notification settings - Fork 7
Description
import math
import numpy as np
def d1(S, K, r, sigma, T):
return (math.log(S/K) + (r + 0.5 * sigma**2) * T) / (sigma * math.sqrt(T))
def d2(S, K, r, sigma, T):
return d1(S, K, r, sigma, T) - sigma * math.sqrt(T)
def BSM_call_price(S, K, r, sigma, T):
return S * math.norm.cdf(d1(S, K, r, sigma, T)) - K * math.exp(-r * T) * math.norm.cdf(d2(S, K, r, sigma, T))
def MC_call_price(S, K, r, sigma, T, M):
dt = T/M
total = 0
for i in range(M):
total += max(S * np.exp((r - 0.5 * sigma**2) * (dt * (i + 1)) + sigma * np.sqrt(dt) * np.random.standard_normal()) - K, 0)
return total/M * np.exp(-r * T)
def MC_call_price_sim(S, K, r, sigma, T, M):
dt = T/M
total = 0
for i in range(M):
S_sim = S * np.exp((r - 0.5 * sigma**2) * (dt * (i + 1)) + sigma * np.sqrt(dt) * np.random.standard_normal())
total += max(S_sim - K, 0)
return total/M * np.exp(-r * T)
def CI(S, K, r, sigma, T, M):
call_price = MC_call_price(S, K, r, sigma, T, M)
sum_payoff = 0
for i in range(M):
sum_payoff += (MC_call_price_sim(S, K, r, sigma, T, M) - call_price)**2
sd = np.sqrt(sum_payoff / (M - 1))
se = sd / np.sqrt(M)
return call_price, sd, se
def main():
S = 100.0
K = 110.0
r = 0.05
sigma = 0.25
T = 1.0
M = 1000
call_price, sd, se = CI(S, K, r, sigma, T, M)
print("Exotic call-option price: ", call_price)
print("Standard Deviation: ", sd)
print("Standard Error: ", se)
if name == "main":
main()
Exotic call-option price: 0.0
Standard Deviation: 0.0
Standard Error: 0.0
What's wrong with the code ?
Thank you!