你好!我叫Roma,我在Exness担任iOS开发人员。此外,我用Clojure写作并进行投资。
今天,我将讨论如何评估期权。这是一篇介绍性文章,使用建议的方法不太可能赚一百万美元。但是,这是了解更复杂的评估方法的良好基础。

Clojure
Clojure?
, , .
, Clojure JVM, , , Java.
, REPL. Clojure, Jupyter Notebook . IDE .
, , – . , - :
(defn call-option-value [security-price strike-price]
(Math/max (- security-price strike-price) 0))
(call-option-value 360.0 280.0)
=> 80.0
(call-option-value 10.0 280.0)
=> 0.0
, . , - .
: , , , .
Clojure :
(-> (get-possible-outcomes) mean present-value))
-, :
(-> (repeatedly n simulate-outcome) mean present-value)))
-
, . .
, :
(defn gbm-step [price dt rate volatility]
(let [drift (* price rate dt)
shock (* price volatility (Math/sqrt dt) (gaussian))
change (+ drift shock)]
(+ price change)))
(gbm-step 1200 1/365 0.01 0.15)
=> 1207.554940519062
, , . .
, iterate .
Apple ($257) 100 :
(take 100 (iterate #(gbm-step % 1/365 0.01 0.15) 257))
=>
(257
258.6727911540819
256.91541924148663
252.98034966342195
251.1008036685261
...
10 , :

, , :
(defn simulate-outcome [price strike rate volatility expiration]
(let [steps 100
dt (/ expiration steps)
prices (iterate #(gbm-step % dt rate volatility) price)
price-at-expiration (last (take steps prices))]
(call-option-value price-at-expiration strike)))
(repeatedly 5 #(simulate-outcome 1924 1925 0.01 0.45 0.5))
=> (0.0 730.6715047778875 329.1915857113486 0.0 0.0)
. , , , 1.
, :
(defn evaluate-call-option [& {:keys [security-price strike-price risk-free-rate volatility expiration]}]
(let [expiration (year-fraction-until expiration)
simulate-fn (partial simulate-outcome security-price strike-price risk-free-rate volatility expiration)
n 1000]
(-> (repeatedly n simulate-fn) mean (present-value risk-free-rate expiration))))
(evaluate-call-option
:security-price 1924
:strike-price 1925
:risk-free-rate 0.01
:volatility 0.45
:expiration (LocalDate/of 2020 4 17))
=> 74.66533445636996
Amazon 2100 2140 17 :
(for [strike (range 2100 2150 10)]
(evaluate-call-option
:security-price 1987
:strike-price strike
:risk-free-rate 0.01
:volatility 0.35
:expiration (LocalDate/of 2020 4 17)))
=> (23.9 21.1 16.4 15.5 15.3)
:
=> (22.9 20.6 18.35 16.4 14.6 13.6)
, .
. . , - cljfx .