Releases: JerBouma/FinanceToolkit
FinanceToolkit v1.9.8
This release features a fix to issues with Yahoo Finance which is used as a fallback whenever FinancialModelingPrep doesn't have the data or because your plan limits you from accessing this data. E.g. if you have the Free plan you can only get historical data on U.S. listed stocks so all other historical data comes from Yahoo Finance. I used to directly query from Yahoo Finance myself but given that it can break over time, it makes more sense to add in an optional dependency (yfinance
). This means that by default this dependency is not installed given that the Finance Toolkit doesn't have to rely on this package if you have the proper FMP plan.
This is what I am referring to (see "The following tickers acquired historical data..")
In case you've used pip install financetoolkit -U
in a new environment you will receive the following message when you have a Free plan and try to download data on stocks not on U.S. exchanges:
As can be read, this can be resolved by using pip install 'financetoolkit[yfinance]'
as shown below:
FinanceToolkit v1.9.6
The last couple of releases were all minor bugfixes therefore it didn't merit a proper release. However, for this one quite a fix things under the hood have changed entirely inside the Economy
menu. Given that OECD recently updated their databases, all of the original links broke and therefore needed fixing. This unfortunately also resulted in some functionality being scrapped given that the datapoints were archived altogether.
Furthermore, I am aware of issues with Yahoo Finance's data download. You won't notice any to this when using an API Key from FMP but if you don't, I had built a fallback method that went to Yahoo Finance. Given that Yahoo Finance doesn't officially support the collection of data for now this functionality within the Finance Toolkit won't function (it will return 0s). I have still to consider whether to remove the functionality altogether or come up with a fix (however given that it is unofficial, things can break at any time again). Given that the package yfinance
exists, I might introduce it as an add-on if you still wish to have this functionality.
Please let me know if you do.
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... |
FinanceToolkit v1.8.5
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 #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.
FinanceToolkit v1.8.3
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.
FinanceToolkit v1.8.1
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!
FinanceToolkit v1.8.0
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.23... |
FinanceToolkit v1.7.4
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.
FinanceToolkit v1.7.3
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.
FinanceToolkit v1.7.2
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!