Files
Basalt2/node_modules/shiki/samples/apl.sample
Robert Jelic 31787b0e9b Fix
2025-02-16 18:04:24 +01:00

38 lines
835 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

CND ← {
X ← ⍵
a ← 0.31938153 ¯0.356563782 1.781477937 ¯1.821255978 1.330274429
l ← |X
k ← ÷1+0.2316419×l
w ← 1 - (÷((2×(○1))*0.5)) × (*-(l×l)÷2) × (a +.× (k*5))
((|0⌊×X)×(1-w))+(1-|0⌊×X)×w
}
⍝ S - current price
⍝ X - strike price
⍝ T - expiry in years
⍝ r - riskless interest rate
⍝ v - volatility
S ← 60
X ← 65
T ← 1
r ← 0.1
v ← 0.2
d1 ← { ((⍟S÷X)+(r+(v*2)÷2)×⍵)÷(v×⍵*0.5) }
d2 ← { (d1 ⍵) -v×⍵*0.5 }
⍝ Call price
callPrice ← { (S×CND(d1 ⍵))-(X×*-r×⍵)×CND(d2 ⍵) }
avg ← { (+/⍵) ÷ ⊃⍴ ⍵ }
⎕←avg callPrice¨ ( 100000) ÷ 10000
⍝ Put price (not tested)
⍝ putPrice ← { (X×*-r×⍵)×CND(-d2 ⍵)-S×CND(-d1 ⍵) }
⍝ From https://github.com/melsman/apltail/blob/master/tests/blacksch.apl