aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics')
-rw-r--r--python/analytics/basket_index.py13
-rw-r--r--python/analytics/tranche_basket.py5
2 files changed, 13 insertions, 5 deletions
diff --git a/python/analytics/basket_index.py b/python/analytics/basket_index.py
index 8bf5a8a2..138090a4 100644
--- a/python/analytics/basket_index.py
+++ b/python/analytics/basket_index.py
@@ -6,6 +6,7 @@ from pyisda.credit_index import CreditIndex
from typing import List
import numpy as np
import pandas as pd
+from math import exp
import datetime
from scipy.optimize import brentq
from pandas.tseries.offsets import BDay
@@ -124,16 +125,20 @@ class BasketIndex(CreditIndex):
def coupon(self, maturity):
return self.index_desc.loc[maturity, 'coupon']
- def tweak(self):
+ def tweak(self, *args):
""" tweak the singlename curves to match index quotes"""
- quotes = self._get_quotes()
+ quotes = self._get_quotes(*args)
self.tweaks = []
for m, index_quote in quotes.items():
lo, hi = -0.3, 0.3
- while lo > -1:
+ hi_tilde = exp(hi) -1
+ while hi_tilde < 5:
+ # map range to (-1, +inf)
+ lo_tilde = exp(lo) -1
+ hi_tilde = exp(hi) -1
try:
eps = brentq(lambda epsilon: self.pv(m, epsilon) -
- index_quote, lo, hi)
+ index_quote, lo_tilde, hi_tilde)
except ValueError:
lo *= 1.1
hi *= 1.1
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index c11798a8..58d09365 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -65,7 +65,10 @@ class TrancheBasket(BasketIndex):
def tranche_factors(self):
return np.diff(self.K) / np.diff(self.K_orig) * self.factor
- def _get_quotes(self):
+ def _get_quotes(self, spread=None):
+ if spread is not None:
+ return {self.maturity:
+ self._snacpv(spread * 1e-4, self.coupon(self.maturity), self.recovery)}
refprice = self.tranche_quotes.indexrefprice.iat[0]
refspread = self.tranche_quotes.indexrefspread.iat[0]
if refprice is not None: