forked from Michalos88/Quant-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVasicek.py
More file actions
47 lines (36 loc) · 1.1 KB
/
Copy pathVasicek.py
File metadata and controls
47 lines (36 loc) · 1.1 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
# Michal Lyskawinski
# Date: 11/28/2016
# Vasicek Model
from math import *
from scipy.stats import norm
# interest rate parameters:
rzero = 0.04
rbar = 0.05
a = 1.5
sigma = 0.01
# Option parameters: European Call
OM = 2 # Option Maturity in years
OBM = 6 # Option's Bond Maturity in years
K = 0.73
# Bond parameters:
BM = 2 # Bond Maturity in years
def PDB(r,M):
P = exp(-r*M)
return P
def Pbond(a,M,sigma,rbar):
Bts = (1/a)*(1-PDB(a,M))
Rinf = rbar - 0.5*((sigma**2)/(a**2))
lnA = (Rinf/a)*(1-PDB(a,M)) - M*Rinf - ((sigma**2)/(4*a**3))*(1-PDB(a,M))**2
P = (PDB(-lnA,1))*(PDB(rbar,Bts)) # Price of the bond
return P
print('Price of the bond =',Pbond(a,BM,sigma,rbar))
# Pricing the option
sigmaR = (sigma/(a*(OM)))*(1-PDB(a,OM)) # Spot rate volatility
POB = Pbond(a,OBM,sigma,rbar)
PO = Pbond(a,OM,sigma,rbar)
v = sqrt(((sigma**2)*(1-PDB(2*a,OM)))/(2*a))
sigmaP =(v*(1-PDB(a, OBM-OM)))/(a)
d1 = ((log(POB/(K*PO)))/(sigmaP))+(sigmaP/2)
d2 = d1 - sigmaP
c = POB*norm.cdf(d1) - K*PO*norm.cdf(d2)
print('Price of the European Call =',c)