aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests
diff options
context:
space:
mode:
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/test_cds.py8
-rw-r--r--python/tests/test_index.py17
-rw-r--r--python/tests/test_scenarios.py18
-rw-r--r--python/tests/test_swaption.py21
4 files changed, 35 insertions, 29 deletions
diff --git a/python/tests/test_cds.py b/python/tests/test_cds.py
index 44832dea..350f722a 100644
--- a/python/tests/test_cds.py
+++ b/python/tests/test_cds.py
@@ -10,12 +10,12 @@ from quantlib.time.api import Date
import sys
sys.path.append('..')
-from analytics import Index
+from analytics import CreditIndex
from yieldcurve import YC, ql_to_jp, get_curve
class TestUpfront(unittest.TestCase):
- index = Index.from_name("ig", 26, "5yr",
- value_date=datetime.date(2016, 9, 21))
+ index = CreditIndex("ig", 26, "5yr",
+ value_date=datetime.date(2016, 9, 21))
index.notional = 50e6
index.spread = 70
@@ -73,5 +73,5 @@ class TestSpreadCurve(unittest.TestCase):
b = cl.pv(trade_date, step_in_date, cash_settle_date, yc, sc, True)
self.assertAlmostEqual(a - b, upf)
-if __name__=="__main__":
+if __name__ == "__main__":
unittest.main()
diff --git a/python/tests/test_index.py b/python/tests/test_index.py
index 59dbfe88..d9dbf868 100644
--- a/python/tests/test_index.py
+++ b/python/tests/test_index.py
@@ -5,13 +5,13 @@ import numpy as np
from pyisda.cdsone import upfront_charge
from pyisda.flat_hazard import pv_vec
-from analytics import Index, ForwardIndex
+from analytics import CreditIndex, ForwardIndex
from analytics.index import g
import pickle
+
class TestPickle(unittest.TestCase):
- index = Index.from_name("ig", 26, "5yr",
- value_date=datetime.date(2016, 7, 1))
+ index = CreditIndex("ig", 26, "5yr", value_date=datetime.date(2016, 7, 1))
index.notional = 50e6
index.spread = 75
@@ -19,9 +19,9 @@ class TestPickle(unittest.TestCase):
a = pickle.loads(pickle.dumps(self.index))
self.assertTrue(hash(a) == hash(self.index))
+
class TestStrike(unittest.TestCase):
- index = Index.from_name("ig", 26, "5yr",
- value_date=datetime.date(2016, 7, 1))
+ index = CreditIndex("ig", 26, "5yr", value_date=datetime.date(2016, 7, 1))
index.notional = 50_000_000.
index.spread = 75
exercise_date = datetime.date(2016, 8, 19)
@@ -55,9 +55,10 @@ class TestStrike(unittest.TestCase):
self.index.price = self.index.price
self.assertAlmostEqual(self.index.spread, 75)
+
class TestForwardIndex(unittest.TestCase):
- index = Index.from_name("ig", 26, "5yr",
- value_date=datetime.date(2016, 7, 1))
+ index = CreditIndex("ig", 26, "5yr",
+ value_date=datetime.date(2016, 7, 1))
index.notional = 50_000_000.
index.spread = 75
exercise_date = datetime.date(2016, 8, 19)
@@ -74,5 +75,5 @@ class TestForwardIndex(unittest.TestCase):
fi = ForwardIndex(self.index, self.index.value_date)
self.assertAlmostEqual(fi.forward_pv, self.index.clean_pv / self.index.notional)
-if __name__=="__main__":
+if __name__ == "__main__":
unittest.main()
diff --git a/python/tests/test_scenarios.py b/python/tests/test_scenarios.py
index d079b1c9..c22c8be3 100644
--- a/python/tests/test_scenarios.py
+++ b/python/tests/test_scenarios.py
@@ -1,18 +1,20 @@
import unittest
-import datetime
import numpy as np
import pandas as pd
-from analytics import Index, BlackSwaption, Portfolio, BlackSwaptionVolSurface
+from analytics import CreditIndex, BlackSwaption, Portfolio, BlackSwaptionVolSurface
from pandas.tseries.offsets import BDay
-from analytics.scenarios import run_portfolio_scenarios, run_swaption_scenarios, run_index_scenarios
+from analytics.scenarios import (run_portfolio_scenarios,
+ run_swaption_scenarios, run_index_scenarios)
+
class TestSenarios(unittest.TestCase):
- option_delta = Index.from_tradeid(874)
+ option_delta = CreditIndex.from_tradeid(874)
option1 = BlackSwaption.from_tradeid(7, option_delta)
option2 = BlackSwaption.from_tradeid(8, option_delta)
portf = Portfolio([option1, option2, option_delta])
- date_range = pd.bdate_range(option_delta.value_date, pd.Timestamp('2017-05-17') - BDay(), freq = '5B')
+ date_range = pd.bdate_range(option_delta.value_date,
+ pd.Timestamp('2017-05-17') - BDay(), freq='5B')
def test_portfolio(self):
""" check that run_portfolio_scenarios match the sum of the individual pieces"""
@@ -21,7 +23,9 @@ class TestSenarios(unittest.TestCase):
vs = BlackSwaptionVolSurface("IG", 28, value_date=self.option_delta.value_date)
vol_surface = vs[vs.list(source="BAML")[-1]]
df = run_portfolio_scenarios(self.portf, self.date_range,
- spread_shock, vol_shock, vol_surface)
+ spread_shock=spread_shock,
+ vol_shock=vol_shock,
+ vol_surface=vol_surface)
df = df.set_index(['spread', 'vol_shock'], append=True)
df1 = run_swaption_scenarios(self.option1, self.date_range,
@@ -38,5 +42,5 @@ class TestSenarios(unittest.TestCase):
df_orig = df_orig.set_index('vol_shock', append=True)
self.assertFalse(np.any((df-df_orig).values))
-if __name__=="__main__":
+if __name__ == "__main__":
unittest.main()
diff --git a/python/tests/test_swaption.py b/python/tests/test_swaption.py
index c270dd2d..4faea8fe 100644
--- a/python/tests/test_swaption.py
+++ b/python/tests/test_swaption.py
@@ -4,11 +4,12 @@ import datetime
import sys
sys.path.append('..')
from analytics.index import g
-from analytics import Index, Swaption, BlackSwaption
+from analytics import CreditIndex, Swaption, BlackSwaption
+
class TestPutCallParity(unittest.TestCase):
- index = Index.from_name("ig", 27, "5yr",
- value_date= datetime.date(2016, 10, 25))
+ index = CreditIndex("ig", 27, "5yr",
+ value_date= datetime.date(2016, 10, 25))
index.spread = 74
exercise_date = datetime.date(2017, 3, 15)
strike = 82.5
@@ -42,8 +43,8 @@ class TestPutCallParity(unittest.TestCase):
self.assertAlmostEqual(payer.sigma, 0.37648716)
def test_hy(self):
- index = Index.from_name("hy", 27, "5yr",
- value_date=datetime.date(2016, 11, 8))
+ index = CreditIndex("hy", 27, "5yr",
+ value_date=datetime.date(2016, 11, 8))
index.price = 103.875
exercise_date = datetime.date(2017, 3, 15)
strike = 102.5
@@ -54,13 +55,13 @@ class TestPutCallParity(unittest.TestCase):
class TestBreakeven(unittest.TestCase):
exercise_date = datetime.date(2017, 3, 15)
- hyindex = Index.from_name("hy", 27, "5yr",
- value_date=datetime.date(2016, 11, 16))
+ hyindex = CreditIndex("hy", 27, "5yr",
+ value_date=datetime.date(2016, 11, 16))
hyindex.price = 103.75
hystrike = 102.5
- igindex = Index.from_name("ig", 27, "5yr",
- value_date=datetime.date(2016, 11, 18))
+ igindex = CreditIndex("ig", 27, "5yr",
+ value_date=datetime.date(2016, 11, 18))
igindex.spread = 76.5
igstrike = 80
@@ -90,5 +91,5 @@ class TestBreakeven(unittest.TestCase):
receiver.notional = 1e7
self.assertAlmostEqual(receiver.breakeven, 73.715942707132982)
-if __name__=="__main__":
+if __name__ == "__main__":
unittest.main()