Transparent and Efficient Financial Analysis
MIT License
Bot releases are hidden (Show)
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:
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:
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):
Published by JerBouma 7 months ago
This release contains new Fixed Income metrics as part of the Economics module, these contain Option-Adjusted Spreads, Effective Yields, Total Returns and Yield to Worst. For example, see the Option-Adjusted Spread below (see documentation here):
The Option-Adjusted Spread (OAS) is the spread relative to a risk-free interest rate, usually measured in basis points (bp), that equates the theoretical present value of a series of uncertain cash flows to the market price of a fixed-income investment. The spread is added to the risk-free rate to compensate for the uncertainty of the cash flows. This is usually a better alternative than the usual Z-spread used to price derivatives.
Furthermore, @northern-64bit (maintainer of scikit-multilearn-ng) introduced new AR and MA models that can be utilised with any type of time series. For more information, see https://github.com/JerBouma/FinanceToolkit/pull/117. @northern-64bit actually introduced many more models in the Finance Toolkit as seen here.
Furthermore, I've introduced bug fixes solving #128 and #129.
Published by JerBouma 9 months ago
This release includes the Binomial Model, a mathematical model for pricing both American as well as European options. The Binomial Model is a discrete-time model that calculates the price of an option by creating a riskless hedge portfolio that replicates the payoff of the option. The model is based on the assumption that the price of the underlying asset follows a binomial distribution. The Binomial Model is a simple and intuitive model that is widely used in practice. It is also the basis for more complex models. See for an elaborate explanation the documentation as found here.
For example, when using the following code:
from financetoolkit import Toolkit
companies = Toolkit(["AAPL", "MSFT"], api_key="FINANCIAL_MODELING_PREP_KEY")
companies.options.get_binomial_model(show_input_info=True)
It returns a large DataFrame with the binomial tree for each company and each strike price around the current price (as defined by the start_date
parameter).
The resulting output is a DataFrame containing the tickers, strike prices and movements as the index and the time to expiration as the columns. The movements index contains the number of up movements and the number of down movements. The output is the binomial tree displayed in a table. E.g. when using 10 time steps, the table for each strike price from each company will contain the actual binomial tree as also depicted in the image as seen below. Find the documentation here.
When selecting for example Apple at a Strike Price of 140 you will get the actual Binomial Tree depicted as a table, this represents the tree you see in the image at the top.
Movement | 2024-02-02 | 2024-03-09 | 2024-04-15 | 2024-05-21 | 2024-06-27 | 2024-08-02 | 2024-09-08 | 2024-10-14 | 2024-11-20 | 2024-12-26 | 2025-02-01 |
---|---|---|---|---|---|---|---|---|---|---|---|
UUUUUUUUUU | 54.7747 | 69.9327 | 87.4757 | 107.31 | 129.344 | 153.573 | 180.122 | 209.208 | 241.069 | 275.965 | 314.18 |
UUUUUUUUUD | nan | 39.9569 | 52.8423 | 68.2288 | 86.0206 | 106.037 | 128.14 | 152.365 | 178.911 | 207.994 | 239.852 |
UUUUUUUUDD | nan | nan | 27.3011 | 37.7763 | 50.8718 | 66.5774 | 84.6651 | 104.825 | 126.925 | 151.146 | 177.689 |
UUUUUUUDDD | nan | nan | nan | 16.9659 | 24.8886 | 35.4656 | 48.9066 | 65.0645 | 83.4462 | 103.602 | 125.698 |
UUUUUUDDDD | nan | nan | nan | nan | 9.1158 | 14.4288 | 22.208 | 33.0259 | 47.083 | 63.8384 | 82.2161 |
UUUUUDDDDD | nan | nan | nan | nan | nan | 3.8311 | 6.7007 | 11.4806 | 19.124 | 30.5822 | 45.85 |
UUUUDDDDDD | nan | nan | nan | nan | nan | nan | 0.9669 | 1.9327 | 3.8631 | 7.722 | 15.4353 |
UUUDDDDDDD | nan | nan | nan | nan | nan | nan | nan | 0 | 0 | 0 | 0 |
UUDDDDDDDD | nan | nan | nan | nan | nan | nan | nan | nan | 0 | 0 | 0 |
UDDDDDDDDD | nan | nan | nan | nan | nan | nan | nan | nan | nan | 0 | 0 |
DDDDDDDDDD | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | 0 |
The model contains parameters to lengthen the time steps, change the risk-free rate and the dividend yield but more importantly, make it possible to calculate the price of both American and European options as well as Call and Put options. For example, let's calculate the price of a American Put option with a strike price of 140 for Apple again:
from financetoolkit import Toolkit
companies = Toolkit(["AAPL", "MSFT"], api_key="FINANCIAL_MODELING_PREP_KEY")
companies.options.get_binomial_model(
show_input_info=True,
put_option=True,
american_option=True,
timesteps=12,
risk_free_rate=0.01)
Which returns the Option valuations for an American Put Option.
Movement | 2024-02-02 | 2024-03-03 | 2024-04-02 | 2024-05-03 | 2024-06-02 | 2024-07-03 | 2024-08-02 | 2024-09-01 | 2024-10-02 | 2024-11-01 | 2024-12-02 | 2025-01-01 | 2025-02-01 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
UUUUUUUUUUUU | 2.3581 | 1.1115 | 0.4236 | 0.116 | 0.0171 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
UUUUUUUUUUUD | nan | 3.7011 | 1.8524 | 0.7546 | 0.2225 | 0.0355 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
UUUUUUUUUUDD | nan | nan | 5.6933 | 3.0346 | 1.3274 | 0.4238 | 0.0736 | 0 | 0 | 0 | 0 | 0 | 0 |
UUUUUUUUUDDD | nan | nan | nan | 8.5588 | 4.8737 | 2.3002 | 0.8005 | 0.1529 | 0 | 0 | 0 | 0 | 0 |
UUUUUUUUDDDD | nan | nan | nan | nan | 12.5322 | 7.6463 | 3.9148 | 1.4975 | 0.3173 | 0 | 0 | 0 | 0 |
UUUUUUUDDDDD | nan | nan | nan | nan | nan | 17.8023 | 11.6676 | 6.518 | 2.7676 | 0.6586 | 0 | 0 | 0 |
UUUUUUDDDDDD | nan | nan | nan | nan | nan | nan | 24.4233 | 17.2193 | 10.5575 | 5.0375 | 1.3671 | 0 | 0 |
UUUUUDDDDDDD | nan | nan | nan | nan | nan | nan | nan | 32.2051 | 24.4052 | 16.5049 | 8.9884 | 2.8376 | 0 |
UUUUDDDDDDDD | nan | nan | nan | nan | nan | nan | nan | nan | 40.6414 | 32.9347 | 24.6074 | 15.6102 | 5.89 |
UUUDDDDDDDDD | nan | nan | nan | nan | nan | nan | nan | nan | nan | 48.9936 | 41.9389 | 34.3151 | 26.0772 |
UUDDDDDDDDDD | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | 56.6615 | 50.2044 | 43.2257 |
UDDDDDDDDDDD | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | 63.702 | 57.7929 |
DDDDDDDDDDDD | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | 70.1673 |
Under the hood of this model the stock prices are simulated based on up and down movements. These can be graphically depicted as a binomial tree and help in understanding the calculated option prices for each node in. More information about these stock price simulations can be found in the documentation here and as follows:
from financetoolkit import Toolkit
companies = Toolkit(["AAPL", "MSFT"], api_key="FINANCIAL_MODELING_PREP_KEY")
companies.options.get_stock_price_simulations(show_input_info=True, timesteps=10)
Which would return for Apple the following graph when plotted:
Given that the Finance Toolkit is modular, you do not have to use the Toolkit functionality directly and can also call each functionality of the model separately. For example, this shows the output of using the model directly, specifying each parameter yourself.
Published by JerBouma 9 months ago
This new release contains intraday historical data which makes it possible to calculate Risk, Performance and Technical metrics based on a 1 min, 5 min, 15 min, 30 min or 1 hour interval. For example, you can obtain the Capital Asset Pricing Model (CAPM) per model in which it calculates the beta for each hour.
Or for example Williams %R on an hourly basis as follows:
Next to that, I've done a lot of polishing. A user noticed that there were some issues with working with delisted companies. As Financial Modeling Prep allows you to get data on these companies whereas Yahoo Finance doesn't, I needed to make sure that the Finance Toolkit didn't attempt to query the Yahoo Finance and return an error. This has been resolved (all of these companies are delisted):
Furthermore, I've fixed small bugs, updated the documentation and more. All in all it should be a more pleasant experience!
Published by JerBouma 9 months ago
It's time for another major release which consists of a full blown Options menu including all First, Second and Third Order Greeks such as Delta, Vega, Gamma, Theta and Ultima. Find the entire list of Greeks here. Update your Finance Toolkit now with:
pip install financetoolkit -U
Based on the Black Scholes formula, it is now possible to get theoretical option prices and greeks for a range of stocks being able to plot charts such as the following:
For example, the following code gets you all Greeks for Tesla.
from financetoolkit import Toolkit
toolkit = Toolkit(["TSLA", "MU"], api_key="FINANCIAL_MODELING_PREP_KEY")
all_greeks = toolkit.options.collect_all_greeks(start_date='2024-01-03')
all_greeks.loc['TSLA', '2024-01-04']
Which returns (Stock Price: 238.45, Volatility: 55.4%, Dividend Yield: 0.0% and Risk Free Rate: 3.91%):
Strike Price | Delta | Dual Delta | Vega | Theta | Rho | Epsilon | Lambda | Gamma | Dual Gamma | Vanna | Charm | Vomma | Vera | Veta | PD | Speed | Zomma | Color | Ultima |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
180 | 1 | -0.9999 | 0 | -0.0193 | 0.4931 | -0.6533 | 4.0782 | 0 | 0 | -0 | 0 | 0 | -0 | 0 | 0 | -0 | 0 | 0 | 0 |
185 | 1 | -0.9999 | 0 | -0.0198 | 0.5068 | -0.6533 | 4.4595 | 0 | 0 | -0 | 0 | 0 | -0 | 0 | 0 | -0 | 0 | 0 | 0 |
190 | 1 | -0.9999 | 0 | -0.0204 | 0.5205 | -0.6533 | 4.9195 | 0 | 0 | -0 | 0 | 0 | -0 | 0 | 0 | -0 | 0 | 0 | 0 |
195 | 1 | -0.9999 | 0 | -0.0209 | 0.5342 | -0.6533 | 5.4853 | 0 | 0 | -0 | 0 | 0 | -0 | 0 | 0 | -0 | 0 | 0 | 0 |
200 | 1 | -0.9999 | 0 | -0.0214 | 0.5479 | -0.6533 | 6.1981 | 0 | 0 | -0 | 0 | 0 | -0 | 0.0012 | 0 | -0 | 0 | 0 | 0 |
205 | 1 | -0.9999 | 0 | -0.022 | 0.5616 | -0.6533 | 7.1239 | 0 | 0 | -0 | 0.0004 | 0.0003 | -0 | 0.1071 | 0 | -0 | 0 | 0.0003 | 0.0001 |
210 | 1 | -0.9999 | 0 | -0.0226 | 0.5753 | -0.6533 | 8.3747 | 0 | 0 | -0.0002 | 0.0199 | 0.0108 | -0.0001 | 4.1973 | 0 | -0 | 0.0001 | 0.012 | 0.0032 |
215 | 0.9998 | -0.9997 | 0.0001 | -0.0252 | 0.5889 | -0.6532 | 10.1567 | 0.0001 | 0.0001 | -0.0041 | 0.414 | 0.1838 | -0.0027 | 72.9841 | 0.0001 | -0 | 0.002 | 0.198 | 0.0324 |
220 | 0.9974 | -0.9971 | 0.001 | -0.0512 | 0.601 | -0.6516 | 12.8704 | 0.0012 | 0.0014 | -0.04 | 4.0384 | 1.3972 | -0.0264 | 580.934 | 0.0014 | -0.0005 | 0.0141 | 1.4208 | 0.1193 |
225 | 0.9783 | -0.9767 | 0.0065 | -0.2027 | 0.6021 | -0.6391 | 17.2415 | 0.0075 | 0.0084 | -0.1863 | 18.7659 | 4.6975 | -0.1235 | 2158.08 | 0.0084 | -0.0022 | 0.0409 | 4.115 | 0.0867 |
230 | 0.8966 | -0.8912 | 0.0224 | -0.6437 | 0.5616 | -0.5857 | 24.2406 | 0.026 | 0.028 | -0.4003 | 40.2357 | 6.3078 | -0.2677 | 3809 | 0.028 | -0.0049 | 0.0261 | 2.5995 | -0.1644 |
235 | 0.6987 | -0.6885 | 0.0435 | -1.2217 | 0.4433 | -0.4565 | 34.5702 | 0.0504 | 0.0519 | -0.3092 | 30.7944 | 2.0098 | -0.2139 | 3626.75 | 0.0519 | -0.004 | -0.0676 | -6.8748 | -0.0997 |
240 | 0.4187 | -0.4074 | 0.0488 | -1.361 | 0.2679 | -0.2735 | 48.191 | 0.0565 | 0.0558 | 0.1652 | -17.2254 | 0.4231 | 0.0945 | 3408.71 | 0.0558 | 0.0014 | -0.0971 | -9.7985 | -0.0227 |
245 | 0.1798 | -0.1722 | 0.0327 | -0.911 | 0.1156 | -0.1174 | 64.4551 | 0.0379 | 0.0359 | 0.4473 | -45.5831 | 5.1158 | 0.2833 | 4082.47 | 0.0359 | 0.0049 | -0.0092 | -0.8794 | -0.1971 |
250 | 0.0534 | -0.0503 | 0.0136 | -0.3769 | 0.0344 | -0.0349 | 82.5525 | 0.0157 | 0.0143 | 0.322 | -32.7 | 6.4816 | 0.2066 | 3305.97 | 0.0143 | 0.0036 | 0.0467 | 4.7605 | -0.0412 |
255 | 0.0108 | -0.01 | 0.0036 | -0.0992 | 0.007 | -0.0071 | 101.798 | 0.0041 | 0.0036 | 0.12 | -12.1728 | 3.4389 | 0.0774 | 1510.91 | 0.0036 | 0.0014 | 0.0324 | 3.2868 | 0.1451 |
260 | 0.0015 | -0.0014 | 0.0006 | -0.017 | 0.001 | -0.001 | 121.702 | 0.0007 | 0.0006 | 0.0266 | -2.6915 | 0.9828 | 0.0172 | 404.445 | 0.0006 | 0.0003 | 0.0101 | 1.0246 | 0.1043 |
265 | 0.0001 | -0.0001 | 0.0001 | -0.002 | 0.0001 | -0.0001 | 141.935 | 0.0001 | 0.0001 | 0.0037 | -0.3769 | 0.1682 | 0.0024 | 66.8956 | 0.0001 | 0 | 0.0018 | 0.1826 | 0.031 |
270 | 0 | -0 | 0 | -0.0002 | 0 | -0 | 162.286 | 0 | 0 | 0.0003 | -0.0349 | 0.0183 | 0.0002 | 7.148 | 0 | 0 | 0.0002 | 0.0203 | 0.0051 |
275 | 0 | -0 | 0 | -0 | 0 | -0 | 182.618 | 0 | 0 | 0 | -0.0022 | 0.0013 | 0 | 0.5115 | 0 | 0 | 0 | 0.0015 | 0.0005 |
280 | 0 | -0 | 0 | -0 | 0 | -0 | 202.841 | 0 | 0 | 0 | -0.0001 | 0.0001 | 0 | 0.0253 | 0 | 0 | 0 | 0.0001 | 0 |
285 | 0 | -0 | 0 | -0 | 0 | -0 | 222.899 | 0 | 0 | 0 | -0 | 0 | 0 | 0.0009 | 0 | 0 | 0 | 0 | 0 |
290 | 0 | -0 | 0 | -0 | 0 | -0 | 242.753 | 0 | 0 | 0 | -0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
295 | 0 | -0 | 0 | -0 | 0 | -0 | 262.382 | 0 | 0 | 0 | -0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Here, it automatically creates Strike Prices around the current stock price (or any price in the past if you change the start_date) parameter as well as plots forward for the time to expiration. Things that you can change with ease yourself if you like. For example:
from financetoolkit import Toolkit
toolkit = Toolkit(["MSFT", "ASML"], api_key="FINANCIAL_MODELING_PREP_KEY")
rho = toolkit.options.get_rho(
start_date="2020-01-02",
strike_price_range=0.15,
expiration_time_range=20,
put_option=True,
show_input_info=True
)
rho.loc['MSFT']
Which returns:
Based on the period 2013-01-22 to 2024-01-17 the following parameters were used:
Stock Price: ASML (291.79), Benchmark (305.06), MSFT (154.78)
Volatility: ASML (34.77%), Benchmark (17.46%), MSFT (26.99%)
Dividend Yield: MSFT (0.96%), ASML (0.6%)
Risk Free Rate: 1.88%
Strike Price | 2020-01-03 | 2020-01-04 | 2020-01-05 | 2020-01-06 | 2020-01-07 | 2020-01-08 | 2020-01-09 | 2020-01-10 | 2020-01-11 | 2020-01-12 | 2020-01-13 | 2020-01-14 | 2020-01-15 | 2020-01-16 | 2020-01-17 | 2020-01-18 | 2020-01-19 | 2020-01-20 | 2020-01-21 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
130 | -0 | -0 | -0 | -0 | -0 | -0 | -0 | -0 | -0.0001 | -0.0002 | -0.0004 | -0.0008 | -0.0015 | -0.0026 | -0.0041 | -0.0062 | -0.0089 | -0.0124 | -0.0167 |
135 | -0 | -0 | -0 | -0 | -0 | -0.0001 | -0.0003 | -0.001 | -0.0022 | -0.0043 | -0.0076 | -0.0122 | -0.0185 | -0.0265 | -0.0365 | -0.0486 | -0.0629 | -0.0794 | -0.0982 |
140 | -0 | -0 | -0 | -0.0003 | -0.0015 | -0.0045 | -0.0101 | -0.0192 | -0.0322 | -0.0493 | -0.0709 | -0.0968 | -0.1271 | -0.1616 | -0.2003 | -0.2429 | -0.2895 | -0.3397 | -0.3934 |
145 | -0 | -0.0004 | -0.0047 | -0.017 | -0.0396 | -0.0727 | -0.1156 | -0.1676 | -0.2277 | -0.295 | -0.3689 | -0.4486 | -0.5335 | -0.6233 | -0.7174 | -0.8154 | -0.917 | -1.022 | -1.13 |
150 | -0.0055 | -0.0485 | -0.1251 | -0.223 | -0.3353 | -0.4579 | -0.5883 | -0.7249 | -0.8666 | -1.0125 | -1.162 | -1.3145 | -1.4698 | -1.6275 | -1.7873 | -1.949 | -2.1125 | -2.2776 | -2.4442 |
155 | -0.2302 | -0.4512 | -0.671 | -0.8903 | -1.1094 | -1.3284 | -1.5474 | -1.7663 | -1.9853 | -2.2043 | -2.4234 | -2.6425 | -2.8617 | -3.081 | -3.3004 | -3.5198 | -3.7393 | -3.9589 | -4.1785 |
160 | -0.4343 | -0.8348 | -1.2016 | -1.5461 | -1.8754 | -2.1938 | -2.504 | -2.8078 | -3.1063 | -3.4006 | -3.6912 | -3.9787 | -4.2636 | -4.5461 | -4.8265 | -5.1051 | -5.382 | -5.6574 | -5.9314 |
165 | -0.452 | -0.9034 | -1.35 | -1.7871 | -2.2125 | -2.6264 | -3.0295 | -3.4229 | -3.8077 | -4.1848 | -4.5552 | -4.9194 | -5.2782 | -5.6322 | -5.9817 | -6.3272 | -6.6691 | -7.0076 | -7.3431 |
170 | -0.4657 | -0.9314 | -1.397 | -1.8618 | -2.3248 | -2.7846 | -3.2402 | -3.6907 | -4.1358 | -4.5753 | -5.0092 | -5.4376 | -5.8608 | -6.2788 | -6.6921 | -7.1007 | -7.5049 | -7.9051 | -8.3013 |
Furthermore, each module now has it's own dedicated Jupyter Notebook. Find all of them below or on my website here.
Published by JerBouma 10 months ago
This release features the Black Scholes Model, Present Value of Growth Opportunities (PVGO) and a variety of bug fixes.
Starting with the Black Scholes model, I've built in a method that automatically calculates the theoretical options value with strike prices that are near the current stock price and for a lengthy period of time. All of this you can expand yourself if desired with the strike_price_range
, strike_step_size
and expiration_time_range
parameters. By default, the strike prices between 75% and 125% of the current stock price are used and the time to expiration is calculated for the upcoming 30 days.
For example:
from financetoolkit import Toolkit
companies = Toolkit(
tickers=['GOOGL', "MSFT", 'AAPL'],
api_key="FMP_KEY",
start_date='2022-01-01',
end_date='2023-01-01'
)
companies.risk.get_black_scholes_model()
Which returns:
I've also added in the Present Value of Growth Opportunities (PVGO), a metric that uses WACC and Earnings per Share to determine the attractiveness of companies in the near future. This was requested by #88.
from financetoolkit import Toolkit
companies = Toolkit(
tickers=['GOOGL', "MSFT", 'AAPL'],
api_key="FMP_KEY",
quarterly=True
)
companies.models.get_present_value_of_growth_opportunities(calculate_daily=True)
Which returns:
Next to that, #94 noted that the Average Shares got adjusted through currency conversions. This has been corrected. Read in the new Q&A why numbers can sometimes deviate from FinancialModelingPrep.
Published by JerBouma 10 months ago
Happy New Year Everyone 🍾
This release includes an entirely new class which is the Discovery class. This class will help in discovering new instruments that can be inputted directly into the Finance Toolkit for further analysis. Find the documentation here.
For example, by importing the Discovery module directly, it is possible to obtain a large list of companies.
from financetoolkit import Discovery
discovery = Discovery(api_key="FINANCIAL_MODELING_PREP_KEY")
stock_list = discovery.get_stock_list()
# The total list equals over 60.000 rows
stock_list.iloc[48000:48010]
Which returns:
Symbol | Name | Price | Exchange | Exchange Code |
---|---|---|---|---|
RBL.AX | Redbubble Limited | 0.54 | Australian Securities Exchange | ASX |
RBL.BO | Rane Brake Lining Limited | 870.05 | Bombay Stock Exchange | BSE |
RBL.NS | Rane Brake Lining Limited | 870.05 | National Stock Exchange of India | NSE |
RBLAY | Robinsons Land Corporation | 4.61 | Other OTC | PNK |
RBLBANK.BO | RBL Bank Limited | 280.9 | Bombay Stock Exchange | BSE |
RBLBANK.NS | RBL Bank Limited | 280.9 | National Stock Exchange of India | NSE |
RBLN-B.CO | Roblon A/S | 91.8 | Copenhagen | CPH |
RBLX | Roblox Corporation | 45.72 | New York Stock Exchange | NYSE |
RBMNF | Rugby Resources Ltd. | 0.065 | Other OTC | PNK |
RBMS.JK | PT Ristia Bintang Mahkotasejati Tbk | 50 | Jakarta Stock Exchange | JKT |
It also enables stock screeners:
from financetoolkit import Discovery
discovery = Discovery(api_key="FINANCIAL_MODELING_PREP_KEY")
discovery.get_stock_screener(
market_cap_higher=1000000,
market_cap_lower=200000000000,
price_higher=100,
price_lower=200,
beta_higher=1,
beta_lower=1.5,
volume_higher=100000,
volume_lower=2000000,
dividend_higher=1,
dividend_lower=2,
is_etf=False
)
Which returns:
Symbol | Name | Market Cap | Sector | Industry | Beta | Price | Dividend | Volume | Exchange | Exchange Code | Country |
---|---|---|---|---|---|---|---|---|---|---|---|
NKE | NIKE, Inc. | 163403295604 | Consumer Cyclical | Footwear & Accessories | 1.079 | 107.36 | 1.48 | 1045865 | New York Stock Exchange | NYSE | US |
SAF.PA | Safran SA | 66234006559 | Industrials | Aerospace & Defense | 1.339 | 160.16 | 1.35 | 119394 | Paris | EURONEXT | FR |
ROST | Ross Stores, Inc. | 46724188589 | Consumer Cyclical | Apparel Retail | 1.026 | 138.785 | 1.34 | 169879 | NASDAQ Global Select | NASDAQ | US |
HES | Hess Corporation | 44694706090 | Energy | Oil & Gas E&P | 1.464 | 145.51 | 1.75 | 123147 | New York Stock Exchange | NYSE | US |
Which then can be directly inputted into the Finance Toolkit:
from financetoolkit import Toolkit
companies = Toolkit(
tickers=['NKE', 'SAF.PA', 'ROST', 'HES'],
api_key="FINANCIAL_MODELING_PREP_KEY",
)
companies.ratios.get_price_earnings_ratio()
Which returns:
2014 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | |
---|---|---|---|---|---|---|---|---|---|---|
HES | 8.4355 | -3.9366 | -2.8064 | -3.3368 | -39.7483 | -79.129 | -5.4733 | 25.1712 | 19.5719 | |
NKE | 29.4181 | 31.0527 | 21.9158 | 23.5325 | 60.6729 | 39.2127 | 86.2596 | 45.9014 | 30.8813 | 33.6161 |
ROST | 19.5859 | 19.8813 | 21.7047 | 21.3971 | 18.6637 | 24.4335 | 493.771 | 22.9419 | 26.2563 | |
SAF.PA | -152.997 | -57.6348 | 14.3119 | 7.1287 | 34.6723 | 24.0264 | 142.461 | 686.616 | -21.0077 |
Next to that, I've also grouped the TQDM statements when using Ratios or Models. So instead of 5 bars, it displays just 2. Furthermore, I've extended the custom ratios functionality, see here.
Published by JerBouma 10 months ago
Added a lot more economic metrics (over 50) into the Finance Toolkit, find the total list here. For example, get insights into how the United States Government spend their income:
from financetoolkit import Economics
economics = Economics()
central_government_spending = economics.get_central_government_spending()
central_government_spending['United States']
Which returns:
General Public Services | Defence | Public Order and Safety | Economic Affairs | Environmental Protection | Housing and Community Amenities | Health | Recreation, Culture and Religion | Education | Social Protection | |
---|---|---|---|---|---|---|---|---|---|---|
2007 | 0.1578 | 0.186 | 0.0148 | 0.0578 | 0 | 0.0192 | 0.2486 | 0.0015 | 0.0222 | 0.2921 |
2008 | 0.1392 | 0.1861 | 0.0148 | 0.069 | 0 | 0.0188 | 0.2369 | 0.0014 | 0.0221 | 0.3117 |
2009 | 0.1198 | 0.1772 | 0.0148 | 0.0639 | 0 | 0.0406 | 0.2417 | 0.0014 | 0.028 | 0.3127 |
2010 | 0.1211 | 0.1759 | 0.0148 | 0.0585 | 0 | 0.0309 | 0.2416 | 0.0015 | 0.0346 | 0.3211 |
2011 | 0.1324 | 0.1754 | 0.0149 | 0.0562 | 0 | 0.0271 | 0.2416 | 0.0014 | 0.0337 | 0.3173 |
2012 | 0.1348 | 0.173 | 0.0154 | 0.056 | 0 | 0.0216 | 0.2491 | 0.0014 | 0.0296 | 0.3191 |
2013 | 0.1333 | 0.162 | 0.0145 | 0.055 | 0 | 0.0172 | 0.2589 | 0.0013 | 0.0281 | 0.3296 |
2014 | 0.135 | 0.1525 | 0.0143 | 0.0524 | 0 | 0.0168 | 0.2765 | 0.0013 | 0.0269 | 0.3244 |
2015 | 0.1294 | 0.1461 | 0.0141 | 0.0473 | 0 | 0.0161 | 0.2919 | 0.0012 | 0.026 | 0.3279 |
2016 | 0.1321 | 0.141 | 0.0141 | 0.0526 | 0 | 0.0156 | 0.2952 | 0.0013 | 0.0244 | 0.3238 |
2017 | 0.1325 | 0.1408 | 0.0137 | 0.0526 | 0 | 0.0171 | 0.2961 | 0.0013 | 0.0233 | 0.3226 |
2018 | 0.1407 | 0.1427 | 0.0135 | 0.0519 | 0 | 0.014 | 0.2967 | 0.0012 | 0.0226 | 0.3165 |
2019 | 0.1417 | 0.1461 | 0.013 | 0.052 | 0 | 0.0133 | 0.2971 | 0.0012 | 0.021 | 0.3147 |
Or plotted:
Or see the Income Inequality in the Netherlands:
from financetoolkit import Toolkit
toolkit = Toolkit("MSFT")
income_inequality = toolkit.economics.get_income_inequality()
income_inequality['Netherlands']
Which returns:
Gini Coefficient | P90/P10 | P90/P50 | P50/P10 | Palma Ratio | S80/S20 | |
---|---|---|---|---|---|---|
2013 | 0.287 | 3.4 | 1.8 | 1.9 | 1.05 | 4.3 |
2014 | 0.305 | 3.4 | 1.8 | 1.9 | 1.16 | 4.6 |
2015 | 0.305 | 3.4 | 1.8 | 1.9 | 1.06 | 4.4 |
2016 | 0.292 | 3.4 | 1.8 | 1.9 | 1.07 | 4.4 |
2017 | 0.298 | 3.4 | 1.8 | 1.9 | 1.11 | 4.5 |
2018 | 0.295 | 3.3 | 1.8 | 1.9 | 1.09 | 4.4 |
2019 | 0.312 | 3.4 | 1.8 | 1.9 | 1.21 | 4.7 |
2020 | 0.295 | 3.3 | 1.8 | 1.9 | 1.09 | 4.4 |
2021 | 0.297 | 3.4 | 1.8 | 1.9 | 1.1 | 4.5 |
Or plotted:
And so much more!
Published by JerBouma 10 months ago
In addition to the many new Economics indicators in the previous release, I've also added in the European Central Banks which include:
These can be shown by using:
from financetoolkit import Economics
economics = Economics(start_date='2000-01-01')
economics.get_european_central_bank_rates()
Which returns (when plotted):
I've also added in the Federal Funds rates which include:
These can be shown by using (and defining the rate):
from financetoolkit import Economics
economics = Economics(start_date='2016-01-01')
# Effective Federal Funds Rate
economics.get_federal_reserve_rates(rate='EFFR')
# Secured Overnight Financing Rate
economics.get_federal_reserve_rates(rate='SOFR')
Which returns (when plotted):
Published by JerBouma 10 months ago
This release features an entirely new module called Economics
. This is meant to collect key economic indicators such as the Gross Domestic Product (GDP), Consumer Price Index (CPI) and Long and Short Term Interest Rates for 60+ countries. Find a complete overview here. This module can be called via the Toolkit:
from financetoolkit import Toolkit
companies = Toolkit(tickers=["AAPL", "TSLA"], api_key="FMP_KEY")
companies.economics.get_house_prices()
But also as standalone module (given that it doesn't require a company ticker):
from financetoolkit import Economics
economics = Economics()
economics.get_house_prices()
Both return the same dataset:
Australia | Austria | Belgium | Brazil | Bulgaria | Canada | Chile | China | Colombia | Croatia | Czech Republic | Denmark | EA | Estonia | Euro Area 17 | Finland | France | Germany | Greece | Hungary | Iceland | India | Indonesia | Ireland | Israel | Italy | Japan | Latvia | Lithuania | Luxembourg | Mexico | Netherlands | New Zealand | Norway | OECD - Total | Poland | Portugal | Romania | Russia | Saudi Arabia | Slovakia | Slovenia | South Africa | South Korea | Spain | Sweden | Switzerland | Turkey | United Kingdom | United States | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2013 | 84.1065 | 92.1 | 98.962 | 98.269 | 95.915 | 89.9958 | 78.0367 | 96.4912 | 85.1748 | 104.627 | 93.875 | 90.0977 | 98.267 | 82.2933 | 98.4009 | 100.353 | 103.8 | 92.5982 | 113.816 | 84.87 | 85.2075 | 76.6863 | 88.5178 | 77.0045 | 88.8228 | 109.1 | 96.148 | 97.6225 | 90.645 | 90.8947 | 88.6885 | 95.7715 | 83.5338 | 91.75 | 92.1431 | 97.4165 | 93.085 | 99.26 | 95.574 | nan | 93.5868 | 106.21 | 87.4525 | 95.7696 | 96.2393 | 80.785 | 94.867 | 75.946 | 87.3505 | 90.7087 |
2014 | 91.7202 | 95.33 | 98.417 | 99.1345 | 97.29 | 94.828 | 88.4455 | 101.132 | 91.9212 | 102.975 | 96.175 | 93.4987 | 98.482 | 93.5795 | 98.5693 | 99.995 | 101.925 | 95.499 | 105.32 | 88.4275 | 92.3855 | 88.032 | 94.73 | 89.7232 | 94.4668 | 103.95 | 97.648 | 103.475 | 96.47 | 94.8777 | 92.4655 | 96.5565 | 88.9588 | 94.25 | 95.5783 | 98.4538 | 97.0375 | 97.22 | 97.9095 | 101.189 | 94.9068 | 99.2025 | 94.146 | 97.2716 | 96.5393 | 88.4025 | 97.4497 | 86.1545 | 94.3388 | 95.1076 |
2015 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 | 100 |
2016 | 105.5 | 108.532 | 102.641 | 100.868 | 107.02 | 110.589 | 106.573 | 112.23 | 109.995 | 100.888 | 107.15 | 104.727 | 104.01 | 104.745 | 104.012 | 101.285 | 100.925 | 107.527 | 97.623 | 113.377 | 109.767 | 106.686 | 103.159 | 107.484 | 107.459 | 100.25 | 102.213 | 108.487 | 105.4 | 106.006 | 107.282 | 105.052 | 114.178 | 107.025 | 105.352 | 101.859 | 107.115 | 105.95 | 102.856 | 95.091 | 106.703 | 103.252 | 105.616 | 101.622 | 104.623 | 108.243 | 101.627 | 113.615 | 106.975 | 105.586 |
2017 | 114.308 | 114.26 | 106.373 | 101.733 | 116.295 | 123.751 | 115.275 | 126.989 | 117.332 | 104.745 | 119.7 | 109.378 | 108.513 | 110.511 | 108.454 | 102.388 | 103.975 | 114.104 | 96.6342 | 127.24 | 131.196 | 115.658 | 106.415 | 119.162 | 111.649 | 99.175 | 104.805 | 118.013 | 114.797 | 111.96 | 115.687 | 112.978 | 121.596 | 112.35 | 111.13 | 105.768 | 117.015 | 112.355 | 108.782 | 88.9675 | 112.99 | 111.785 | 110.064 | 102.854 | 111.105 | 115.427 | 103.591 | 125.392 | 111.834 | 112.078 |
2018 | 112.664 | 119.64 | 109.415 | 102.599 | 123.955 | 128.378 | 126.812 | 134.268 | 123.825 | 111.14 | 130 | 114.529 | 113.668 | 117.066 | 113.604 | 103.335 | 107.15 | 121.681 | 98.379 | 145.495 | 142.006 | 122.248 | 109.895 | 131.363 | 110.724 | 98.625 | 106.849 | 129.3 | 123.18 | 119.862 | 125.951 | 123.656 | 125.966 | 113.975 | 116.592 | 112.765 | 129.032 | 118.618 | 116.147 | 86.4625 | 121.32 | 121.547 | 114.246 | 104.275 | 118.58 | 114.35 | 106.728 | 134.891 | 115.496 | 118.951 |
2019 | 108.084 | 126.6 | 113.779 | 103.464 | 131.417 | 129.959 | 137.5 | 139.503 | 130.601 | 121.103 | 141.9 | 117.53 | 118.641 | 125.267 | 118.505 | 103.77 | 110.675 | 128.707 | 105.481 | 170.167 | 148.291 | 126.309 | 111.91 | 134.431 | 112.812 | 98.525 | 108.553 | 140.875 | 131.61 | 131.987 | 136.739 | 132.658 | 129.9 | 116.8 | 121.327 | 122.55 | 141.882 | 122.69 | 119.822 | 83.5023 | 132.395 | 129.69 | 118.273 | 103.968 | 124.715 | 117.188 | 110.572 | 141.024 | 116.592 | 124.942 |
2020 | 113.916 | 136.311 | 118.595 | 104.332 | 137.412 | 138.454 | 146.659 | 144.577 | 133.834 | 130.38 | 153.85 | 123.531 | 124.813 | 132.792 | 124.761 | 105.595 | 116.825 | 138.685 | 110.223 | 178.577 | 157.788 | 129.465 | 113.646 | 134.847 | 116.261 | 100.4 | 108.63 | 145.768 | 141.178 | 151.115 | 144.687 | 142.761 | 143.109 | 121.775 | 128.945 | 135.335 | 154.327 | 128.435 | 144.26 | 84.833 | 145.061 | 135.657 | 121.228 | 107.451 | 127.505 | 122.11 | 115.355 | 173.709 | 119.904 | 134.761 |
2021 | 133.764 | 153.262 | 127.058 | 105.198 | 149.333 | 159.222 | 164.029 | 150.101 | 141.909 | 139.912 | 184.225 | 138.01 | 134.675 | 152.778 | 134.765 | 110.448 | 124.625 | 154.739 | 118.606 | 208.037 | 177.563 | 132.749 | 115.27 | 146 | 126.076 | 102.95 | 115.102 | 161.645 | 163.84 | 172.151 | 156.073 | 164.241 | 180.981 | 134.525 | 145.113 | 147.76 | 168.84 | 134.088 | 175.268 | 85.7263 | 154.334 | 151.317 | 126.269 | 116.89 | 132.195 | 134.463 | 123.334 | 237.534 | 130.515 | 157.24 |
2022 | 142.65 | 170.765 | 134.194 | 106.063 | 169.917 | 177.235 | 175.906 | 151.385 | 152.542 | 160.685 | 215.275 | 137.36 | 144.219 | 186.76 | 144.178 | 111.745 | 132.5 | 162.941 | 132.69 | 254.345 | 214.848 | 136.925 | nan | 163.977 | 147.852 | 106.875 | 124.755 | 184.005 | 195.048 | 188.6 | 169.973 | 186.321 | 182.022 | 141.575 | 165.45 | 165.18 | 190.17 | 143.697 | 225.506 | 87.5558 | 175.471 | 173.648 | 130.758 | 119.32 | 141.978 | 139.25 | 132.603 | 601.714 | 143.214 | 179.097 |
It is also possible to plot things such as the Employment Rate as also found in the README:
Or the Long Term (10 year) and Short Term (3 month) Interest Rates:
Or any of the other metrics:
Are you looking for any specific economic parameter? Let me know and I'll start working on it.
Published by JerBouma 11 months ago
This releases introduces the GARCH model including volatility forecasting. Next to that, it includes a bugfix for the currency conversion.
Designed by @northern-64bit (LinkedIn) in #82, this release introduces GARCH (Generalized autoregressive conditional heteroskedasticity) which is stochastic model for time series, which is for instance used to model volatility clusters, stock return and inflation. It is a generalisation of the ARCH models.
It can be found inside the risk
module and can be ran with the following code:
from financetoolkit import Toolkit
toolkit = Toolkit(["AMZN", "TSLA"], api_key=FMP_KEY)
toolkit.risk.get_garch()
Which produces the following result:
Date | AMZN | TSLA | Benchmark |
---|---|---|---|
2012 | 0 | 0 | 0 |
2013 | 0.2038 | 5.027 | 0.024 |
2014 | 0.4016 | 10.2307 | 0.0537 |
2015 | 0.53 | 13.2345 | 0.0688 |
2016 | 0.7664 | 15.6152 | 0.079 |
2017 | 0.8181 | 17.5204 | 0.0887 |
2018 | 0.8896 | 19.0642 | 0.0997 |
2019 | 0.9235 | 20.2789 | 0.104 |
2020 | 0.9479 | 21.2567 | 0.1169 |
2021 | 1.0203 | 27.5585 | 0.1209 |
2022 | 1.0201 | 27.0986 | 0.129 |
2023 | 1.0445 | 26.7482 | 0.1305 |
You can also forecast in the future for any period and for any interval. For example, the quarterly expected volatility estimations can be shown with:
from financetoolkit import Toolkit
toolkit = Toolkit(["AMZN", "TSLA"], api_key=FMP_KEY)
toolkit.risk.get_garch_forecast(period='quarterly')
Which returns:
AMZN | TSLA | Benchmark | |
---|---|---|---|
2024Q1 | 0 | 0 | 0 |
2024Q2 | 0 | 0 | 0 |
2024Q3 | 0.006 | 0.3185 | 0.0003 |
2024Q4 | 0.0114 | 0.6051 | 0.0006 |
2025Q1 | 0.0162 | 0.8631 | 0.0008 |
2025Q2 | 0.0206 | 1.0953 | 0.001 |
2025Q3 | 0.0245 | 1.3042 | 0.0012 |
2025Q4 | 0.0281 | 1.4923 | 0.0014 |
2026Q1 | 0.0312 | 1.6615 | 0.0015 |
2026Q2 | 0.0341 | 1.8138 | 0.0017 |
Next to that, a bug fix went in related to the currency conversions which makes it more robust when there is data missing. If you didn't know, when you have a Premium FMP plan the Finance Toolkit will now automatically convert currencies that do not match up with the historical data. For more see here: https://github.com/JerBouma/FinanceToolkit/releases/tag/v1.6.3
Published by JerBouma 11 months ago
This release features currency conversions. A user noticed that the financial statements are not always in the expected currency (different from the historical data):
This could lead to confusion when comparing numbers between companies and or when calculating ratios that require both data from the financial statement and the historical market data. This has now been resolved with an automatic converter that converts the financial statements accordingly. With this, the end of quarter or end of year exchange rate is used.
This is also saved in a seperate function called get_exchange_rates
as shown below:
This is quite a major change given that there are plenty of financial statements that report their financial statements in their local currency while the listed historical prices are in USD. This ensures that those numbers can be compared. This can be disabled by setting convert_currency
to False
in the Toolkit
initialisation. Note that by default it is automatically turned off when using the Free plan of FinancialModelingPrep as it could drain the API calls for that specific day.
I've also added in a parameter that recognises if you are using a Free or Premium plan from FinancialModelingPrep. This is a dependency for the sleep_timer
which will wait a maximum of 60 seconds before making a new request to FMP. This is only relevant for the Premium plans since there is a rate limit per minute. For the Free plan it doesn't matter given that you are limited to 250 requests per day. In any case, this should make the Free experience smoother since you are not waiting for no reason. This solves #80.
Note: this consumes 1 API call so if you don't want that, just set sleep_timer to True or False.
if sleep_timer is None:
# This tests the API key to determine the subscription plan. This is relevant for the sleep timer
# but also for other components of the Toolkit. This prevents wait timers from occurring while
# it wouldn't result to any other answer than a rate limit error.
determine_plan = helpers.get_financial_data(
url=f"https://financialmodelingprep.com/api/v3/income-statement/AAPL?period=quarter&apikey={api_key}",
sleep_timer=False,
)
self._fmp_plan = "Premium"
for option in ["NOT AVAILABLE", "LIMIT REACH", "INVALID API KEY"]:
if option in determine_plan:
self._fmp_plan = "Free"
break
else:
self._fmp_plan = "Premium"
Published by JerBouma 12 months ago
I did a new release last week but for everything I've added in it made sense to do another full release. This release includes new models and ESG scores and a lot of the code has been refactored, many new tests have been added and a lot of bug fixes went in. For example, @brianrasmusson noticed in #76 that Apple's data was a bit out of whack. This has now been resolved. I've also added in a lot pretty graphs into the README to show what you can really do with the data, e.g. see this one on the Value of Risk:
It is now possible to view ESG Scores for any range of companies with get_esg_scores
:
Next to that, within the Models
module, two new models are included. These are Altman Z-Score and Piotroski F-score. The former calculates the chance of bankruptcy based on a set of criteria:
The latter scores the financial strength of the company:
Furthermore, I've added a performance measurement which shows the period growth rate that has occurred (taking out fluctuations over time as shown in the plot below):
Other than that, I've extended the examples and gave more explanation how to add in your own datasets.
Published by JerBouma 12 months ago
Introducing the power of Threading into the FinanceToolkit. Update now via pip install financetoolkit -U
.
As an example, obtaining the balance sheet statements of 345 different companies for the period 1983 to 2023 takes less than 40 seconds. This makes data collection extremely quick and makes the FinanceToolkit an invaluable tool for any financial specialist.
Next to that, given that there are rate limits, these are correctly dealt with through sleep timers. If you have a subscription from FinancialModelingPrep that limits you to 300 requests per minute, the FinanceToolkit will deal with this and will wait until it can make requests again.
Furthermore, if some of the historical data is not available from FinancialModelingPrep it will try YahooFinance instead making sure that you don't lose vital data for your calculations.
Of course, all of this extends in all functionality. E.g. see Jensen's Alpha for all 345 tickers on a quarterly basis. Given that the calculations are done by the FinanceToolkit, this takes just a few seconds.
Published by JerBouma 12 months ago
I've added in the Dividend Calendar which can be shown by get_dividend_calendar()
:
from financetoolkit import Toolkit
API_KEY = "FINANCIAL_MODELING_PREP_KEY"
# Initialize the Toolkit with company tickers
companies = Toolkit(
["AAPL", "MSFT", "GOOGL", "AMZN"], api_key=API_KEY, start_date="2005-01-01"
)
companies.get_dividend_calendar()
Which returns:
Next to that, this release introduces historical data from FinancialModelingPrep. This is enabled by default when you provide an API key but can be changed back by setting historical_source
to "YahooFinance"
when initialising the Toolkit. When you don't provide an API key it defaults to Yahoo Finance.
This is done to prevent rate limits from becoming an issue when you have purchased a FinancialModelingPrep subscription given that Yahoo Finance will rate limit at some point. It of course makes little sense that you are paying and still get rate limited!
E.g. the following will net you the same result:
from financetoolkit import Toolkit
API_KEY = "FINANCIAL_MODELING_PREP_KEY"
# Use FinancialModelingPrep to obtain Historical Data
companies = Toolkit(
["AAPL", "MSFT", "GOOGL", "AMZN"], api_key=API_KEY, start_date="2005-01-01"
)
companies.get_historical_data()
# Use Yahoo Finance to obtain Historical Data even though you set a FinancialModelingPrep API Key
companies = Toolkit(
["AAPL", "MSFT", "GOOGL", "AMZN"], api_key=API_KEY, start_date="2005-01-01", historical_source='YahooFinance'
)
companies.get_historical_data()
# Use Yahoo Finance to obtain Historical Data without needing to set an API Key
companies = Toolkit(
["AAPL", "MSFT", "GOOGL", "AMZN"], start_date="2005-01-01"
)
companies.get_historical_data()
Which returns:
Published by JerBouma about 1 year ago
This releases includes the Fama and French 5-factor model. Something I've been wanting to add into the Finance Toolkit for some time now. This allows you to understand the explanatory power of the following factors on each ticker included in the Toolkit on any period, let it be yearly, quarterly, monthly or weekly:
I've added correlation functions that help you understand how factors correlate with each other over time. For example, the following GIF is created with data from the function performance.get_factor_correlations
.
Next to that, you can perform Linear Regressions on each factor and each factor combination to discover sensitivities of individual assets to each factor (this is not only limited to companies but can also be currencies, commodities, ETFs and more):
from financetoolkit import Toolkit
# Initialize the Finance Toolkit
companies = Toolkit(
tickers=["MSFT", 'AAPL', 'TSLA', 'GOOG', "AMZN", 'MU'], api_key=FMP_KEY, quarterly=False
)
companies.performance.get_fama_and_french_model()
Which returns regression coefficients for all factors for each individual stock:
You have the option to show both the results from a simple linear regression (which is defined as Excess Return = Intercept + Slope * Factor Value + Residuals
) or a multi linear regression (which is defined as Excess Return = Intercept + Beta1 * Mkt-RF + Beta2 * SMB + Beta3 * HML + Beta4 * RMW + Beta5 * CMA + Residuals
) the latter is the default. E.g. you can show the explanatory power of each individual factor for example for Microsoft as follows:
from financetoolkit import Toolkit
# Initialize the Finance Toolkit
companies = Toolkit(
tickers=["MSFT"], api_key=FREE_FMP_KEY, quarterly=False
)
result = companies.performance.get_fama_and_french_model(period='quarterly', method='simple')
result['MSFT'].xs('R Squared', level=1, axis=1).plot(figsize=(15, 5), title=f'Factor Sensitivities of Microsoft')
Which returns the following:
Published by JerBouma about 1 year ago
This releases features a couple of Quality of Life improvements and some bug fixes:
If you didn't know, any type of asset class works with the Finance Toolkit (e.g. Equities, Currencies, Cryptocurrencies, ETFs, Mutual Funds, Indices, Money Markets, Commodities and more) which also allows you to obtain detailed calculations such as the Conditional Value at Risk (cVaR).
Published by JerBouma about 1 year ago
This release mainly introduces fixes to existing functionality, most importantly the calculation of trailing ratios. The timing of the trailing ratios was a bit off as it took to the sum of the periods after calculation instead of before. This has now been fixed.
If you didn't know, you can calculate trailing ratios (e.g. revenue TTM, price-to-earnings TTM) and much more by using the trailing
parameter. This parameter represents the amount of periods you wish to combine to calculate the trailing ratio, e.g. if you use quarterly=True
in the Toolkit initialisation and then set trailing=4
for any ratio, you are able to calculate any TTM ratio.
The same can be done for a financial statement.
I also noticed that the days used for calculating Efficiency Ratios was set to 365 by default. This is fine for annual calculations but for quarterly calculations it should be divided by 4. This is now done automatically.
Published by JerBouma about 1 year ago
A user of the Finance Toolkit reported some issues with the dividends. Noticed it was unfortunately broken. This has now been fixed. Other than that, I've updated a couple of docstrings.
Published by JerBouma about 1 year ago
This release adds a minor, but important, function (get_historical_statistics
) that shows in what currency the historical data is denoted. Besides that, it also gives some insights since when the product was traded and in what timezone it belongs.