[Tutor] Cumulative distribution function

Peter Otten __peter__ at web.de
Thu Oct 1 10:57:18 CEST 2015


Michel Guirguis wrote:

[Please don't start a new thread for an old problem]

> I have a problem with the cumulative distribution function in calculating
> derivatives. I am getting a call option figure of 2.5961 while it should
> be 2.9081. Could you please help.

> >>> S=50
> >>> K=50
> >>> r=0.03
> >>> q=0.02
> >>> sig=0.20
> >>> T=0.5

> >>> from math import*
> >>> d1=(log(S/K)+(r-q+(sig*sig)*0.5)*T)/(sig*sqrt(T))
> >>> d1
> 0.10606601717798211
> >>> d2 =d1-sig*sqrt(T)
> >>> d2
> -0.03535533905932742
> >>>  def cumdist():

Something is missing here...

> call = 50*exp(-0.02*0.5)*cumdist*(d1)-50*exp(-0.03*0.5)*cumdist*(d2)

... and here seem to be erroneous * operators.

> >>> call
> 2.596102990952506

Did you see Laura's answer to your previous question? Using 
scipy.stats.norm.cdf and turning your interactive session into a little 
script I get

$ cat cumulative.py
import scipy.stats
from math import log, exp, sqrt

cumdist = scipy.stats.norm.cdf

S = 50
K = 50
r = 0.03
q = 0.02
sig = 0.20
T = 0.5

d1 = (log(S/K)+(r-q+(sig*sig)*0.5)*T)/(sig*sqrt(T))
print("d1 = {}".format(d1))

d2 = d1-sig*sqrt(T)
print("d2 = {}".format(d2))

call = 50*exp(-0.02*0.5)*cumdist(d1)-50*exp(-0.03*0.5)*cumdist(d2)
print("call = {}".format(call))

$ python cumulative.py 
d1 = 0.106066017178
d2 = -0.0353553390593
call = 2.9087784079

Not exactly 2.9081, but closer :)

Assuming 2.9088 is the correct value, but for some reason you cannot use 
scipy the problem is with your cumdist() function.

You don't provide that function and you don't provide the source where you 
adapted it from. How do you expect us to help you fix code without spec -- 
and without seeing said code?




More information about the Tutor mailing list