diff options
Diffstat (limited to 'python/analytics')
| -rw-r--r-- | python/analytics/basket_index.py | 4 | ||||
| -rw-r--r-- | python/analytics/tranche_basket.py | 37 |
2 files changed, 34 insertions, 7 deletions
diff --git a/python/analytics/basket_index.py b/python/analytics/basket_index.py index 2d84e564..ea61f186 100644 --- a/python/analytics/basket_index.py +++ b/python/analytics/basket_index.py @@ -1,6 +1,6 @@ from .index_data import get_index_quotes, get_singlenames_curves from . import serenitas_engine -from .utils import tenor_t +from .utils import tenor_t, get_fx from functools import partial from pyisda.cdsone import upfront_charge, spread_from_upfront from pyisda.credit_index import CreditIndex @@ -89,6 +89,7 @@ class BasketIndex(CreditIndex): self.currency = "EUR" if index_type in ["XO", "EU"] else "USD" self.yc = get_curve(value_date, self.currency) + self._fx = get_fx(value_date, self.currency) self.step_in_date = value_date + Day() self.cash_settle_date = value_date + 3 * BDay() self.tweaks = [] @@ -164,6 +165,7 @@ class BasketIndex(CreditIndex): self.index_type, self.series, d, self._curve_tenors ) self.yc = get_curve(d, self.currency) + self._fx = get_fx(d, self.currency) self.step_in_date = d + Day() self.cash_settle_date = d + 3 * BDay() self.start_date = previous_twentieth(d) # or d + 1? diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py index 25e3f4c9..35efac81 100644 --- a/python/analytics/tranche_basket.py +++ b/python/analytics/tranche_basket.py @@ -14,7 +14,14 @@ from .tranche_functions import ( ) from .exceptions import MissingDataError from .index_data import get_tranche_quotes -from .utils import memoize, build_table, bus_day, next_twentieth +from .utils import ( + memoize, + build_table, + bus_day, + next_twentieth, + get_external_nav, + run_local, +) from collections import namedtuple from . import dawn_engine, serenitas_engine, serenitas_pool from copy import deepcopy @@ -243,6 +250,7 @@ class DualCorrTranche: if rec.index_ref is not None: instance._index.tweak([rec.index_ref]) instance._trade_date = rec.trade_date + instance._trade_id = trade_id try: instance.reset_pv() except ValueError: @@ -353,12 +361,23 @@ class DualCorrTranche: @property def pv(self): pl, cl = self._pv() - _pv = -self.notional * self.tranche_factor * (pl + cl) - return _pv + if not analytics._local: + return -self.notional * self.tranche_factor * (pl + cl) * self._index._fx + else: + return -self.notional * self.tranche_factor * (pl + cl) + + @property + def accrued(self): + if not analytics._local: + return ( + -self.notional * self.tranche_factor * self._accrued * self._index._fx + ) + else: + return -self.notional * self.tranche_factor * self._accrued @property def clean_pv(self): - return self.pv + self.notional * self._accrued + return self.pv - self.accrued def _pv(self, epsilon=0.0): """ computes coupon leg, protection leg and bond price. @@ -386,7 +405,10 @@ class DualCorrTranche: def upfront(self): """returns protection upfront in points""" pl, cl = self._pv() - return -100 * (pl + cl - self._accrued) + if not analytics._local: + return -100 * (pl + cl - self._accrued) * self._index._fx + else: + return -100 * (pl + cl - self._accrued) @property def price(self): @@ -403,7 +425,10 @@ class DualCorrTranche: print(r.converged) def reset_pv(self): - self._original_clean_pv = self.clean_pv + with run_local(): + _pv = self.clean_pv + self._original_local_clean_pv = _pv + self._original_clean_pv = _pv * self._index._fx self._trade_date = self.value_date def singlename_spreads(self): |
