FinanceToolkit

Transparent and Efficient Financial Analysis

MIT License

Downloads
6K
Stars
2.4K
Committers
7

Bot releases are visible (Hide)

FinanceToolkit - FinanceToolkit v1.3.6

Published by JerBouma about 1 year ago

This version introduces ISIN support. If you submit an ISIN, it will find the relevant symbol and use that instead. It will also mention to what symbol it made the conversion so it is clear what ticker to look at. I've also added some dependencies, mostly a clean-up (I was struggling with getting SciPy to work, now this is built in with Pandas). Next to that, I've added the Finance Database as a dependency as in the future the Finance Toolkit will feature functionality from this database.

FinanceToolkit - FinanceToolkit v1.3.5

Published by JerBouma about 1 year ago

This is a minor release getting some bugfixes in and making the code a bit more robust. Less errors should now occur when you do not have the correct API key set and someone noticed that if you call the Statistics functionality before anything else it returns an error. This is now fixed.

If you feel like any functionality is missing, definitely let me know and we can start adding them in!

FinanceToolkit - FinanceToolkit v1.3.4

Published by JerBouma about 1 year ago

This releases introduces two new models which are the Weighted Average Cost of Capital (WACC) and the Intrinsic Valuation.

As an example, see the WACC below. For the method of calculation please see here.

Furthermore, the Intrinsic Valuation attempts to calculate the intrinsic value of an asset. This does require some manual input through which are growth, perpetual growth and WACC numbers given that this model is highly subjective and asset dependent.

The growth numbers can be specified for each asset individually as well. For the method of calculation please see here.

Next to that, I've introduced trailing calculations for the Financial Statements and Ratios. As an example, you can now see the Trailing P/E ratio with the following code. Note that you need to have quarterly=True to get the actual TTM (otherwise you will take the trailing value over 4 years).

FinanceToolkit - FinanceToolkit v1.3.3

Published by JerBouma about 1 year ago

This new release features a whole lot of new features yet again. This includes the following:

Performance Metrics

There is now a large list of performance metrics to be found in the performance class in similar fashion as e.g. ratios. This gets you the following:

  • Alpha
  • Jensen's Alpha
  • Beta
  • Capital Asset Pricing Model (CAPM)
  • Treynor Ratio
  • Sharpe Ratio
  • Sortino Ratio
  • Ulcer Performance Index (UPI)
  • M2 Ratio
  • Tracking Error
  • Information Error

This is an extra powerful class as you can get these ratios "within" periods. This means that if you select the period "quarterly", it will calculate the ratios for the days within each quarter. As an example:

Risk Metrics

Not only Performance Metrics are added in but courtesy of @northern-64bit, it is now also possible to observe the following risk metrics:

  • Value at Risk (VaR) with distributions Historical, Gaussian, Student-t, Cornish-Fisher.
  • Conditional Value at Risk (cVaR) with distributions Historical, Gaussian, Laplace, Logistic.
  • Entropic Value at Risk (eVaR) with a Gaussian distribution.
  • Ulcer Index (UI)
  • Maximum Drawdown (MDD)
  • Skewness
  • Kurtosis

Just like with the performance metrics, you can view these for within each period as well. E.g. on a weekly basis:

Risk Free Rates and Benchmarks

Within the Toolkit class (upon initialisation) a benchmark can be defined. By default this is set to "^GSPC" which is the S&P 500 index. This benchmark is required to calculate metrics such as CAPM, Beta and (Jensens Alpha) and is very neat to have when you wish to analyze and compare tickers. It is of course possible to change this benchmark ticker to anything (or disable it by setting it to None).

Next to that, it is also possible to define a risk free rate, this can be '13w', '5y', '10y' or '30y' and defaults to '10y'. Both settings will lead to different results for some of the calculations and it is therefore important you set a benchmark and risk free rate that matches your beliefs and analysis. As an example:

Other than that, many improvements behind the scenes were made. E.g. it is now really easy to add new ratios since all the data has been prepared properly and some fixes have been made to data that could sometimes mess up in niche scenarios. Next to that, the documentation has been greatly extended: https://www.jeroenbouma.com/projects/financetoolkit/docs.


Find a variety of How-To Guides including Code Documentation for the FinanceToolkit here.


FinanceToolkit - FinanceToolkit v1.3.2

Published by JerBouma about 1 year ago

This release focusses on numerous smaller enhancements that make the quality of the data better. For example, through grouping of historical data, I've noticed that it resulted in numerous NaN values given that for that particular stock there is no data available. These were minor details but it slightly messed up any form of charting. Next to that, technical indicators falsely calculated with NaN values.

Next to that, I noticed that if you input a ticker that had no data outside of the defined period (with start and end) it gave an error. This has now been tackled. Much more is upcoming with a new Risk class (for Value at Risk, Conditional Value at Risk and much more) currently in the works!

All in all, you can now generate charts like these with relative ease through collecting data from the FinanceDatabase and FinanceToolkit incredibly quickly being able to do really proper investment research.

As an example, these are companies found through the Finance Database:

Which, once data is collected through the Finance Toolkit, can return:

image

Also did you notice that really any asset works and not only companies? :)

image

FinanceToolkit - FinanceToolkit v1.3.1

Published by JerBouma about 1 year ago

This is a massive release to the FinanceToolkit adding a lot more functionality including 30+ technical indicators. These are the key improvements:

Added a technicals class, this has the option to calculate over 30 technical indicators (e.g. Relative Strength Index and Bollinger Bands) with the chosen dataset. Just like other components of the FinanceToolkit, this works very well with any list of tickers. As an example, the following collects all technical indicators:

from financetoolkit import Toolkit

toolkit = Toolkit(tickers=["AAPL", "MSFT", "AMZN"])

toolkit.technicals.collect_all_indicators()

This returns the following:

Just like with ratios, it is also possible to show single indicators:

from financetoolkit import Toolkit

toolkit = Toolkit(tickers=["AAPL", "MSFT", "AMZN"])

toolkit.technicals.get_bollinger_bands()

This is a major addition as it is now possible to do quantitative research both based on fundamental data and technical indicators further accelerating the package to also become a great place for Machine Learning professionals.

I've expanded the historical dataset with new vital columns. It not only returns Open, High, Low, Close and Returns but also shows Dividends, Volatility, Excess Returns (minus Risk Free Rate), Excess Volatility and Cumulative Returns.

from financetoolkit import Toolkit

toolkit = Toolkit(tickers=["AAPL", "MSFT", "AMZN"])

toolkit.get_historical_data()

I've reworked a lot of docstrings. This makes it possible to better understand what a function is providing and what the meaning is of the result. This is also further highlighted on the documentation page here. As an example:

"""
Calculate the debt to equity ratio, a solvency ratio that measures the
proportion of a company's equity that is financed by debt.

The debt to equity ratio, also known as the D/E ratio, indicates the relative
contribution of debt and equity to a company's capital structure. It helps assess
the level of financial risk a company carries due to its debt obligations. A higher
ratio implies a higher reliance on debt to finance the business, which could increase
risk but also potentially lead to higher returns for shareholders.

Args:
    rounding (int, optional): The number of decimals to round the results to. Defaults to 4.
    growth (bool, optional): Whether to calculate the growth of the ratios. Defaults to False.
    lag (int | str, optional): The lag to use for the growth calculation. Defaults to 1.

Returns:
    pd.DataFrame: Debt to equity ratio values.

Notes:
- The method retrieves historical data and calculates the ratio for each asset in the Toolkit instance.
- If `growth` is set to True, the method calculates the growth of the ratio values using the specified `lag`.

As an example:

from financetoolkit import Toolkit

toolkit = Toolkit(["AAPL", "TSLA"], api_key=FMP_KEY)

debt_to_equity_ratios = toolkit.ratios.get_debt_to_equity_ratio()
"""

I've added in a risk free rate. This is based on ^TNX which is the 10-year Treasury Rate. This is relevant for calculations that require a Risk Free Rate such as the Sharpe Ratio. This is hidden in the back-end but can be retrieved (after using get_historical_data) with companies._daily_risk_free_rate. As an example:

from financetoolkit import Toolkit

toolkit = Toolkit(tickers=["AAPL", "MSFT", "AMZN"])

toolkit.get_historical_data()

toolkit._daily_risk_free_rate

Which returns:

FinanceToolkit - FinanceToolkit v1.2.6

Published by JerBouma about 1 year ago

Major release with numerous new functionality and a lot of misc fixes. The major components are:

Calculating custom ratios are greatly improved with a lot of robustness.* This now features the following things:

  • Simple operations such as: 'Quick Assets': 'Cash and Short Term Investments + Accounts Receivable'
  • Working with multiple operations: 'Cash Op Expenses':'Cost of Goods Sold + Selling, General and Administrative Expenses - Depreciation and Amortization',
  • Using curly brackets: 'WC / Net Income as %': '(Working Capital / Net Income) * 100',
  • Defining a criteria: 'Large Revenues': 'Revenue > 1000000000',
  • Using actual numbers: 'Daily Cash Op Expenses': 'Cash Op Expenses / 365',
  • Combining earlier defined formulas: 'Defensive Interval':'Quick Assets / Daily Cash Op Expenses'

As an example (also see the README and Notebooks):

The historical dataset now calculates OLHC, volumes, returns, cumulative returns and volatility. This also works for different periods (e.g. yearly) to see how volatility moved over the years for example. Next to that, within the backend a bit more data is collected than displayed to overcome issues with incomplete quarters or years.

It is possible to view treasury rates over the last 3 months for multiple maturities. This makes it possible to create yield curves for multiple months and can serve as a basis for discounting.

Improved the External Datasets usage. Previously, this was a little bit buggy and could result in a lot of errors when things didn't match up right. This has now been corrected and the example is also better explained. Please see the updated Jupyter Notebook here.

FinanceToolkit - FinanceToolkit v1.2.5

Published by JerBouma about 1 year ago

I've been busy again to improve numerous docstrings, optimize code and ensure that there is better error handling. I've introduced some other features that have been requested which are the following:

An earnings calendar in which all exact earnings dates in the past and in the future are displayed including estimates. It has the option to show the quarterly statement dates or the annual dates and can be shown for any amount of companies.

The option to segregate revenue by product. This makes it possible to understand where the revenue is coming from. Note that this is a Professional and Enterprise Subscription feature. As an example, Apple.

The option to segregate revenue by geography. This makes it possible to understand from what countries, a company makes its revenue. Note that this is a Professional and Enterprise Subscription feature. As an example, Google.

As you can see, both options can be either quarterly or annually.

FinanceToolkit - FinanceToolkit v1.2.4

Published by JerBouma about 1 year ago

Many many new additions!

  • Introduced a TQDM progress bar for financial statements. This only activates if you have TQDM installed and can also be disabled by setting progress_bar=False in the Toolkit initalization. The purpose of this is to make it more clear how far the data collection is progressing. This fixes #53.
  • Added a sleeper in case you breach the request limit. This is mostly relevant for Premium subscriptions that reach the 300 (or 750) API Calls per minute. On average, this should be almost never an issue. This fixes #52.
  • I've done some number formatting. Ratios or percentages are depicted with 4 decimals and all other values with 2. This made more sense and keeps the data concise.
  • Many QOL updates and Docstring fixes.

I've extended the historical dataset with dividends, returns and cumulative returns. As an example:

I've added in the ability to collect Analyst Estimates. This gives insights in how a range of analysts thought about the past and think about the future of each company.

The Enterprise functionality is now located in models and is calculated with the available data. This makes it more in line with the rest of the Toolkit. This also shows the new progress bars.

FinanceToolkit - FinanceToolkit v1.2.2

Published by JerBouma about 1 year ago

This release introduces growth metrics. This allows any financial statement, ratio or model to also be viewed as growth metrics. Next to that, with the lag parameter multiple periods can be defined. This is now also updated in the Example files. Lastly, the historical data output now also calculates returns.

For example:

from financetoolkit import Toolkit

API_KEY = "FMP_KEY"

companies = Toolkit(
    ["AAPL", "MSFT", "GOOGL", "AMZN"], api_key=API_KEY, start_date="2000-01-01"
)

companies.get_income_statement(growth=True)

Which returns:

And an example for ratios with multiple lags:

from financetoolkit import Toolkit

API_KEY = "FMP_KEY"

companies = Toolkit(
    ["AAPL", "MSFT", "GOOGL", "AMZN"], api_key=API_KEY, start_date="2000-01-01"
)

companies.ratios.collect_all_ratios(growth=True, lag=[1, 2, 3])

Which returns:

FinanceToolkit - FinanceToolkit v1.2.1

Published by JerBouma about 1 year ago

I've updated much of the docstrings to now include examples. These examples and the code documentation in general is now depicted on: https://www.jeroenbouma.com/projects/financetoolkit

Furthermore, I've introduced dividends within the Historical data. This allow you to see annual and quarterly dividend values for each.

It’s good to note the following: the most recent annual and quarterly numbers might differ from what other websites report because this is based on the dividend that actually has been paid and not what is announced.

These are the annual values:
image

And these are the quarterly values:
image

FinanceToolkit - FinanceToolkit v1.2.0

Published by JerBouma about 1 year ago

