20
20
# TODO: Fix up __repr__ function
21
21
###############################################################################
22
22
23
+
23
24
class DiscountCurveZeros (DiscountCurve ):
24
- """ This is a curve calculated from a set of dates and zero rates. As we
25
+ """This is a curve calculated from a set of dates and zero rates. As we
25
26
have rates as inputs, we need to specify the corresponding compounding
26
27
frequency. Also to go from rates and dates to discount factors we need to
27
28
compute the year fraction correctly and for this we require a day count
28
29
convention. Finally, we need to interpolate the zero rate for the times
29
30
between the zero rates given and for this we must specify an interpolation
30
- convention. The class inherits methods from FinDiscountCurve. """
31
-
32
- ###############################################################################
33
-
34
- def __init__ (self ,
35
- value_dt : Date ,
36
- zero_dts : list ,
37
- zero_rates : (list , np .ndarray ),
38
- freq_type : FrequencyTypes = FrequencyTypes .ANNUAL ,
39
- dc_type : DayCountTypes = DayCountTypes .ACT_ACT_ISDA ,
40
- interp_type : InterpTypes = InterpTypes .FLAT_FWD_RATES ):
41
- """ Create the discount curve from a vector of dates and zero rates
31
+ convention. The class inherits methods from FinDiscountCurve."""
32
+
33
+ ###############################################################################
34
+
35
+ def __init__ (
36
+ self ,
37
+ value_dt : Date ,
38
+ zero_dts : list ,
39
+ zero_rates : list | np .ndarray ,
40
+ freq_type : FrequencyTypes = FrequencyTypes .ANNUAL ,
41
+ dc_type : DayCountTypes = DayCountTypes .ACT_ACT_ISDA ,
42
+ interp_type : InterpTypes = InterpTypes .FLAT_FWD_RATES ,
43
+ ):
44
+ """Create the discount curve from a vector of dates and zero rates
42
45
factors. The first date is the curve anchor. Then a vector of zero
43
46
dates and then another same-length vector of rates. The rate is to the
44
47
corresponding date. We must specify the compounding frequency of the
@@ -59,8 +62,7 @@ def __init__(self,
59
62
raise FinError ("Unknown Frequency type " + str (freq_type ))
60
63
61
64
if dc_type not in DayCountTypes :
62
- raise FinError ("Unknown Cap Floor DayCountRule type " +
63
- str (dc_type ))
65
+ raise FinError ("Unknown Cap Floor DayCountRule type " + str (dc_type ))
64
66
65
67
self .value_dt = value_dt
66
68
self .freq_type = freq_type
@@ -74,38 +76,36 @@ def __init__(self,
74
76
if test_monotonicity (self ._times ) is False :
75
77
raise FinError ("Times or dates are not sorted in increasing order" )
76
78
77
- dfs = self ._zero_to_df (self .value_dt ,
78
- self ._zero_rates ,
79
- self ._times ,
80
- self .freq_type ,
81
- self .dc_type )
79
+ dfs = self ._zero_to_df (
80
+ self .value_dt , self ._zero_rates , self ._times , self .freq_type , self .dc_type
81
+ )
82
82
83
83
self ._dfs = np .array (dfs )
84
84
85
85
self ._interp_type = interp_type
86
86
self ._interpolator = Interpolator (self ._interp_type )
87
87
self ._interpolator .fit (self ._times , self ._dfs )
88
88
89
- # ###############################################################################
89
+ # ###############################################################################
90
90
91
- # def bump(self, bump_size):
92
- # """ Calculate the continuous forward rate at the forward date. """
91
+ # def bump(self, bump_size):
92
+ # """ Calculate the continuous forward rate at the forward date. """
93
93
94
- # times = self.times.copy()
95
- # discount_factors = self._discount_factors.copy()
94
+ # times = self.times.copy()
95
+ # discount_factors = self._discount_factors.copy()
96
96
97
- # n = len(self.times)
98
- # for i in range(0, n):
99
- # t = times[i]
100
- # discount_factors[i] = discount_factors[i] * np.exp(-bump_size*t)
97
+ # n = len(self.times)
98
+ # for i in range(0, n):
99
+ # t = times[i]
100
+ # discount_factors[i] = discount_factors[i] * np.exp(-bump_size*t)
101
101
102
- # disc_curve = FinDiscountCurve(self.value_dt, times,
103
- # discount_factors,
104
- # self._interp_type)
102
+ # disc_curve = FinDiscountCurve(self.value_dt, times,
103
+ # discount_factors,
104
+ # self._interp_type)
105
105
106
- # return disc_curve
106
+ # return disc_curve
107
107
108
- ###############################################################################
108
+ ###############################################################################
109
109
110
110
def __repr__ (self ):
111
111
@@ -118,15 +118,17 @@ def __repr__(self):
118
118
s += label_to_string ("DATES" , "ZERO RATES" )
119
119
num_points = len (self ._times )
120
120
for i in range (0 , num_points ):
121
- s += label_to_string ("%12s" % self ._zero_dts [i ],
122
- "%10.7f" % self ._zero_rates [i ])
121
+ s += label_to_string (
122
+ "%12s" % self ._zero_dts [i ], "%10.7f" % self ._zero_rates [i ]
123
+ )
123
124
124
125
return s
125
126
126
- ###############################################################################
127
+ ###############################################################################
127
128
128
129
def _print (self ):
129
- """ Simple print function for backward compatibility. """
130
+ """Simple print function for backward compatibility."""
130
131
print (self )
131
132
133
+
132
134
###############################################################################
0 commit comments