2020# TODO: Fix up __repr__ function
2121###############################################################################
2222
23+
2324class 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
2526 have rates as inputs, we need to specify the corresponding compounding
2627 frequency. Also to go from rates and dates to discount factors we need to
2728 compute the year fraction correctly and for this we require a day count
2829 convention. Finally, we need to interpolate the zero rate for the times
2930 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
4245 factors. The first date is the curve anchor. Then a vector of zero
4346 dates and then another same-length vector of rates. The rate is to the
4447 corresponding date. We must specify the compounding frequency of the
@@ -59,8 +62,7 @@ def __init__(self,
5962 raise FinError ("Unknown Frequency type " + str (freq_type ))
6063
6164 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 ))
6466
6567 self .value_dt = value_dt
6668 self .freq_type = freq_type
@@ -74,38 +76,36 @@ def __init__(self,
7476 if test_monotonicity (self ._times ) is False :
7577 raise FinError ("Times or dates are not sorted in increasing order" )
7678
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+ )
8282
8383 self ._dfs = np .array (dfs )
8484
8585 self ._interp_type = interp_type
8686 self ._interpolator = Interpolator (self ._interp_type )
8787 self ._interpolator .fit (self ._times , self ._dfs )
8888
89- # ###############################################################################
89+ # ###############################################################################
9090
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. """
9393
94- # times = self.times.copy()
95- # discount_factors = self._discount_factors.copy()
94+ # times = self.times.copy()
95+ # discount_factors = self._discount_factors.copy()
9696
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)
101101
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)
105105
106- # return disc_curve
106+ # return disc_curve
107107
108- ###############################################################################
108+ ###############################################################################
109109
110110 def __repr__ (self ):
111111
@@ -118,15 +118,17 @@ def __repr__(self):
118118 s += label_to_string ("DATES" , "ZERO RATES" )
119119 num_points = len (self ._times )
120120 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+ )
123124
124125 return s
125126
126- ###############################################################################
127+ ###############################################################################
127128
128129 def _print (self ):
129- """ Simple print function for backward compatibility. """
130+ """Simple print function for backward compatibility."""
130131 print (self )
131132
133+
132134###############################################################################
0 commit comments