aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/exploration/test_swaption.py45
1 files changed, 38 insertions, 7 deletions
diff --git a/python/exploration/test_swaption.py b/python/exploration/test_swaption.py
index acaec705..b2e3eb77 100644
--- a/python/exploration/test_swaption.py
+++ b/python/exploration/test_swaption.py
@@ -1,18 +1,49 @@
-from quantlib.time.api import Date, Period, Years
-from yieldcurve import YC
+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, Date, Days
+from quantlib.settings import Settings
-yc = YC()
+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, Period(2, Years), strike=0.0206).
- with_underlying_type(Receiver)())
+swaption1 = (MakeSwaption(index1, Period(2, Years), strike=0.020805).
+ with_underlying_type(Receiver).
+ with_nominal(10_000_000)())
swaption2 = (MakeSwaption(index2, Period(10, Years), strike=0.0212).
- with_underlying_type(Receiver)())
-pe1 = BlackSwaptionEngine(yc, 0.2987)
+ with_underlying_type(Receiver).
+ with_nominal(10_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
+ evaluation_date = Settings().evaluation_date
+ Settings().evaluation_date = evaluation_date + Period(1, Days)
+ theta = swaption.npv - old_pv
+ Settings().evaluation_date = evaluation_date
+ return theta
+
+
+def dv01(swaption, helpers):
+ old_pv = swaption.npv
+ old_quotes = [rh.quote for rh in helpers]
+ for rh in helpers:
+ rh.quote += 1e-4
+ dv01 = old_pv - swaption.npv
+ for rh, q in zip(helpers, old_quotes):
+ rh.quote = q
+ return dv01
+
+
+print("NPV: ", swaption1.npv)
+print("DV01: ", dv01(swaption1, helpers))
+print("theta: ", theta(swaption1))
+print("vega: ", swaption1.vega / 100)