FinanceToolkit v1.9.0
The release of the Finance Toolkit v1.9.0 includes an entirely new Fixed Income module. This module contains a wide variety of fixed income related calculations such as the Effective Yield, the Macaulay Duration, the Modified Duration Convexity, the Yield to Maturity and models such as Black and Bachelier to valuate derivative instruments such as Swaptions.
For example, it is possible to perform Bond Calculations with collect_bond_statistics
which can valuate a variety of bonds based on used input:
Bond 1 | Bond 2 | Bond 3 | Bond 4 | Bond 5 | Bond 6 | |
---|---|---|---|---|---|---|
Par Value | 100 | 250 | 50 | 1000 | 85 | 320 |
Coupon Rate | 0.05 | 0.02 | 0.075 | 0 | 0.15 | 0.015 |
Years to Maturity | 5 | 10 | 2 | 10 | 3 | 1 |
Yield to Maturity | 0.08 | 0.021 | 0.03 | 0 | 0.16 | 0.04 |
Frequency | 1 | 1 | 4 | 1 | 2 | 12 |
Present Value | 88.0219 | 247.766 | 54.3518 | 1000 | 83.0353 | 312.171 |
Current Yield | 0.0568 | 0.0202 | 0.069 | 0 | 0.1535 | 0.0154 |
Effective Yield | 0.05 | 0.02 | 0.0771 | 0 | 0.1556 | 0.0151 |
Macaulay's Duration | 4.5116 | 9.1576 | 1.8849 | 10 | 2.5667 | 0.9932 |
Modified Duration | 4.1774 | 8.9693 | 1.8709 | 10 | 2.3766 | 0.9899 |
Effective Duration | 4.0677 | 8.5181 | 1.8477 | 9.4713 | 2.2952 | 0.9844 |
Dollar Duration | 3.677 | 22.2228 | 1.0168 | 100 | 1.9734 | 3.0902 |
DV01 | 0.0004 | 0.0022 | 0 | 0.01 | 0.0001 | 0 |
Convexity | 22.4017 | 93.7509 | 4.0849 | 110 | 7.0923 | 1.0662 |
This can be done with the following code:
from financetoolkit import FixedIncome
fixedincome = FixedIncome()
# Valuate a specific bond, for example Bond 1
fixedincome.collect_bond_statistics(
par_value=100,
coupon_rate=0.05,
years_to_maturity=5,
yield_to_maturity=0.08,
frequency=1,
)
Not only Bonds can be valuated, the module can also be used to valudate derivatives such as Swaptions utilizing the Black and Bachelier models. For example, the Black model can be used to valuate a Swaption:
from financetoolkit import FixedIncome
fixedincome = FixedIncome()
# You can also provide lists of values for the strike rate and years to maturity
# to define your own strike rates and years to maturity to display in the DataFrame
fixedincome.get_derivative_price(model_type='black', forward_rate=0.0325)
This returns a large DataFrame that shows the present value of such a swaption contract at a variety of strike rates and maturities.
Strike Rate | 2025-04-21 | 2026-04-21 | 2027-04-21 | 2028-04-20 | 2029-04-20 | 2030-04-20 | 2031-04-20 | 2032-04-19 | 2033-04-19 | 2034-04-19 |
---|---|---|---|---|---|---|---|---|---|---|
0.005 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0.01 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0.015 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0.02 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0.025 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0.03 | 0 | 0 | 0 | 0.04 | 0.25 | 0.9 | 2.3 | 4.68 | 8.22 | 12.98 |
0.035 | 24200.6 | 23426.7 | 22677.6 | 21952.5 | 21251.2 | 20573.2 | 19918.5 | 19286.4 | 18676.5 | 18088 |
0.04 | 72601.7 | 70280.1 | 68032.7 | 65857.2 | 63751.2 | 61712.6 | 59739.2 | 57828.9 | 55979.6 | 54189.6 |
0.045 | 121003 | 117133 | 113388 | 109762 | 106252 | 102854 | 99565.3 | 96381.4 | 93299.4 | 90315.9 |
0.05 | 169404 | 163987 | 158743 | 153667 | 148753 | 143996 | 139391 | 134934 | 130619 | 126442 |
0.055 | 217805 | 210840 | 204098 | 197571 | 191254 | 185138 | 179218 | 173487 | 167939 | 162569 |
0.06 | 266206 | 257694 | 249453 | 241476 | 233754 | 226280 | 219044 | 212039 | 205259 | 198695 |
0.065 | 314607 | 304547 | 294808 | 285381 | 276255 | 267421 | 258870 | 250592 | 242578 | 234821 |
0.07 | 363008 | 351400 | 340163 | 329286 | 318756 | 308563 | 298696 | 289144 | 279898 | 270948 |
0.075 | 411410 | 398254 | 385518 | 373191 | 361257 | 349705 | 338522 | 327697 | 317218 | 307074 |
0.08 | 459811 | 445107 | 430874 | 417095 | 403758 | 390846 | 378348 | 366250 | 354538 | 343200 |
0.085 | 508212 | 491960 | 476229 | 461000 | 446258 | 431988 | 418174 | 404802 | 391858 | 379327 |
0.09 | 556613 | 538814 | 521584 | 504905 | 488759 | 473130 | 458000 | 443355 | 429177 | 415453 |
0.095 | 605014 | 585667 | 566939 | 548810 | 531260 | 514272 | 497827 | 481907 | 466497 | 451580 |
0.1 | 653415 | 632521 | 612294 | 592714 | 573761 | 555413 | 537653 | 520460 | 503817 | 487706 |
0.105 | 701816 | 679374 | 657649 | 636619 | 616262 | 596555 | 577479 | 559012 | 541137 | 523832 |
0.11 | 750217 | 726227 | 703004 | 680524 | 658762 | 637697 | 617305 | 597565 | 578456 | 559959 |
0.115 | 798619 | 773081 | 748359 | 724429 | 701263 | 678839 | 657131 | 636118 | 615776 | 596085 |
0.12 | 847020 | 819934 | 793715 | 768334 | 743764 | 719980 | 696957 | 674670 | 653096 | 632211 |
0.125 | 895421 | 866787 | 839070 | 812238 | 786265 | 761122 | 736783 | 713223 | 690416 | 668338 |
0.13 | 943822 | 913641 | 884425 | 856143 | 828766 | 802264 | 776609 | 751775 | 727735 | 704464 |
It is also possible to access Government Bond rates from 30+ countries. For example, using get_government_bond_yields(short_term=False, period='monthly')
:
Australia | Austria | Belgium | Brazil | Bulgaria | Canada | Chile | China | Colombia | Costa Rica | Croatia | Czech Republic | Denmark | Estonia | Euro Area 19 | Finland | France | Germany | Greece | Hungary | Iceland | India | Indonesia | Ireland | Israel | Italy | Japan | Latvia | Lithuania | Luxembourg | Mexico | Netherlands | New Zealand | Norway | Poland | Portugal | Romania | Russia | Slovakia | Slovenia | South Africa | South Korea | Spain | Sweden | Switzerland | United Kingdom | United States | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2023-05 | 0.035 | 0.0303 | 0.0304 | 0.0728 | 0.0403 | 0.0305 | 0.0555 | 0.0269 | 0.1111 | nan | 0.0371 | 0.045 | 0.0254 | 0.0394 | 0.0321 | 0.0298 | 0.0294 | 0.0234 | 0.0398 | 0.0778 | nan | 0.0701 | 0.0636 | 0.0279 | 0.0379 | 0.0431 | 0.0043 | 0.0383 | 0.0288 | 0.0295 | 0.0876 | 0.0273 | 0.0423 | 0.0323 | 0.0593 | 0.0316 | 0.063 | nan | 0.0359 | 0.0315 | 0.1194 | 0.034 | 0.0341 | 0.0232 | 0.0085 | 0.0396 | 0.0357 |
2023-06 | 0.0392 | 0.0305 | 0.0305 | 0.0728 | 0.0403 | 0.0334 | 0.0531 | 0.0264 | 0.1015 | nan | 0.0373 | 0.0435 | 0.0257 | 0.0394 | 0.0316 | 0.03 | 0.0293 | 0.0238 | 0.037 | 0.072 | nan | 0.0705 | 0.0622 | 0.0278 | 0.0374 | 0.0407 | 0.004 | 0.0379 | 0.0288 | 0.0295 | 0.0857 | 0.0275 | 0.0448 | 0.0348 | 0.0591 | 0.0309 | 0.0611 | nan | 0.0362 | 0.0338 | 0.1194 | 0.0361 | 0.034 | 0.0246 | 0.0097 | 0.0437 | 0.0375 |
2023-07 | 0.0403 | 0.0312 | 0.0314 | 0.07 | 0.0403 | 0.0345 | 0.0533 | 0.0266 | 0.1022 | nan | 0.0374 | 0.0415 | 0.027 | 0.0409 | 0.0327 | 0.0307 | 0.0304 | 0.0246 | 0.0385 | 0.071 | nan | 0.0711 | 0.0633 | 0.029 | 0.0377 | 0.0416 | 0.0059 | 0.0381 | 0.0288 | 0.0303 | nan | 0.0284 | 0.0465 | 0.0364 | 0.0556 | 0.0323 | 0.062 | nan | 0.0369 | 0.034 | 0.1172 | 0.0368 | 0.035 | 0.0252 | 0.0098 | 0.0444 | 0.039 |
2023-08 | 0.0413 | 0.0318 | 0.0322 | 0.07 | 0.0403 | 0.0365 | 0.0563 | 0.0256 | 0.107 | nan | 0.0393 | 0.0426 | 0.0277 | 0.0415 | 0.0334 | 0.0315 | 0.0311 | 0.0255 | 0.0388 | 0.074 | nan | 0.0719 | 0.0636 | 0.0296 | 0.0391 | 0.0422 | 0.0064 | 0.0385 | 0.0288 | 0.0308 | 0.091 | 0.0292 | 0.049 | 0.0381 | 0.0559 | 0.0331 | 0.0634 | nan | 0.038 | 0.0348 | 0.1172 | 0.0386 | 0.0359 | 0.0275 | 0.0095 | 0.0453 | 0.0417 |
2023-09 | 0.0421 | 0.0329 | 0.0332 | 0.07 | 0.0403 | 0.0382 | 0.0597 | 0.0268 | 0.1187 | nan | 0.0395 | 0.0449 | 0.0283 | 0.0425 | 0.0351 | 0.0325 | 0.0324 | 0.0266 | 0.0408 | 0.0708 | nan | 0.0717 | 0.0691 | 0.0309 | 0.04 | 0.0451 | 0.0076 | 0.0388 | 0.0288 | 0.0316 | 0.0968 | 0.0304 | 0.0505 | 0.0382 | 0.0568 | 0.0345 | 0.0748 | nan | 0.0391 | 0.0347 | 0.1206 | 0.0395 | 0.0372 | 0.0289 | 0.0109 | 0.0442 | 0.0438 |
2023-10 | 0.0463 | 0.0349 | 0.0352 | 0.0655 | 0.0403 | 0.0406 | 0.0653 | 0.0269 | 0.1181 | nan | 0.0418 | 0.0472 | 0.0305 | 0.0409 | 0.0372 | 0.0347 | 0.0345 | 0.0282 | 0.043 | 0.0753 | nan | 0.0735 | 0.0705 | 0.0327 | 0.0438 | 0.0488 | 0.0095 | 0.0414 | 0.0288 | 0.0332 | nan | 0.0321 | 0.0546 | 0.0395 | 0.0584 | 0.0359 | 0.0681 | nan | 0.0412 | 0.0367 | 0.1236 | 0.0427 | 0.0395 | 0.0302 | 0.0105 | 0.0457 | 0.048 |
2023-11 | 0.0458 | 0.0321 | 0.0323 | 0.0655 | 0.0403 | 0.0371 | 0.0598 | nan | 0.1089 | nan | 0.0393 | 0.0443 | 0.0279 | 0.0367 | 0.0342 | 0.032 | 0.0319 | 0.026 | 0.0388 | 0.0701 | nan | nan | nan | 0.0301 | 0.0427 | 0.0443 | 0.0066 | 0.0398 | 0.0288 | 0.0303 | 0.1023 | 0.0295 | 0.051 | 0.0368 | 0.0554 | nan | 0.0675 | nan | 0.0386 | 0.0353 | 0.1179 | 0.0389 | 0.0366 | 0.0276 | 0.0082 | 0.0427 | 0.045 |
Next to that, the well-known Corporate Bond indices from ICE BofA are also available. For example this shows the Corporate Bond Yield and Option-Adjust Spread (OAS) for a variety of maturities. You can access this data with get_ice_bofa_effective_yield
and get_ice_bofa_option_adjusted_spread
.
Central Bank Rates such as the EURIBOR and SOFR rates can be accessed that serve as the reference (or benchmark) rate of a large variety of derivative contracts such as swaps and futures. For example:
from financetoolkit import FixedIncome
fixedincome = FixedIncome(start_date='2023-12-01')
euribor_rates = fixedincome.get_euribor_rates()
Which returns:
1-Month | 3-Month | 6-Month | 12-Month | |
---|---|---|---|---|
2023-12 | 0.0386 | 0.0393 | 0.0392 | 0.0367 |
2024-01 | 0.0387 | 0.0393 | 0.0389 | 0.0361 |
2024-02 | 0.0387 | 0.0392 | 0.039 | 0.0367 |
Next to that, I've added in the European Central Banks which include:
- The main refinancing operations (MRO) rate is the interest rate banks pay when they borrow money from the ECB for one week. When they do this, they have to provide collateral to guarantee that the money will be paid back.
- The marginal lending facility rate is the interest rate banks pay when they borrow from the ECB overnight. When they do this, they have to provide collateral, for example securities, to guarantee that the money will be paid back.
- The deposit facility rate which is one of the three interest rates the ECB sets every six weeks as part of its monetary policy. The rate defines the interest banks receive for depositing money with the central bank overnight.
These can be shown by using:
from financetoolkit import FixedIncome
fixedincome = FixedIncome(start_date='2000-01-01')
fixedincome.get_european_central_bank_rates()
Which returns (when plotted):
I've also added in the Federal Funds rates which include:
- The effective federal funds rate (EFFR) which is calculated as a volume-weighted median of overnight federal funds transactions reported in the FR 2420 Report of Selected Money Market Rates.
- The overnight bank funding rate (OBFR) which is calculated as a volume-weighted median of overnight federal funds transactions, Eurodollar transactions, and the domestic deposits reported as “Selected Deposits” in the FR 2420 Report.
- The TGCR which is calculated as a volume-weighted median of transaction-level tri-party repo data collected from the Bank of New York Mellon.
- The BGCR which is calculated as a volume-weighted median of transaction-level tri-party repo data collected from the Bank of New York Mellon as well as GCF Repo transaction data obtained from the U.S. Department of the Treasury’s Office of Financial Research (OFR).
- The SOFR which is calculated as a volume-weighted median of transaction-level tri-party repo data collected from the Bank of New York Mellon as well as GCF Repo transaction data and data on bilateral Treasury repo transactions cleared through FICC's DVP service, which are obtained from the U.S. Department of the Treasury’s Office of Financial Research (OFR).
These can be shown by using (and defining the rate):
from financetoolkit import FixedIncome
fixedincome = FixedIncome(start_date='2016-01-01')
# Effective Federal Funds Rate
fixedincome.get_federal_reserve_rates(rate='EFFR')
# Secured Overnight Financing Rate
fixedincome.get_federal_reserve_rates(rate='SOFR')
Which returns (when plotted):