NameError:my function has not be defined
<p>This is my python code in ipython notebook</p>

<pre><code>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)&lt;options_data.loc[option]['STRIKE']
                             &lt;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
</code></pre>

<p>this the module I wrote:</p>

<pre><code>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
</code></pre>

<p>my error is:</p>

<pre><code>name 'bsm_call_imp_vol' is not defined
</code></pre>

<p>I do not know the reason of this error</p>

<p>You need to <strong>import</strong> your module. You add the <em>parent directory</em> of a module to your <code>sys.path</code>, then import names from the module:</p>

<pre><code>sys.path.append('C:/Users/dell/.ipynb_checkpoints')
from bsm_functions import bsm_call_imp_vol
</code></pre>

<p>Adding the path to a <code>.py</code> file itself to <code>sys.path</code> does not import the module.</p>

python