riskfreerates¶
athena.riskfreerates
¶
RiskFreeRateSeries
¶
Bases: Enum
FRED series identifiers for risk-free rates.
Source code in src/athena/riskfreerates.py
RiskFreeRateManager
¶
Bases: ABC
Abstract base class for risk-free rate data providers.
Source code in src/athena/riskfreerates.py
get_rate(rate_date)
abstractmethod
¶
Get the annualized risk-free rate for a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate_date
|
date
|
The date to get the rate for. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
The annualized rate as a decimal (e.g., Decimal("0.045") for 4.5%). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no rate is available for the date. |
Source code in src/athena/riskfreerates.py
get_daily_rate(rate_date, trading_days_per_year=252)
abstractmethod
¶
Get the daily risk-free rate for a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate_date
|
date
|
The date to get the rate for. |
required |
trading_days_per_year
|
int
|
Number of trading days per year (default 252). |
252
|
Returns:
| Type | Description |
|---|---|
Decimal
|
The daily rate as a decimal. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no rate is available for the date. |
Source code in src/athena/riskfreerates.py
get_rates_for_range(start_date, end_date)
abstractmethod
¶
Get all available annualized rates for a date range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
date
|
Start of the date range (inclusive). |
required |
end_date
|
date
|
End of the date range (inclusive). |
required |
Returns:
| Type | Description |
|---|---|
dict[date, Decimal]
|
Dictionary mapping dates to annualized rates. |
dict[date, Decimal]
|
Only includes dates where data is available (trading days). |
Source code in src/athena/riskfreerates.py
FixedRiskFreeRateManager
¶
Bases: RiskFreeRateManager
Returns a fixed risk-free rate for all dates.
Source code in src/athena/riskfreerates.py
__init__(annual_rate=Decimal('0.05'))
¶
Initialize with a fixed annual rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annual_rate
|
Decimal
|
The fixed annual rate as a decimal (e.g., 0.05 for 5%). |
Decimal('0.05')
|
Source code in src/athena/riskfreerates.py
FREDRiskFreeRateManager
¶
Bases: RiskFreeRateManager
Risk-free rate manager using FRED (Federal Reserve Economic Data).
Fetches Treasury Bill rates directly from FRED's CSV endpoint. Data is cached locally to avoid repeated downloads.
Source code in src/athena/riskfreerates.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
__init__(series=RiskFreeRateSeries.DTB3, min_date=None, max_date=None, use_cache=True)
¶
Initialize the FRED risk-free rate manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series
|
RiskFreeRateSeries
|
The FRED series to use (default: DTB3 - 3-Month T-Bill). |
DTB3
|
min_date
|
date | None
|
Earliest date to fetch data for (default: 5 years ago). |
None
|
max_date
|
date | None
|
Latest date to fetch data for (default: today). |
None
|
use_cache
|
bool
|
Whether to use local caching (default: True). |
True
|
Source code in src/athena/riskfreerates.py
get_rate(rate_date)
¶
Get the annualized risk-free rate for a specific date.
If no data is available for the exact date (weekend, holiday), looks back up to 14 days to find the most recent trading day.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate_date
|
date
|
The date to get the rate for. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
The annualized rate as a decimal (e.g., Decimal("0.045") for 4.5%). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no rate is available for the date or recent history. |
Source code in src/athena/riskfreerates.py
get_daily_rate(rate_date, trading_days_per_year=252)
¶
Get the daily risk-free rate for a specific date.
Converts the annualized rate to a daily rate by dividing by the number of trading days per year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate_date
|
date
|
The date to get the rate for. |
required |
trading_days_per_year
|
int
|
Number of trading days per year (default 252). |
252
|
Returns:
| Type | Description |
|---|---|
Decimal
|
The daily rate as a decimal. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no rate is available for the date. |
Source code in src/athena/riskfreerates.py
get_rates_for_range(start_date, end_date)
¶
Get all available annualized rates for a date range.
Only returns dates where actual FRED data exists (trading days). Does not interpolate or carry forward rates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
date
|
Start of the date range (inclusive). |
required |
end_date
|
date
|
End of the date range (inclusive). |
required |
Returns:
| Type | Description |
|---|---|
dict[date, Decimal]
|
Dictionary mapping dates to annualized rates (as decimals). |
Source code in src/athena/riskfreerates.py
get_available_dates()
¶
Get all dates for which rate data is available.
Returns:
| Type | Description |
|---|---|
list[date]
|
Sorted list of dates with available data. |