-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathHull-White.py
More file actions
53 lines (40 loc) · 1.05 KB
/
Copy pathHull-White.py
File metadata and controls
53 lines (40 loc) · 1.05 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Michal Lyskawinski
# Date: 11/28/2016
# Hull-White Model
from math import *
from scipy.stats import norm
# interest rate parameters:
r = 0.04
r1 = 0.04
sigma = 0.01
a = 0.1
# Option parameters: European Call
OM = 2 # Option Maturity in years
OBM = 6 # Option's Bond Maturity in years
K = 0.73
# Bond parameters:
T = 1 # Bond Maturity in years
s = 2
t = 0 # Present time
dt = 0.1
def PDB(r,M):
P = exp(-r*M)
return P
# Pricing the Bond:
P5 = PDB(r,s)
P1 = PDB(r,T)
dB = (1/a)*(1-PDB(a,s-T))
Slope = (log(PDB(r,T+dt))-log(PDB(r,T-dt)))/(2*dt)
lnA = log(P5/P1) - dB*(Slope)
BP = exp(lnA)*PDB(r1,dB)
print('Price of the bond =',BP)
# Pricing the European Option:
PO = PDB(r,OM)
POB = PDB(r,OBM)
# K = POB/PO # If no K
sigmaP = sqrt((sigma**2/(2*a**3))*(1-PDB(2*a,OM))*(1-PDB(a,OBM-OM))**2)
d1 = ((log((POB)/(K*P1)))/(sigmaP)) + (sigmaP*0.5)
d2 = d1 - sigmaP
c = POB*norm.cdf(d1) - K*PO*norm.cdf(d2) # call
p = PO*K*norm.cdf(-d2) - POB*norm.cdf(-d1) # put
print('Price of the European Call =',c)