Skip to content

Instantly share code, notes, and snippets.

@OpenGamma-Blog
Last active December 24, 2015 12:19
Show Gist options
  • Save OpenGamma-Blog/6796793 to your computer and use it in GitHub Desktop.
Save OpenGamma-Blog/6796793 to your computer and use it in GitHub Desktop.
(use 'com.lambder.deriva.core)
(def N
'(/ 1
(+ 1
(exp (-
(* -0.07056 (pow x 3))
(* -1.5976 x)))))
(def d1 '(/ (+ (/ F K) (* T (/ (sq sigma) 2)))))
(def d2 '(/ (- (/ F K) (* T (/ (sq sigma) 2)))))
(def call
`(*
(exp (- (* r T))
(-
(* F ~(bind N x d1))
(* K ~(bind N x d2)))))
(def put
`(*
(exp (- (* r T))
(-
(* F ~(bind N x (- d1)))
(* K ~(bind N x (- d2))))))
(defn black-expression [call?] call put)
;; usage
(def black-model-with-sensitivities (∂ (bind (black-expression true) T 0.523) F K r))
(black-model-with-sensitivities 12.3 14.3 0.03)
(black-model-with-sensitivities 12.3 11.0 0.03)
(black-model-with-sensitivities 12.3 11.0 0.02)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment