22
22
23
23
24
24
class DiscountCurvePWFONF (DiscountCurve ):
25
- """ Curve with piece-wise flat instantaneous (ON) fwd rates. Curve is made up of a series of sections with each having
25
+ """Curve with piece-wise flat instantaneous (ON) fwd rates. Curve is made up of a series of sections with each having
26
26
a flat instantaneous forward rate. The default compounding assumption is
27
- continuous. The class inherits methods from DiscountCurve. """
28
-
29
- def __init__ (self ,
30
- value_dt : Date ,
31
- knot_dates : list ,
32
- onfwd_rates : Union [list , np .ndarray ]):
33
- """
27
+ continuous. The class inherits methods from DiscountCurve."""
28
+
29
+ def __init__ (
30
+ self ,
31
+ value_dt : Date ,
32
+ knot_dates : list ,
33
+ onfwd_rates : Union [list , np .ndarray ],
34
+ ):
35
+ """
34
36
Creates a discount curve using a vector of times and ON fwd rates
35
37
The fwd rate is right-continuous i.e. a given value in the input is applied to the left of that date until the previous date exclusive
36
38
The last fwd rate is extrapolated into the future
@@ -52,25 +54,37 @@ def __init__(self,
52
54
self ._freq_type = FrequencyTypes .CONTINUOUS
53
55
self ._day_count_type = DayCountTypes .SIMPLE
54
56
55
- dc_times = times_from_dates (self . _knot_dates ,
56
- self .value_dt ,
57
- self . _day_count_type )
57
+ dc_times = times_from_dates (
58
+ self . _knot_dates , self .value_dt , self . _day_count_type
59
+ )
58
60
59
61
self ._times = np .atleast_1d (dc_times )
60
62
61
63
# it is easier to deal in log(dfs), log(df[Ti]) = -\int_0^T_i f(u) du
62
- self ._logdfs = - \
63
- np .cumsum (np .diff (self ._times , prepend = 0.0 ) * self ._onfwd_rates )
64
+ self ._logdfs = - np .cumsum (
65
+ np .diff (self ._times , prepend = 0.0 ) * self ._onfwd_rates
66
+ )
64
67
self ._logdfs_interp = interpolate .interp1d (
65
- np .concatenate (([0.0 ], self ._times )), np .concatenate (([0.0 ], self ._logdfs )), kind = 'linear' , bounds_error = False , fill_value = 'extrapolate' )
68
+ np .concatenate (([0.0 ], self ._times )),
69
+ np .concatenate (([0.0 ], self ._logdfs )),
70
+ kind = "linear" ,
71
+ bounds_error = False ,
72
+ fill_value = "extrapolate" ,
73
+ )
66
74
67
75
if test_monotonicity (self ._times ) is False :
68
76
raise FinError ("Times are not sorted in increasing order" )
69
77
70
78
###############################################################################
71
79
72
80
@classmethod
73
- def brick_wall_curve (cls , valuation_date : Date , start_date : Date , end_date : Date , level : float = 1.0 * g_basis_point ):
81
+ def brick_wall_curve (
82
+ cls ,
83
+ valuation_date : Date ,
84
+ start_date : Date ,
85
+ end_date : Date ,
86
+ level : float = 1.0 * g_basis_point ,
87
+ ):
74
88
"""Generate a discount curve of the shape f(t) = level*1_{startdate < t <= enddate} where f(.) is the instantaneous forward rate
75
89
Mostly useful for applying bumps to other discount_curve's, see composite_discount_curve.py
76
90
Args:
@@ -82,23 +96,24 @@ def brick_wall_curve(cls, valuation_date: Date, start_date: Date, end_date: Date
82
96
Returns:
83
97
DiscountCurve: discount curve of the required shape
84
98
"""
85
- knot_dates = [start_date , end_date , end_date .add_tenor ('1D' )]
99
+ knot_dates = [start_date , end_date , end_date .add_tenor ("1D" )]
86
100
onfwd_rates = [0.0 , level , 0.0 ]
87
101
return cls (valuation_date , knot_dates , onfwd_rates )
88
102
89
103
###############################################################################
90
104
91
105
@classmethod
92
- def flat_curve (cls , valuation_date : Date , level : float = 1.0 * g_basis_point ):
93
- knot_dates = [valuation_date .add_tenor ('1Y' )]
106
+ def flat_curve (
107
+ cls , valuation_date : Date , level : float = 1.0 * g_basis_point
108
+ ):
109
+ knot_dates = [valuation_date .add_tenor ("1Y" )]
94
110
onfwd_rates = [level ]
95
111
return cls (valuation_date , knot_dates , onfwd_rates )
96
112
97
113
###############################################################################
98
114
99
- def _zero_rate (self ,
100
- times : Union [float , np .ndarray , list ]):
101
- """
115
+ def _zero_rate (self , times : Union [float , np .ndarray , list ]):
116
+ """
102
117
Piecewise flat instantaneous (ON) fwd rate is the same as linear logDfs
103
118
"""
104
119
@@ -109,25 +124,23 @@ def _zero_rate(self,
109
124
110
125
times = np .maximum (times , g_small )
111
126
ldfs = self ._logdfs_interp (times )
112
- zero_rates = - ldfs / times
127
+ zero_rates = - ldfs / times
113
128
return zero_rates
114
129
115
130
###############################################################################
116
131
117
- def _df (self , t : Union [float , np .ndarray ]):
118
- """ Return discount factors given a single or vector of times in years. The
132
+ def df_t (self , t : Union [float , np .ndarray ]):
133
+ """Return discount factors given a single or vector of times in years. The
119
134
discount factor depends on the rate and this in turn depends on its
120
135
compounding frequency and it defaults to continuous compounding. It
121
136
also depends on the day count convention. This was set in the
122
- construction of the curve to be ACT_ACT_ISDA. """
137
+ construction of the curve to be ACT_ACT_ISDA."""
123
138
124
139
zero_rates = self ._zero_rate (t )
125
140
126
- df = self ._zero_to_df (self .value_dt ,
127
- zero_rates ,
128
- t ,
129
- self ._freq_type ,
130
- self ._day_count_type )
141
+ df = self ._zero_to_df (
142
+ self .value_dt , zero_rates , t , self ._freq_type , self ._day_count_type
143
+ )
131
144
132
145
return df
133
146
@@ -145,7 +158,8 @@ def __repr__(self):
145
158
###############################################################################
146
159
147
160
def _print (self ):
148
- """ Simple print function for backward compatibility. """
161
+ """Simple print function for backward compatibility."""
149
162
print (self )
150
163
164
+
151
165
###############################################################################
0 commit comments