Hi,
I was writing a module for the black-scholes pricing model in python, but I
keep getting this error message:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File
"C:\Python26\lib\blackscholes.py", line 25 d2=d1-v*sqrt(t)
This is the code in my blackscholes.py file:#Black-Scholes model
import mathimport numpyimport scipy
#Cumulative normal distribution
def CND(x):
(a1,a2,a3,a4,a5)=(0.31938153,-0.356563782,1.781477937,-1.821255978,1.330274429)
L=abs(x) K=1.0/(1.0+0.2316419*L)
w=1.0-1.0/sqrt(2*pi)*exp(-L*L/2)*(a1*K+a2*K*K+a3*pow(K,3)+a4*pow(K,4)+a5*pow(K,5))
if x<0: w=1.0-w return w
#s: price of underlying stock x:strike price#r: continuously compounded risk
free interest rate#t: time in years until expiration of option#v: implied
volatility of underlying stock
def dividend(s,x,r,t,v): d1=(log(s/x)+((r+v**2/2)*t)/(v*sqrt(t))
d2=d1-v*sqrt(t)
def BS(s,x,r,t,v): c=s*CND(d1)-x*exp(-r*t)*CND(d2)
p=x*exp(-r*t)*CND(-d2)-s*CND(-d1) delta=CND(d1)-1 gamma=CND(d1)/(s*v*sqrt(t))
vega=s*CND(d1)*sqrt(t)
theta=-((s*CND(d1)*v)/(2*sqrt(t))+r*x*exp(-r*t)*CND(-d2)
rho=-x*t*exp(-r*t)*CND(-d2)
What is wrong here? What do I need to change? Thanks! Quick reply will be much
appreciated because the deadline is tomorrow!
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor