def __calculate_price(underlying, strike, annuity, domestic_short_rate, foreign_short_rate,
implied_sigma, days_to_maturity, sign):
""" P_t = A_t * (S_t * N(d_1) - k * e^(- (r_d - r_f) * T) * N(d_2))
:param underlying:
:param strike:
:param annuity:
:param implied_sigma:
:param days_to_maturity:
:param sign:
:return:
"""
from scipy.stats import norm
from math import exp
if sign != 1 and sign != -1:
raise ValueError("Invalid Sign")
d1 = calculate_d1(underlying, strike, domestic_short_rate, foreign_short_rate, implied_sigma, days_to_maturity)
d2 = calculate_d2(underlying, strike, domestic_short_rate, foreign_short_rate, implied_sigma, days_to_maturity)
r = domestic_short_rate - foreign_short_rate
year_fraction = float(days_to_maturity) / 365
df = exp(-r * year_fraction)
price = annuity * sign * (underlying * norm.cdf(sign * d1) - strike * df * norm.cdf(sign * d2))
return price
CGenericOptionBlackScholesModel.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录