This new release has numerous of improvements:

  • Worked on fixing the date formatting, you will now see the correct dates for Quarters (2020Q2, 2020Q3 etc). This fixed an issue where the reporting dates of companies varied. For some the end of June could be Q3 while for others Q1. Now both will be Q2 so comparison makes more sense. See #45
  • Introduced a Statistics statement that includes CIK Codes, reporting dates and financial statement links.
  • It is now possible to calculate custom ratios based on the normalized financial statements. This makes it much easier to calculate ratios that are currently not included. See #47 by @sword134
  • Overall improvements of the code, a big step forward in optimization and error handling. It won't happen that the functions crash but instead will show an error message and continue.
  • Fix issues with values being 0 (divide by zero).

See below output of both the new date naming for quarters as well as the newly defined ratios.

2022Q3 2022Q4 2023Q1 2023Q2
Current Assets Inventory 1.62953e+11 1.62125e+11 1.5967e+11 1.66557e+11
Net Income / Total Assets 0.0388271 0.037299 0.0407344 0.0479527
Quick Ratio Current 2.46977 2.33947 2.31896 2.14334
Quick Ratio Total 1.55744 1.48575 1.4703 1.43704
WC / Net Income 7.19842 7.00932 6.1877 4.95857
FinanceToolkit - FinanceToolkit v1.1.2

Published by JerBouma about 1 year ago

Added in functionality to set a start and end date. For example:

from financetoolkit import Toolkit

companies = Toolkit(['AAPL', 'MSFT'], api_key="FMP_KEY", start_date='2017-12-31')

# an Enterprise example
enterprise = companies.get_enterprise()

# a Historical example
historical_data = companies.get_historical_data()

# a Financial Statement example
balance_sheet_statement = companies.get_balance_sheet_statement()

# a Ratios example
profitability_ratios = companies.ratios.collect_profitability_ratios()

# Show the profitability ratios for Apple
profitability_ratios.loc['AAPL']

This returns the following output for profitability_ratios.loc['AAPL]. Omitting .loc['AAPL'] will return the result for both AAPL and MSFT.

2018 2019 2020 2021 2022
Gross Margin 0.383437 0.378178 0.382332 0.417794 0.433096
Operating Margin 0.26694 0.24572 0.241473 0.297824 0.302887
Net Profit Margin 0.224142 0.212381 0.209136 0.258818 0.253096
Interest Burden Ratio 1.02828 1.02827 1.01211 1.00237 0.997204
Income Before Tax Profit Margin 0.274489 0.252666 0.244398 0.298529 0.30204
Effective Tax Rate 0.183422 0.159438 0.144282 0.133023 0.162045
Return on Assets (ROA) 0.162775 0.16323 0.177256 0.269742 0.282924
Return on Equity (ROE) 0.555601 0.610645 0.878664 1.50071 1.96959
Return on Invested Capital (ROIC) 0.269858 0.293721 0.344126 0.503852 0.562645
Return on Capital Employed (ROCE) 0.305968 0.297739 0.320207 0.495972 0.613937
Return on Tangible Assets 0.555601 0.610645 0.878664 1.50071 1.96959
Income Quality Ratio 1.30073 1.25581 1.4052 1.09884 1.22392
Net Income per EBT 0.816578 0.840562 0.855718 0.866977 0.837955
Free Cash Flow to Operating Cash Flow Ratio 0.828073 0.848756 0.909401 0.893452 0.912338
EBT to EBIT Ratio 0.957448 0.948408 0.958936 0.976353 0.975982
EBIT to Revenue 0.286688 0.26641 0.254864 0.305759 0.309473
FinanceToolkit - FinanceToolkit v1.1.0

Published by JerBouma about 1 year ago

This release features numerous enhancements and fixes:

  • Overall robustness fixes to ensure errors are easier to understand. This fixes #38.
  • Ensure that if a ticker has no data, that this is accurately displayed and taken out of the calculation. By default tickers are removed but there is a possibility to stop this behaviour. This fixes #42.
  • Zero Division Errors due to missing data, this was often an issue when data was available for one financial statement but not for the others resulting in zeros. This fixes #39.
  • Add the option to more easily combine DataFrames into the desired format for the Toolkit. Now, with from financetoolkit.base import helpers and then helpers.combine_dataframes it is possible to feed a dictionary with tickers as keys and dataframes as values to create the desired format. This fixes #41.

Full Changelog: https://github.com/JerBouma/FinanceToolkit/commits/v1.1.0

Package Rankings
Top 6.61% on Proxy.golang.org
Top 3.24% on Pypi.org
Badges
Extracted from project README
FinanceToolkit GitHub Sponsors Buy Me a Coffee Twitter LinkedIn Documentation Supported Python Versions PYPI Version PYPI Downloads Star History Chart
Related Projects