Black-Sholes 공식 모델링

허상범·2023년 7월 18일
0

Finance

목록 보기
4/9

Black-Sholes Model Implementation in Python

CallCall == S0N(d1)S_{0}N(d_{1}) - N(d2)KerTN(d2)Ke^{-rT}
PutPut == N(d2)KerTN(-d_{2})Ke^{-rT}-N(d1)S0N(-d_{1})S_{0}

d1d_{1} == ln(S/K)+(r+σ2/2)TσT\frac{ln(S/K)+(r+\sigma^{2}/2)T}{\sigma\sqrt T},

d2=d1σTd_{2} = d_{1}-\sigma\sqrt T

S:=currentassetpriceS := current\:asset\:price
K:=strikepriceoftheoptionK := strike\:price\:of\:the\:option
r:=riskfreerater := risk\: free \: rate
T:=timeuntiloptionexpirationT := time \: until\: option\: expiration
σ:=annualizedvolatilityoftheassetsreturns\sigma := annualized \:volatility\: of\: the\: *asset's\: returns*

N(x)N(x) is the cumulative distribution function(CDFCDF) for a standard normal distribution shown below.

N(x)N(x) == xex2/22π\int^{x}_{-\infty} \frac{e^{-x^{2}/2}}{\sqrt 2\pi}

import numpy as np
import matplotlib.pyplot as plt # https://pythonguides.com/module-matplotlib-has-no-attribute-plot/
from scipy.stats import norm

N = norm.cdf

def BS_CALL(S, K, T, r, sigma):
    d1 = (np.log(S/K) + (r + sigma**2/2)*T) / (sigma*np.sqrt(T))
    d2 = d1 - sigma * np.sqrt(T)
    return S * N(d1) - K * np.exp(-r*T)* N(d2)

def BS_PUT(S, K, T, r, sigma):
    d1 = (np.log(S/K) + (r + sigma**2/2)*T) / (sigma*np.sqrt(T))
    d2 = d1 - sigma* np.sqrt(T)
    return K*np.exp(-r*T)*N(-d2) - S*N(-d1)

Effect of variables on Option Value

Effect of sigma (sigma as x-axis)

K = 100
r = 0.1
T = 1
s = 100

# x-axis
Sigmas = np.arange(0.1, 1.5, 0.01)

# y-axis
calls = [BS_CALL(s, K, T, r, sig) for sig in Sigmas]
puts = [BS_PUT(s, K, T, r, sig) for sig in Sigmas]

plt.plot(Sigmas, calls, label='Call Value')
plt.plot(Sigmas, puts, label='Put Value')
plt.xlabel('$\sigma$')
plt.ylabel('Value')
plt.legend()

Effect of S (S as x-axis)

K = 100
r = 0.1
T = 1
sigma = 0.3

S = np.arange(60,140,0.1)

calls = [BS_CALL(s, K, T, r, sigma) for s in S]
puts = [BS_PUT(s, K, T, r, sigma) for s in S]

plt.plot(S, calls, label='Call Value')
plt.plot(S, puts, label='Put Value')
plt.xlabel('$S_0$')
plt.ylabel(' Value')
plt.legend()

profile
Engineering & Science, Since 2021 | Finance, Backend, Data

2개의 댓글

comment-user-thumbnail
2023년 7월 18일

글이 많은 도움이 되었습니다, 감사합니다.

답글 달기
comment-user-thumbnail
2023년 7월 18일

소중한 정보 잘 봤습니다!

답글 달기