aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests
diff options
context:
space:
mode:
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/test_swaption.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/python/tests/test_swaption.py b/python/tests/test_swaption.py
new file mode 100644
index 00000000..1ff2f5ec
--- /dev/null
+++ b/python/tests/test_swaption.py
@@ -0,0 +1,42 @@
+import unittest
+from pyisda.cdsone import upfront_charge
+from pyisda.utils import build_yc
+from pyisda.flat_hazard import strike_vec
+import datetime
+import numpy as np
+
+import sys
+sys.path.append('..')
+from swaption import Index, g
+
+class TestStrike(unittest.TestCase):
+ index = Index.from_name("ig", 26, "5yr",
+ trade_date = datetime.date(2016, 7, 1))
+ index.notional = 50e6
+ index.spread = 75
+ exercise_date = datetime.date(2016, 8, 19)
+
+ def test_strike(self):
+ """ check if strike price is the same as computing the pv
+ with the expected forward yield curve."""
+ strike = g(self.index, self.index.spread, self.exercise_date)
+ old_yc = self.index._yc
+ self.index.trade_date = self.exercise_date
+ self.index._yc = old_yc.expected_forward_curve(self.exercise_date)
+ self.index.spread = 75
+ self.assertAlmostEqual(self.index.clean_pv, strike)
+
+ def test_strike_vec(self):
+ self.index.trade_date = datetime.date(2016, 8, 19)
+ a, b = strike_vec(np.array([70, 75])*1e-4, self.index._yc, self.index.trade_date,
+ self.index._value_date, self.index.start_date, self.index.end_date,
+ self.index.recovery)
+ r = (a - self.index.fixed_rate*1e-4 * b)
+ self.index.notional = 1
+ self.index.spread = 70
+ self.assertAlmostEqual(self.index.clean_pv, r[0])
+ self.index.spread = 75
+ self.assertAlmostEqual(self.index.clean_pv, r[1])
+
+if __name__=="__main__":
+ unittest.main()