NameError:我的函数尚未定义

时间:2016-09-18 12:48:42

标签: python

这是我在ipython notebook中的python代码

import sys
sys.path.append('C:/Users/dell/.ipynb_checkpoints/bsm_functions.py')
tol=0.5
for option in options_data.index:
forward=futures_data[futures_data['MATURITY']==\
                   options_data.loc[option]['MATURITY']]['PRICE'].values[0]
if(forward*(1-tol)<options_data.loc[option]['STRIKE']
                             <forward*(1+tol)):
    imp_vol=bsm_call_imp_vol(v0,
                 options_data.loc[option]['STRIKE'],
    options_data.loc[option]['TTM'],r,
    options_data.loc[option]['PRICE'],
    sigma_est=2,it=100)
    options_data['IMP_VOL'].loc[option]=imp_vol

这是我写的模块:

def bsm_call_value(S0,K,T,r,sigma):
    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))
    return value
def bsm_vega(S0,K,T,r,sigma):
    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.cdf(d1,0.0,1.0)*sqrt(T)
    return vega
def bsm_call_imp_vol(S0,K,T,r,C0,sigma_est,it=100):
    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

我的错误是:

name 'bsm_call_imp_vol' is not defined

我不知道这个错误的原因

0 个答案:

没有答案