NB. J version of Black Scholes formula; material here appeared in
Vector 19.3, January 2003
NB. contributions by Hu Zhe, Oleg Kobchenko, Arthur Whitney, Ewart
Shaw, Eugene McDonnell
NB. Hu Zhe wrote an early version, translated from original formula
directly into J
NB. Stimulated by the Hu Zhe version, BS was written, using much more
of J's capabilities
BS =: monad define
'S X T r v' =. y
d=.((^.S%X)+T*r(+,-)-:*:v)%v*%:T NB. Eugene McDonnell
-/(S,X*^-r*T) * cnd d NB. Oleg Kobchenko
)
NB. erf and cnd due to Ewart Shaw; notice use of Hypergeometric
conjunction
erf =: (*&(%:4p_1)%^@:*:)*[:1 H. 1.5*: NB. A&S 7.1.21 (right)
cnd =: [:-:1:+[:erf%&(%:2) NB. A&S 26.2.29 (solved for P)
NB. S is current stock price
NB. X is option strike price
NB. T is time in years until strike date
NB. r is risk-free interest rate
NB. v is volatility, or standard deviation of asset price
NB. positive v for call, negative v for put (Arthur Whitney)
NB. erf is error function
NB. cnd is cumulative standard normal distribution
NB. test cases
NB. call
yc=:60 65 0.25 0.08 0.3
BS yc
2.13337
NB. put
yp=:60 65 0.25 0.08 _0.3
BS yp
_5.84628
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm