diff options
Diffstat (limited to 'python/analytics/basket_index.py')
| -rw-r--r-- | python/analytics/basket_index.py | 13 |
1 files changed, 9 insertions, 4 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 |
