diff options
Diffstat (limited to 'python/analytics/index.py')
| -rw-r--r-- | python/analytics/index.py | 87 |
1 files changed, 38 insertions, 49 deletions
diff --git a/python/analytics/index.py b/python/analytics/index.py index 6a0b0ad5..d782310e 100644 --- a/python/analytics/index.py +++ b/python/analytics/index.py @@ -13,7 +13,7 @@ from pandas.tseries.offsets import BDay from db import dbengine from sqlalchemy import exc from pyisda.curve import SpreadCurve -from .utils import previous_twentieth +from .utils import previous_twentieth, build_table from yieldcurve import YC, ql_to_jp, roll_yc, rate_helpers from blinker import signal @@ -386,58 +386,47 @@ class Index(object): return instance 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) - if not self.spread: - raise ValueError("Market spread is missing!") - s = ["{:<20}\t{:>15}".format("CDS Index", colored(self.name, attrs = ['bold'])), - "", - "{:<20}\t{:>15}".format("Trade Date", ('{:%m/%d/%y}'. - format(self.trade_date))), - "{:<20}\t{:>15.2f}\t\t{:<20}\t{:>10,.2f}".format("Trd Sprd (bp)", - self.spread, - "Coupon (bp)", - self.fixed_rate), - "{:<20}\t{:>15}\t\t{:<20}\t{:>10}".format("1st Accr Start", - '{:%m/%d/%y}'. - format(self.issue_date), - "Payment Freq", - "Quarterly"), - "{:<20}\t{:>15}\t\t{:<20}\t{:>10.2f}".format("Maturity Date", - ('{:%m/%d/%y}'. - format(self.end_date)), - "Rec Rate", - self.recovery), - "{:<20}\t{:>15}\t\t{:<20}\t{:>10}".format("Bus Day Adj", - "Following", - "Day Count", - "ACT/360"), - "", - colored("Calculator", attrs = ['bold']), - "{:<20}\t{:>15}".format("Valuation Date", ('{:%m/%d/%y}'. - format(self.trade_date))), - "{:<20}\t{:>15}".format("Cash Settled On", ('{:%m/%d/%y}'. - format(self._value_date))), - "", - "{:<20}\t{:>15.8f}\t\t{:<20}\t{:>10,.2f}".format("Price", - self.price, - "Spread DV01", - self.DV01), - "{:<20}\t{:>15,.0f}\t\t{:<20}\t{:>10,.2f}".format("Principal", - self.clean_pv, - "IR DV01", - self.IRDV01), - "{:<20}\t{:>15,.0f}\t\t{:<20}\t{:>10,.2f}".format(accrued_str, - self.accrued, - "Rec Risk (1%)", - self.rec_risk), - "{:<20}\t{:>15,.0f}\t\t{:<20}\t{:>10,.0f}".format("Cash Amount", - self.pv, - "Def Exposure", - self.jump_to_default) - ] + + s = ["{:<20}\tNotional {:>5}MM {}\tFactor {:>28}".format("Buy Protection"\ + if self._direction == -1 \ + else "Sell Protection", + 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.trade_date], + ["Cash Settled On", self._value_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) |
