@@ -99,6 +99,18 @@ def dfs(self) -> np.ndarray:
9999
100100 ###########################################################################
101101
102+ def set_df (self , index , df ):
103+ """Set the discount factor at a specific index."""
104+
105+ n_points = len (self ._dfs )
106+
107+ if index < 0 or index >= n_points :
108+ raise IndexError ("Index out of bounds" )
109+
110+ self ._dfs [index ] = df
111+
112+ ###########################################################################
113+
102114 def _zero_to_df (
103115 self ,
104116 value_dt : Date , # TODO: why is value_dt not used ?
@@ -122,12 +134,12 @@ def _zero_to_df(
122134 df = np .exp (- rates * t )
123135 elif freq_type == FrequencyTypes .SIMPLE :
124136 df = 1.0 / (1.0 + rates * t )
125- elif (
126- freq_type == FrequencyTypes .ANNUAL
127- or freq_type == FrequencyTypes .SEMI_ANNUAL
128- or freq_type == FrequencyTypes .QUARTERLY
129- or freq_type == FrequencyTypes .MONTHLY
130- ) :
137+ elif freq_type in {
138+ FrequencyTypes .ANNUAL ,
139+ FrequencyTypes .SEMI_ANNUAL ,
140+ FrequencyTypes .QUARTERLY ,
141+ FrequencyTypes .MONTHLY ,
142+ } :
131143 df = 1.0 / np .power (1.0 + rates / f , f * t )
132144 else :
133145 raise FinError ("Unknown Frequency type" )
@@ -217,15 +229,15 @@ def zero_rate(
217229
218230 if isinstance (dts , Date ):
219231 return zero_rates [0 ]
220- else :
221- return np .array (zero_rates )
222232
223- return zero_rates
233+ return np . array ( zero_rates )
224234
225235 ###########################################################################
226236
227237 def cc_rate (
228- self , dts : Union [list , Date ], dc_type : DayCountTypes = DayCountTypes .SIMPLE
238+ self ,
239+ dts : Union [list , Date ],
240+ dc_type : DayCountTypes = DayCountTypes .SIMPLE ,
229241 ):
230242 """Calculation of zero rates with continuous compounding. This
231243 function can return a vector of cc rates given a vector of
@@ -262,7 +274,8 @@ def swap_rate(
262274
263275 if freq_type == FrequencyTypes .SIMPLE :
264276 raise FinError ("Cannot calculate par rate with simple yield freq." )
265- elif freq_type == FrequencyTypes .CONTINUOUS :
277+
278+ if freq_type == FrequencyTypes .CONTINUOUS :
266279 raise FinError ("Cannot calculate par rate with continuous freq." )
267280
268281 if isinstance (maturity_dt , Date ):
@@ -305,8 +318,8 @@ def swap_rate(
305318
306319 if isinstance (maturity_dts , Date ):
307320 return par_rates [0 ]
308- else :
309- return par_rates
321+
322+ return par_rates
310323
311324 ###########################################################################
312325
@@ -378,8 +391,8 @@ def fwd(self, dts: Date):
378391
379392 if isinstance (dts , Date ):
380393 return fwd [0 ]
381- else :
382- return np .array (fwd )
394+
395+ return np .array (fwd )
383396
384397 ###########################################################################
385398
@@ -461,8 +474,8 @@ def fwd_rate(
461474
462475 if isinstance (start_dt , Date ):
463476 return fwd_rates [0 ]
464- else :
465- return np .array (fwd_rates )
477+
478+ return np .array (fwd_rates )
466479
467480 ###########################################################################
468481
0 commit comments