Discussion:
[Tutor] How to calculate the cumulative normal distribution
Michel Guirguis
2015-09-30 06:12:20 UTC
Permalink
Good afternoon,

How to calculate the cumulative normal distribution function CND in order to use this figure to calculate the call option based on the Black and Scholes model.
from math import*
m = abs(X)
[a1,a2,a3,a4,a5]=(0.31938153,-0.356563782,1.781477937,-1.821255978,1.330274429)
k = 1/(1+0.2316419*m)
CND1 = 1.0-1.0/ sqrt(2*3.1415)* exp(-m*m*0.5)
CND2 =(a1*k + a2*k*k+a3*k*k*k+a4*k*k*k*k+a5*k*k*k*k*k)
CND = CND1*CND2
d1=(math.log(S/K)+(r-q+(sig*sig)*0.5)*T)/(sig*math.sqrt(T))
d1
0.10606601717798211
d2 =d1-sig*math.sqrt(T)
d2
-0.03535533905932742
call = 50*exp(-0.02*0.5)*CND(d1)-50*exp(-0.03*0.5)*CND(d2)
call
Thanks,

Michel

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Laura Creighton
2015-09-30 09:13:04 UTC
Permalink
Post by Michel Guirguis
Good afternoon,
How to calculate the cumulative normal distribution function CND in order to use this figure to calculate the call option based on the Black and Scholes model.
The easy way is to install scipy.
Post by Michel Guirguis
from scipy.stats import norm
norm.cdf(1.96)
array(0.97500210485177952)

The easy way to install scipy is to get your python via anaconda
https://www.continuum.io/downloads

Laura
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Steven D'Aprano
2015-09-30 12:11:36 UTC
Permalink
Post by Laura Creighton
Post by Michel Guirguis
Good afternoon,
How to calculate the cumulative normal distribution function CND in
order to use this figure to calculate the call option based on the
Black and Scholes model.
The easy way is to install scipy.
That's no fun :-(
--
Steve
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Oscar Benjamin
2015-10-02 20:39:35 UTC
Permalink
Post by Michel Guirguis
Good afternoon,
How to calculate the cumulative normal distribution function CND in order
to use this figure to calculate the call option based on the Black and
Scholes model.

The easy way is to install scipy



Michel, It sounds like you probably do want to install scipy for the work
that you're doing and Laura's correct that anaconda is the easiest way to
do that.

However I want to point out that your specific problem is easily solved
with the stdlib. The CDF of the standard normal distribution is easily
expressed in terms of the error function erf which is available in the math
module:

fron math import erf

def phi(z):
return 0.5 * (1 + erf(z))

--
Oscar
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Steven D'Aprano
2015-09-30 12:15:22 UTC
Permalink
Post by Michel Guirguis
Good afternoon,
How to calculate the cumulative normal distribution function CND in
order to use this figure to calculate the call option based on the
Black and Scholes model.
from math import*
m = abs(X)
[a1,a2,a3,a4,a5]=(0.31938153,-0.356563782,1.781477937,-1.821255978,1.330274429)
k = 1/(1+0.2316419*m)
CND1 = 1.0-1.0/ sqrt(2*3.1415)* exp(-m*m*0.5)
CND2 =(a1*k + a2*k*k+a3*k*k*k+a4*k*k*k*k+a5*k*k*k*k*k)
CND = CND1*CND2
I haven't checked that algorithm, but you need to return a result, not
assign to the function name:

return CND1*CND2
--
Steve
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Steven D'Aprano
2015-09-30 12:36:33 UTC
Permalink
Post by Michel Guirguis
Good afternoon,
How to calculate the cumulative normal distribution function CND in
order to use this figure to calculate the call option based on the
Black and Scholes model.
from math import*
m = abs(X)
[a1,a2,a3,a4,a5]=(0.31938153,-0.356563782,1.781477937,-1.821255978,1.330274429)
k = 1/(1+0.2316419*m)
CND1 = 1.0-1.0/ sqrt(2*3.1415)* exp(-m*m*0.5)
CND2 =(a1*k + a2*k*k+a3*k*k*k+a4*k*k*k*k+a5*k*k*k*k*k)
CND = CND1*CND2
That cannot possibly be the *cumulative* normal distribution, as that
should approach 1 as x gets really large:

py> CND(2000000.0)
6.893832052455898e-07


Are you sure this is the right description or algorithm?
--
Steve
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Continue reading on narkive:
Loading...