Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run ratios on local fiancial statements #169

Open
latifs opened this issue Jan 24, 2025 · 3 comments
Open

Can't run ratios on local fiancial statements #169

latifs opened this issue Jan 24, 2025 · 3 comments

Comments

@latifs
Copy link

latifs commented Jan 24, 2025

Hi guys,

My assumption with this package was that I'd be able to run analysis on financial statements that I'd provide myself, but can't seem to be able to do that.
Here, is my code below, I used the CSV statements files available in the examples folder on this package (The google ones). I just renamed the Ticker to CUST.

When not putting any API_KEY it won't do anything and when putting the API_KEY it tries to fetch data for the CUST ticker which obviously doesn't exist.

import pandas as pd
from financetoolkit import Toolkit, helpers

# Balance Sheet Statements
cust_balance = pd.read_csv("external_datasets/CUST_balance.csv", index_col=0)

# Income Statements
cust_income = pd.read_csv("external_datasets/CUST_income.csv", index_col=0)

# Cash Flow Statements
cust_cash = pd.read_csv("external_datasets/CUST_cash.csv", index_col=0)

normalization_files = Toolkit("CUST").get_normalization_files()


balance_sheets = helpers.combine_dataframes({"CUST": cust_balance})
income_statements = helpers.combine_dataframes({"CUST": cust_income})
cash_flow_statements = helpers.combine_dataframes({"CUST": cust_cash})

income_statements = income_statements.drop(columns=["ttm"])
cash_flow_statements = cash_flow_statements.drop(columns=["ttm"])


# initialize the Toolkit
companies = Toolkit(
    tickers=["CUST"],
    balance=balance_sheets,
    income=income_statements,
    cash=cash_flow_statements,
    format_location="external_datasets",
    reverse_dates=True,
    api_key="xxxx",
)

profitability_ratios = companies.ratios.collect_profitability_ratios() # this obviously does not work

this is the full error returned:

No data found for the following tickers: CUST
No data found for the following tickers: CUST
Due to a missing optional dependency (yfinance) and your current FinancialModelingPrep plan, data for the following tickers could not be acquired: CUST
Enable this functionality by using: pip install 'financetoolkit[yfinance]' 
There is an index name missing in the provided financial statements. This is 'Revenue'. This is required for the function (get_gross_margin) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Operating Income'. This is required for the function (get_operating_margin) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Net Income'. This is required for the function (get_net_profit_margin) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Operating Income'. This is required for the function (get_interest_coverage_ratio) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Income Before Tax'. This is required for the function (get_income_before_tax_profit_margin) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Income Tax Expense'. This is required for the function (get_effective_tax_rate) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Net Income'. This is required for the function (get_return_on_assets) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Net Income'. This is required for the function (get_return_on_equity) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Net Income'. This is required for the function (get_return_on_invested_capital) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Net Income'. This is required for the function (get_return_on_capital_employed) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Net Income'. This is required for the function (get_return_on_tangible_assets) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Cash Flow from Operations'. This is required for the function (get_income_quality_ratio) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Net Income'. This is required for the function (get_net_income_per_ebt) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Free Cash Flow'. This is required for the function (get_free_cash_flow_operating_cash_flow_ratio) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Net Income'. This is required for the function (get_EBT_to_EBIT) to run. Please fill this column to be able to calculate the ratios.
There is an index name missing in the provided financial statements. This is 'Net Income'. This is required for the function (get_EBIT_to_revenue) to run. Please fill this column to be able to calculate the ratios.
Traceback (most recent call last):
  File "/opt/anaconda3/envs/finance-tool/lib/python3.12/site-packages/pandas/core/generic.py", line 576, in _get_axis_number
    return cls._AXIS_TO_AXIS_NUMBER[axis]
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
KeyError: 'columns'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/Documents/finance-tool/original.py", line 52, in <module>
    profitability_ratios = companies.ratios.collect_profitability_ratios()
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/finance-tool/lib/python3.12/site-packages/financetoolkit/ratios/ratios_controller.py", line 2409, in collect_profitability_ratios
    .dropna(axis="columns", how="all")
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/finance-tool/lib/python3.12/site-packages/pandas/core/series.py", line 5897, in dropna
    self._get_axis_number(axis or 0)
  File "/opt/anaconda3/envs/finance-tool/lib/python3.12/site-packages/pandas/core/generic.py", line 578, in _get_axis_number
    raise ValueError(f"No axis named {axis} for object type {cls.__name__}")
ValueError: No axis named columns for object type Series
@JerBouma
Copy link
Owner

Please note that the package assumes:

  • That the ticker you provide is an actual ticker.
  • You provide everything. You haven't provided historical data so it is trying to obtain that data.

There are also checks whether the historical data lines up with the financial statement data which it is unable to do if you did not provide an existing ticker (can be disabled with convert_currency=False).

The ratios module also assumes historical exists as it is needed for several ratios.

@latifs
Copy link
Author

latifs commented Jan 24, 2025

Hey @JerBouma,

ok then that is my fault for assuming that this package would do what I need it to do.

I assumed that by providing the financial statements(locally) in the right format,
that I could use this tool to calculate the ratios on the statements provided.

I don't see why I'd need to provide financial statements if I can get all that info with just providing a ticker, that's where I got confused I guess.

I'm also not sure what you mean by historical data? on FMP there's a lot of historical data

I don't know If this could be added but being able to calculate as many ratios as possible with just the income statement, balance sheet and cash flow statement would be really valuable.

Thanks

@JerBouma
Copy link
Owner

With historical data, I am referring to OHLC data. Also, I believe the main issue here is that you didn't fill the normalisation templates correctly. This is also why you are receiving the errors that certain columns can't be found.

Please recheck: https://www.jeroenbouma.com/projects/financetoolkit/external-datasets

I've had many people who successfully managed to make this work and I am sure it's just a minor detail right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants