• 大小: 17.13MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-13
  • 语言: Python
  • 标签: Python  金融  源码  Yves  

资源简介

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_objects_GUIs.ipynb
     文件       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个文件信息

评论

共有 条评论