Standard deviations should be positive values. This is because in statistics, it is calculated as sigma = sqrt(E[(X-mu)^2]))
. The square term inside the expectation will only ever be positive.
If you adjust sigma_j
to be 0.002
instead of -0.002
, and correct the value elsewhere in your code (such as when you calculate x
and P_j
), you should get good results.
The specific problem is caused because normcdf()
doesn't handle the negative sigma properly, and returns NaN
.