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
|
import datetime
from yieldcurve import YC, rate_helpers
from quantlib.indexes.swap.usd_libor_swap import UsdLiborSwapIsdaFixAm
from quantlib.instruments.make_swaption import MakeSwaption
from quantlib.pricingengines.api import BlackSwaptionEngine
from quantlib.instruments.swap import Receiver
from quantlib.time.api import Period, Years, Days, Date
from quantlib.settings import Settings
from quantlib.experimental.risk.sensitivityanalysis import parallel_analysis
helpers = rate_helpers("USD", evaluation_date=datetime.date.today())
yc = YC(helpers)
index1 = UsdLiborSwapIsdaFixAm(Period(2, Years), yc)
index2 = UsdLiborSwapIsdaFixAm(Period(10, Years), yc)
swaption1 = (MakeSwaption(index1, Date(8, 6, 2020), strike=0.019475).
with_underlying_type(Receiver).
with_nominal(225_000_000)())
swaption2 = (MakeSwaption(index2, Date(8, 6, 2020), strike=0.0206).
with_underlying_type(Receiver).
with_nominal(50_000_000)())
pe1 = BlackSwaptionEngine(yc, 0.2815)
pe2 = BlackSwaptionEngine(yc, 0.2830)
swaption1.set_pricing_engine(pe1)
swaption2.set_pricing_engine(pe2)
def theta(swaption):
old_pv = swaption.npv
with Settings() as settings:
settings.evaluation_date += Period(1, Days)
theta = swaption.npv - old_pv
return theta
def dv01(swaption, helpers):
old_pv = swaption.npv
old_quotes = [rh.quote.value for rh in helpers]
for rh in helpers:
rh.quote.value += 1e-4
dv01 = old_pv - swaption.npv
for rh, q in zip(helpers, old_quotes):
rh.quote.value = q
return dv01
delta, gamma = parallel_analysis([h.quote for h in helpers],
[swaption1], [])
print("NPV: ", swaption1.npv)
print("NPV2: ", swaption2.npv)
print("DV01: ", dv01(swaption1, helpers))
print("theta: ", theta(swaption1))
print("vega: ", swaption1.vega / 100)
|