To follow this you'll need to refer to the page: http://www.jsoftware.com/jwiki/Doc/Articles/Play193
I'm testing the code for Edn 2 of APWJ, and it doesn't give the result I expect. It checks out fine until I come to this example about halfway down, attributed to Oleg: BlackScholes=: 4 : 0 'S X T r v' =. y. d1=. ((ln S%X)+(r+-:*:v)*T)%(v * sqrt T) d2=. d1 - v * sqrt T (S, X * exp-r*T) (-/ . * cnd)&(-^:x.) (d1, d2) ) At the end of the article, Gene gives a sample result with his improved Black-Scholes formula BS as follows (this I can reproduce, so I'm happy that BS works): yc=:60 65 0.25 0.08 0.3 BS yc 2.13337 yp=:60 65 0.25 0.08 _0.3 BS yp _5.84628 (ignore the minus... a side-effect of a clever trick to specify 'put' or 'call'. The example verbs attributed to Hu Zhe work okay also: BlackScholesCall yc 2.13338 BlackScholesPut yc 5.84629 ...well, near enough I reason that the given verb BlackScholes should check out in like manner using the same yc: 0 BlackScholes yc NB. left arg 0/1 decides if a 'put' or a 'call' 2.13337 1 BlackScholes yc 5.84629 ...or maybe it's the other way around...? But I don't get anything like these values. I get _3.91783 and 3.508 respectively. I can verify that the intermediate values d1 and d2 in BlackScholes get the same values as they do in the Hu Zhe example (_0.325285 and _0.475285 respectively). It's the final line that's the mischief: (S, X * exp-r*T) (-/ . * cnd)&(-^:x.) (d1, d2) Somehow, over the years, J must have changed in how it executes it. Can anyone debug it, please, to give the expected result? BTW: It seems to me the given example should also work if x and y replace deprecated x. and y. respectively. Unfortunately the subsequent examples won't work then, because x clashes with its use as a work-variable to hold the second element of yc. This can be overcome by adhering rigidly to the earlier convention of using S X T for the first 3 elements of yc instead of s x t --which the article lapses into doing. But that is (I think) an independent issue. Ian Clark ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
