Skip to content

Commit bdb2e6f

Browse files
authored
Merge pull request #236 from shubhamlodha21/add-repr-cds-tranche
Add __repr__ and _print to CDSTranche
2 parents 2e8528a + 1a7e0da commit bdb2e6f

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

financepy/products/credit/cds_tranche.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Copyright (C) 2018, 2019, 2020 Dominic O'Kane
33
##############################################################################
44

5-
# TODO: Add __repr__ method
65

76
from math import sqrt
87
from enum import Enum
@@ -27,7 +26,7 @@
2726
from ...market.curves.interpolator import InterpTypes, interpolate
2827
from ...utils.error import FinError
2928

30-
from ...utils.helpers import check_argument_types
29+
from ...utils.helpers import check_argument_types, label_to_string
3130
from ...utils.date import Date
3231

3332
########################################################################################
@@ -288,3 +287,29 @@ def value_bc(
288287

289288

290289
########################################################################################
290+
291+
def __repr__(self):
292+
"""Print out details of the CDSTranche contract."""
293+
s = label_to_string("OBJECT TYPE", type(self).__name__)
294+
s += label_to_string("STEP-IN DATE", self.step_in_dt)
295+
s += label_to_string("MATURITY DATE", self.maturity_dt)
296+
s += label_to_string("ATTACHMENT POINT (K1)", self.k1)
297+
s += label_to_string("DETACHMENT POINT (K2)", self.k2)
298+
s += label_to_string("NOTIONAL", self.notional)
299+
s += label_to_string("RUNNING COUPON", self.running_cpn * 10000, "bp\n")
300+
s += label_to_string("LONG PROTECTION", self.long_protect)
301+
s += label_to_string("FREQUENCY", self.freq_type)
302+
s += label_to_string("DAYCOUNT", self.dc_type)
303+
s += label_to_string("CALENDAR", self.cal_type)
304+
s += label_to_string("BUSDAYRULE", self.bd_type)
305+
s += label_to_string("DATEGENRULE", self.dg_type)
306+
return s
307+
308+
####################################################################################
309+
310+
def _print(self):
311+
"""Simple print function for backward compatibility."""
312+
print(self)
313+
314+
315+
########################################################################################

0 commit comments

Comments
 (0)