diff options
Diffstat (limited to 'python/analytics/index.py')
| -rw-r--r-- | python/analytics/index.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/python/analytics/index.py b/python/analytics/index.py index 4fcfc3d0..9504451a 100644 --- a/python/analytics/index.py +++ b/python/analytics/index.py @@ -231,6 +231,60 @@ class CreditIndex(CreditDefaultSwap): def cumloss(self): return self._cumloss + def __repr__(self): + if not self.spread: + raise ValueError("Market spread is missing!") + if self.days_accrued > 1: + accrued_str = "Accrued ({} Days)".format(self.days_accrued) + else: + accrued_str = "Accrued ({} Day)".format(self.days_accrued) + + s = [ + "{:<20}\tNotional {:>5.2f}MM {}\tFactor {:>28.5f}".format( + "Buy Protection" if self.notional > 0.0 else "Sell Protection", + abs(self.notional) / 1_000_000, + self.currency, + self._factor, + ), + "{:<20}\t{:>15}".format("CDS Index", colored(self.name, attrs=["bold"])), + "", + ] + rows = [ + ["Trd Sprd (bp)", self.spread, "Coupon (bp)", self.fixed_rate], + ["1st Accr Start", self.issue_date, "Payment Freq", "Quarterly"], + ["Maturity Date", self.end_date, "Rec Rate", self.recovery], + ["Bus Day Adj", "Following", "DayCount", "ACT/360"], + ] + format_strings = [ + [None, "{:.2f}", None, "{:.0f}"], + [None, "{:%m/%d/%y}", None, None], + [None, "{:%m/%d/%y}", None, None], + [None, None, None, None], + ] + s += build_table(rows, format_strings, "{:<20}{:>19}\t\t{:<20}{:>15}") + s += ["", colored("Calculator", attrs=["bold"])] + rows = [ + ["Valuation Date", self.value_date], + ["Cash Settled On", self._cash_settle_date], + ] + format_strings = [[None, "{:%m/%d/%y}"], [None, "{:%m/%d/%y}"]] + s += build_table(rows, format_strings, "{:<20}\t{:>15}") + s += [""] + rows = [ + ["Price", self.price, "Spread DV01", self.DV01], + ["Principal", self.clean_pv, "IR DV01", self.IRDV01], + [accrued_str, self.accrued, "Rec Risk (1%)", self.rec_risk], + ["Cash Amount", self.pv, "Def Exposure", self.jump_to_default], + ] + format_strings = [ + [None, "{:.8f}", None, "{:,.2f}"], + [None, "{:,.0f}", None, "{:,.2f}"], + [None, "{:,.0f}", None, "{:,.2f}"], + [None, "{:,.0f}", None, "{:,.0f}"], + ] + s += build_table(rows, format_strings, "{:<20}{:>19}\t\t{:<20}{:>15}") + return "\n".join(s) + class ForwardIndex: __slots__ = ( |
