资源简介
Python金融大数据分析.源码.py4fi-master.zip
请不要给我5星好评,因为好评会上涨积分!
代码片段和文件信息
#
# Valuation of European call options in Black-Scholes-Merton model
# incl. Vega function and implied volatility estimation
# bsm_functions.py
#
# Analytical Black-Scholes-Merton (BSM) Formula
def bsm_call_value(S0 K T r sigma):
‘‘‘ Valuation of European call option in BSM model.
Analytical formula.
Parameters
==========
S0 : float
initial stock/index level
K : float
strike price
T : float
maturity date (in year fractions)
r : float
constant risk-free short rate
sigma : float
volatility factor in diffusion term
Returns
=======
value : float
present value of the European call option
‘‘‘
from math import log sqrt exp
from scipy import stats
S0 = float(S0)
d1 = (log(S0 / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * sqrt(T))
d2 = (log(S0 / K) + (r - 0.5 * sigma ** 2) * T) / (sigma * sqrt(T))
value = (S0 * stats.norm.cdf(d1 0.0 1.0)
- K * exp(-r * T) * stats.norm.cdf(d2 0.0 1.0))
# stats.norm.cdf --> cumulative distribution function
# for normal distribution
return value
# Vega function
def bsm_vega(S0 K T r sigma):
‘‘‘ Vega of European option in BSM model.
Parameters
==========
S0 : float
initial stock/index level
K : float
strike price
T : float
maturity date (in year fractions)
r : float
constant risk-free short rate
sigma : float
volatility factor in diffusion term
Returns
=======
vega : float
partial derivative of BSM formula with respect
to sigma i.e. Vega
‘‘‘
from math import log sqrt
from scipy import stats
S0 = float(S0)
d1 = (log(S0 / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * sqrt(T))
vega = S0 * stats.norm.pdf(d1 0.0 1.0) * sqrt(T)
return vega
# Implied volatility function
def bsm_call_imp_vol(S0 K T r C0 sigma_est it=100):
‘‘‘ Implied volatility of European call option in BSM model.
Parameters
==========
S0 : float
initial stock/index level
K : float
strike price
T : float
maturity date (in year fractions)
r : float
constant risk-free short rate
sigma_est : float
estimate of impl. volatility
it : integer
number of iterations
Returns
=======
simga_est : float
numerically estimated implied volatility
‘‘‘
for i in range(it):
sigma_est -= ((bsm_call_value(S0 K T r sigma_est) - C0)
/ bsm_vega(S0 K T r sigma_est))
return sigma_est
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-07-11 18:24 py4fi-master\
文件 690 2017-07-11 18:24 py4fi-master\.gitignore
文件 1778 2017-07-11 18:24 py4fi-master\README.md
目录 0 2017-07-11 18:24 py4fi-master\ipython\
文件 45503 2017-07-11 18:24 py4fi-master\ipython\01_Why_Python_ipynb.ipynb
文件 303643 2017-07-11 18:24 py4fi-master\ipython\03_Introductory_Examples.ipynb
文件 65313 2017-07-11 18:24 py4fi-master\ipython\04_Data_Structures.ipynb
文件 783006 2017-07-11 18:24 py4fi-master\ipython\05_Visualization.ipynb
文件 560306 2017-07-11 18:24 py4fi-master\ipython\06_Financial_Time_Series.ipynb
文件 285701 2017-07-11 18:24 py4fi-master\ipython\07_Input_Output.ipynb
文件 107594 2017-07-11 18:24 py4fi-master\ipython\08_Performance_Python.ipynb
文件 560298 2017-07-11 18:24 py4fi-master\ipython\09_Math_Tools.ipynb
文件 692957 2017-07-11 18:24 py4fi-master\ipython\10_Stochastics.ipynb
文件 661928 2017-07-11 18:24 py4fi-master\ipython\11_Statistics_a.ipynb
文件 897769 2017-07-11 18:24 py4fi-master\ipython\11_Statistics_b.ipynb
文件 36894 2017-07-11 18:24 py4fi-master\ipython\12_Excel_Integration.ipynb
文件 104830 2017-07-11 18:24 py4fi-master\ipython\13_ob
文件 64688 2017-07-11 18:24 py4fi-master\ipython\14_Web_Integration.ipynb
文件 432419 2017-07-11 18:24 py4fi-master\ipython\15_DX_Library_ipynb.ipynb
文件 83682 2017-07-11 18:24 py4fi-master\ipython\19_Volatility_Options.ipynb
文件 58068 2017-07-11 18:24 py4fi-master\ipython\C_Dates_and_Times.ipynb
文件 2693 2017-07-11 18:24 py4fi-master\ipython\bsm_functions.py
文件 2092 2017-07-11 18:24 py4fi-master\ipython\bsm_option_class.py
目录 0 2017-07-11 18:24 py4fi-master\ipython\data\
文件 0 2017-07-11 18:24 py4fi-master\ipython\data\.placeholder
目录 0 2017-07-11 18:24 py4fi-master\ipython\images\
文件 1513419 2017-07-11 18:24 py4fi-master\ipython\images\msft_1.html
文件 3886998 2017-07-11 18:24 py4fi-master\ipython\images\msft_2.html
文件 828 2017-07-11 18:24 py4fi-master\ipython\mcs_full_vector_numpy.py
文件 1041 2017-07-11 18:24 py4fi-master\ipython\mcs_pure_python.py
文件 837 2017-07-11 18:24 py4fi-master\ipython\mcs_vector_numpy.py
............此处省略122个文件信息
相关资源
- python网络爬虫电子书
- python-3.1.1.msi
- Python机器学习基础教程(完整高清
- Learning Python 5th Edition.pdf
- 流畅的python中文版高清完整版mobi
- Python项目开发实战第2版带书签超清
- deep learning with python 中文版的
- 卷积神经网络预测
- Automate the Boring Stuff with Python 原版PD
- python2.7 32位
- 精通Python自然语言处理
- Python深度学习(中文版) 超清带书签
- 人脸识别python实现源码功能丰富
- Python机器学习
- numpy-1.17.4-cp38-cp38-win_amd64.whl
- 源码python数据挖掘入门与实践源码
- Python数据科学手册(PDF)
- Python测试驱动开发:使用Django、Sele
- Python Data Analytics 无水印pdf 0分
- Deep Learning with Applications Using Python C
- 信用风险建模:理论基础、诊断工具
- Python编程导论(第2版).rar
- 图灵书籍(Python数据处理.pdf+代码)
- Python爬虫抓取东方财富网股票数据并
- Grokking Deep Learning 正式版pdf
- python游戏编程入门源代码
- 流畅的python-LucianoRamalho.pdf
- torch-1.1.0-cp36-cp36m-linux_aarch64.whl
- scipy-1.0.1-cp36-cp36m-win_amd64.whl
- 《Python机器学习及实践从零开始通往
评论
共有 条评论