;;; Copyright Igor Rivin, 2004, 2005, All rights reserved. (load "stats.ss") (load "math.ss") (define BlackScholes (lambda (K S r q Tcal Ttrade vol iscall) (let* ((thelog (log (/ S K))) (thesqrt (sqrt Ttrade)) (vol2 (* vol vol)) (denom (* vol thesqrt)) (d1 (/ (+ thelog (* (- r q) Tcal) (* vol2 0.5 Ttrade)) denom)) (d2 (- d1 denom))) (if iscall (- (* S (exp (- (* q Tcal))) (Phi d1)) (* K (exp (- (* r Tcal))) (Phi d2))) (- (* S (exp (- (* r Tcal))) (Phi (- d2))) (* K (exp (- (* q Tcal))) (Phi (- d1)))))))) (define OptionPriceSimp ;;one dividend approximation ;(only does something interesting for american calls. (lambda (K S r q Tcal Ttrade Tcalx Tradex vol iscall) (if (or (not iscall) (<= Tcalx 0)) (BlackScholes K S r q Tcal Ttrade vol iscall) (let ((p1 (BlackScholes K S r q Tcal Ttrade vol iscall)) (p2 (BlackScholes K S r 0 Tcalx Tradex vol iscall)); what if exercise on ex-date ) (max p1 p2))))) (define VolTol 1.0e-6) (define ImpliedVol ;;pricefunc is the option pricing function (lambda (K S r q Tcal Ttrade Tcalx Tradex iscall pricefunc theprice) (let ((PriceOpt (lambda (vol) (- (pricefunc K S r q Tcal Ttrade Tcalx Tradex vol iscall) theprice)))) (zerosearch PriceOpt 10.0 0.0 1.0 VolTol)))) (define faux (lambda (x y a b rho) (let* ((r2 (* rho rho)) (tmp (/ 1 (sqrt (* 2 (- 1 r2))))) (a1 (* a tmp)) (b1 (* b tmp)) (thearg (+ (* a1 (- (* 2 x) a1)) (* b1 (- (* 2 y) b1)) (* 2 rho (- x a1) (- y b1))))) (exp thearg))))