call.fun 993 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #import std
  2. #import nat
  3. #import flo
  4. #import crt
  5. #import cop
  6. usage =
  7. :/'usage: call [-parameter value]* [--greeks]' ~&t -[
  8. -s <initial stock price>
  9. -t <time to expiration>
  10. -v <volatility>
  11. -r <interest rate>
  12. -k <strike price>]-
  13. #optimize+
  14. price =
  15. <"s","t","v","r","k">. levin_limit amer* *- (
  16. crr$[s: "s"!,t: "t"!,v: "v"!,r: "r"!,n: ~&]* ~&NiC|\ 8!* iota4,
  17. max/0.+ minus\"k")
  18. greeks =
  19. ^|T(~&,printf/':%10.3f')*+ -+
  20. //~&p <'delta','theta','vega ','rho ','dc/dk','gamma'>,
  21. ^lrNCT(
  22. ~&h+ jacobian(1,5) ~&iNC+ price,
  23. ("h","t"). (derivative derivative price\"t") "h")+-
  24. #comment usage--<'','last modified: '--__source_time_stamp>
  25. #executable (<'par'>,<>)
  26. call =
  27. ~&iNC+ file$[contents: ~&]+ -+
  28. ^CNNCT/-+printf/'price:%10.2f',price+~&r+- ~&l&& greeks+ ~&r,
  29. ~command.options; ^/(any ~keyword[='greeks') -+
  30. -&~&itZBg,eql/16,all ~&jZ\'0123456789.-'+ ~&h&-?/%ep* usage!%,
  31. ~parameters*+ ~&itZBFL+ gang *~* ~keyword==* ~&iNCS 'stvrk'+-+-