вторник, 22 августа 2023 г.

Theta, Python

https://smart-lab.ru/blog/933793.php

d:\PyCode\Options01

import numpy as np
from scipy.stats import norm

def black_sholes_theta(S,K,T,r,sigma, option_type):
d1 =(np.log(S/K) + (r + 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T))
d2 = d1 - sigma * np.sqrt(T)
if option_type == 'call':
theta = -(S*norm.pdf(d1)*sigma) / (2 * np.sqrt(T)) - r * K * np.exp(-r*T) * norm.cdf(d2)
elif option_type == 'put':
theta = -(S*norm.pdf(d1)*sigma) / (2 * np.sqrt(T)) + r * K * np.exp(-r* T) * norm.cdf(d2)
else:
raise ValueError("Invalid option type. Use 'call' or 'put'.")
return theta / 365.0

S = 93375
K = 95000
T = 30.0 / 365.0
r = 0.05
sigma = 21.674

option_type = 'call'
theta = black_sholes_theta(S,K,T,r,sigma,option_type) / 365.0
print(f"Theoretical Theta for the {option_type} option: {theta:.5f}") # -31.14005

option_type = 'put'
theta = black_sholes_theta(S,K,T,r,sigma,option_type) / 365.0
print(f"Theoretical Theta for the {option_type} option: {theta:.5f}") # -31.11572

Комментариев нет:

Отправить комментарий