currency¶
athena.currency
¶
Currency
¶
Bases: Enum
Supported currencies for exchange rate conversions.
Source code in src/athena/currency.py
ExchangeRateManager
¶
Bases: ABC
Abstract base class for currency exchange rate providers.
Source code in src/athena/currency.py
__init__(min_datetime=None, max_datetime=None)
¶
Initialize the exchange rate manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_datetime
|
datetime | None
|
Earliest date for which rates are available. |
None
|
max_datetime
|
datetime | None
|
Latest date for which rates are available. |
None
|
Source code in src/athena/currency.py
get_exchange_rate(from_currency, to_currency, datetime=None)
abstractmethod
¶
Get the exchange rate between two currencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_currency
|
Currency
|
The source currency. |
required |
to_currency
|
Currency
|
The target currency. |
required |
datetime
|
datetime | None
|
The date for the rate lookup. If None, uses the current date. |
None
|
Returns:
| Type | Description |
|---|---|
Decimal
|
The exchange rate as a Decimal. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always, must be overridden by subclasses. |
Source code in src/athena/currency.py
FixedExchangeRateManager
¶
Bases: ExchangeRateManager
Exchange rate manager using fixed, hardcoded rates.
Provides static exchange rates that do not vary by date. Useful for testing or when live rates are not needed.
Source code in src/athena/currency.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 | |
__init__(exchange_rates={})
¶
Initialize with optional custom exchange rates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exchange_rates
|
dict[tuple[Currency, Currency], Decimal]
|
Custom rates to use. Missing pairs are filled from global_exchange_rates defaults. |
{}
|
Source code in src/athena/currency.py
set_exchange_rate(from_currency, to_currency, rate)
¶
Set or override the exchange rate for a currency pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_currency
|
Currency
|
The source currency. |
required |
to_currency
|
Currency
|
The target currency. |
required |
rate
|
Decimal
|
The exchange rate to set. |
required |
Source code in src/athena/currency.py
get_exchange_rate(from_currency, to_currency, datetime=None)
¶
Get the fixed exchange rate between two currencies.
Falls back to USD-triangulated conversion if no direct rate exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_currency
|
Currency
|
The source currency. |
required |
to_currency
|
Currency
|
The target currency. |
required |
datetime
|
datetime | None
|
Ignored; included for interface compatibility. |
None
|
Returns:
| Type | Description |
|---|---|
Decimal
|
The exchange rate as a Decimal. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no rate is available for the currency pair. |
Source code in src/athena/currency.py
FederalReserveExchangeRateManager
¶
Bases: ExchangeRateManager
Exchange rate manager that fetches historical rates from the Federal Reserve H.10 data.
Downloads daily exchange rate CSV data from the Fed's website and caches it locally. Supports lookback of up to 14 days for missing dates.
Source code in src/athena/currency.py
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 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
__init__(min_datetime=None, max_datetime=None, use_cache=False)
¶
Initialize by fetching exchange rate data from the Federal Reserve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_datetime
|
datetime | None
|
Start of the date range. Defaults to 2020-01-01. |
None
|
max_datetime
|
datetime | None
|
End of the date range. Defaults to now. |
None
|
use_cache
|
bool
|
If True, use disk-cached CSV data when available and fresh. |
False
|
Source code in src/athena/currency.py
get_exchange_rate(from_currency, to_currency, datetime=None)
¶
Get exchange rate for a currency pair on a specific date.
If no data is available for the requested date, looks back up to 14 days to handle weekends, bank holidays, and publication delays. If neither currency is USD, converts via USD (e.g., HKD -> USD -> CAD).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_currency
|
Currency
|
The source currency. |
required |
to_currency
|
Currency
|
The target currency. |
required |
datetime
|
datetime | None
|
The date for the rate lookup. Defaults to now. |
None
|
Returns:
| Type | Description |
|---|---|
Decimal
|
The exchange rate as a Decimal. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no rate is available for the pair within the 14-day lookback window. |