-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblack_scholes.007
More file actions
37 lines (31 loc) · 1.24 KB
/
Copy pathblack_scholes.007
File metadata and controls
37 lines (31 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- SPDX-License-Identifier: MPL-2.0
-- CONFIDENTIAL — EXPERIMENTAL — NOT FOR DISTRIBUTION
--
-- Black-Scholes Option Pricing Model in 007
--
-- C = S * N(d1) - K * exp(-rT) * N(d2)
-- P = K * exp(-rT) * N(-d2) - S * N(-d1)
@total data spot = 100.0
@total data strike = 105.0
@total data time_to_expiry = 1.0
@total data rate = 0.05
@total data vol = 0.2
@pure fn bs_d1(s: Float, k: Float, t: Float, r: Float, sigma: Float) -> Float {
return (ln(s / k) + (r + sigma * sigma / 2.0) * t) / (sigma * sqrt(t))
}
@pure fn bs_d2(d1_val: Float, sigma: Float, t: Float) -> Float {
return d1_val - sigma * sqrt(t)
}
@pure fn call_price(s: Float, k: Float, t: Float, r: Float, sigma: Float) -> Float {
let d1 = bs_d1(s, k, t, r, sigma)
let d2 = bs_d2(d1, sigma, t)
return s * norm_cdf(d1) - k * exp(neg(r * t)) * norm_cdf(d2)
}
@pure fn put_price(s: Float, k: Float, t: Float, r: Float, sigma: Float) -> Float {
let d1 = bs_d1(s, k, t, r, sigma)
let d2 = bs_d2(d1, sigma, t)
return k * exp(neg(r * t)) * norm_cdf(neg(d2)) - s * norm_cdf(neg(d1))
}
@total data d1_result = bs_d1(100.0, 105.0, 1.0, 0.05, 0.2)
@total data call_result = call_price(100.0, 105.0, 1.0, 0.05, 0.2)
@total data put_result = put_price(100.0, 105.0, 1.0, 0.05, 0.2)