Look at the effect of the original cnd on arguments (d1 yc) (d2 yc):

   cndo (d1 yc),d2 yc
1.0551908

what we need is:

   cnd (d1 yc),d2 yc
0.3724829 0.317292

So leave cnd as it is and change BlackScholes:


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"0 )&(-^:x) d1, d2
)



Hallo Ian Clark, je schreef op 30-06-09 18:45:
> Neat, Aai.
>
> But it raises more questions than it answers.
>
> The verb cnd is used elsewhere. It's going to need an awfully cunning
> footnote to explain to the J beginner why the original Hu Zhe example
> needs modifying in this way.
>
> Ian
>
>
>
> On 6/30/09, Aai <[email protected]> wrote:
>   
>> AFAICS you only have to change the first cnd verb to:
>>
>>  cnd =: 3 : 'normalprob 0, 1,__,y'"0
>>
>>
>>
>>
>>  Hallo Ian Clark, je schreef op 30-06-09 07:54:
>>
>>     
>>> 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
>>  >
>>  >
>>  >
>>
>>
>>  --
>>  Met vriendelijke groet,
>>  =@@i
>>
>>  ----------------------------------------------------------------------
>>  For information about J forums see http://www.jsoftware.com/forums.htm
>>
>>     
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>   

-- 
Met vriendelijke groet,
=@@i

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to