Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 8

HW8

鮑欣禾 112071469
筆記
European put
def blsprice_put(S0, X, r, T, sigma):
d1 = (np.log(S0 / X) + (r + 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T))
d2 = d1 - sigma * np.sqrt(T)
put_price = X * np.exp(-r * T) * norm.cdf(-d2) - S0 * norm.cdf(-d1)
return put_price

def BlsMC_put(S0, X, r, T, sigma, NRepl):


nuT = (r - 0.5 * sigma ** 2) * T
siT = sigma * np.sqrt(T)
DiscPayoff = np.exp(-r * T) * np.maximum(0, X - S0 * np.exp(nuT + siT * np.r
andom.randn(NRepl)))
Price, StdDev = norm.fit(DiscPayoff)
CI = norm.interval(0.95, loc=Price, scale=StdDev / np.sqrt(NRepl))
return Price, CI
European put
S0 = 50
X = 52
r = 0.1
T = 5 / 12
sigma = 0.4
NRepl1 = 1000
NRepl2 = 200000

Bls_put = blsprice_put(S0, X, r, T, sigma)


np.random.seed(0)
MC1000_put, CI1000_put = BlsMC_put(S0, X, r, T, sigma, NRepl1)
np.random.seed(0)
MC200000_put, CI200000_put = BlsMC_put(S0, X, r, T, sigma, NRepl2)
European put
print("Black-Scholes Put Option Price:", Bls_put)
print("Monte Carlo (1000 simulations) Put Option Price:", MC1000_put)
print("Monte Carlo (1000 simulations) Put Option 95% Confidence Interval:", CI
1000_put)
print("Monte Carlo (200000 simulations) Put Option Price:", MC200000_put)
print("Monte Carlo (200000 simulations) Put Option 95% Confidence Interval:",
CI200000_put)
Other European options
import numpy as np
from scipy.stats import norm

def blsprice_put(S0, X, r, T, sigma):


d1 = (np.log(S0 / X) + (r + 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T))
d2 = d1 - sigma * np.sqrt(T)
put_price = X * np.exp(-r * T) * norm.cdf(-d2) - S0 * norm.cdf(-d1)
return put_price

def BlsMCAV_put(S0, X, r, T, sigma, NRepl):


nuT = (r - 0.5 * sigma ** 2) * T
siT = sigma * np.sqrt(T)
Veps = np.random.randn(NRepl)
Payoff1 = np.maximum(0, X - S0 * np.exp(nuT + siT * Veps))
Payoff2 = np.maximum(0, X - S0 * np.exp(nuT + siT * (-Veps)))
DiscPayoff = np.exp(-r * T) * 0.5 * (Payoff1 + Payoff2)
Price, StdDev = norm.fit(DiscPayoff)
CI = norm.interval(0.95, loc=Price, scale=StdDev / np.sqrt(NRepl))
return Price, CI
Other European options
S0 = 50
X = 52
r = 0.1
T = 5 / 12
sigma = 0.4
NRepl1 = 100000
NRepl2 = 200000

Bls_put = blsprice_put(S0, X, r, T, sigma)


np.random.seed(0)
MC200000_put, CI1_put = BlsMCAV_put(S0, X, r, T, sigma, NRepl2)
np.random.seed(0)
MCAV100000_put, CI2_put = BlsMCAV_put(S0, X, r, T, sigma, NRepl1)
Other European options
print("Black-Scholes Put Option Price:", Bls_put)
print("Monte Carlo (200000 simulations) Put Option Price:", MC200000_put)
print("Monte Carlo (200000 simulations) Put Option 95% Confidence Interval:",
CI1_put)
print("Monte Carlo with Antithetic Variates (100000 simulations) Put Option Pric
e:", MCAV100000_put)
print("Monte Carlo with Antithetic Variates (100000 simulations) Put Option 95%
Confidence Interval:", CI2_put)

You might also like