-
Notifications
You must be signed in to change notification settings - Fork 11
/
myblackscholes.py
60 lines (41 loc) · 1.6 KB
/
myblackscholes.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def callPrice(Spot, Strk, TtM, InR, Sigma):
# INPUT
# Spot : spot price
# Strk : strike price
# TtM : time to maturity
# InRn : interest rate
# Sigma : volatility
# OUTPUT
# out : call price
from numpy import log, exp, sqrt
from scipy.stats import norm
d1 = (log(Spot / Strk) + (InR + 0.5 * Sigma ** 2) * TtM) / (Sigma * sqrt(TtM))
d2 = (log(Spot / Strk) + (InR - 0.5 * Sigma ** 2) * TtM) / (Sigma * sqrt(TtM))
return (Spot * norm.cdf(d1, 0.0, 1.0) - Strk * exp(-InR * TtM) * norm.cdf(d2, 0.0, 1.0))
def putPrice(Spot, Strk, TtM, InR, Sigma):
# INPUT
# Spot : spot price
# Strk : strike price
# TtM : time to maturity
# InRn : interest rate
# Sigma : volatility
# OUTPUT
# out : call price
from numpy import log, exp, sqrt
from scipy.stats import norm
d1 = (log(Spot / Strk) + (InR + 0.5 * Sigma ** 2) * TtM) / (Sigma * sqrt(TtM))
d2 = (log(Spot / Strk) + (InR - 0.5 * Sigma ** 2) * TtM) / (Sigma * sqrt(TtM))
return (Strk * exp(-InR * TtM) * norm.cdf(-d2, 0.0, 1.0) - Spot * norm.cdf(-d1, 0.0, 1.0))
def vega(Spot, Strk, TtM, InR, Sigma):
# INPUT
# Spot : spot price
# Strk : strike price
# TtM : time to maturity
# InRn : interest rate
# Sigma : volatility
# OUTPUT
# out : call price
from scipy.stats import norm
from numpy import log, sqrt
d1 = (log(Spot / Strk) + (InR + 0.5 * Sigma ** 2) * TtM) / (Sigma * sqrt(TtM))
return Spot * sqrt(TtM) * norm.cdf(d1)