|
2 | 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane |
3 | 3 | ############################################################################## |
4 | 4 |
|
5 | | -# TODO: Add __repr__ method |
6 | 5 |
|
7 | 6 | from math import sqrt |
8 | 7 | from enum import Enum |
|
27 | 26 | from ...market.curves.interpolator import InterpTypes, interpolate |
28 | 27 | from ...utils.error import FinError |
29 | 28 |
|
30 | | -from ...utils.helpers import check_argument_types |
| 29 | +from ...utils.helpers import check_argument_types, label_to_string |
31 | 30 | from ...utils.date import Date |
32 | 31 |
|
33 | 32 | ######################################################################################## |
@@ -288,3 +287,29 @@ def value_bc( |
288 | 287 |
|
289 | 288 |
|
290 | 289 | ######################################################################################## |
| 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