From 8babe30e6604940c83849e9c13354fc51edbbd63 Mon Sep 17 00:00:00 2001 From: jeroen Date: Tue, 2 Apr 2024 17:19:42 +0200 Subject: [PATCH] Bugfix for #128 --- financetoolkit/historical_model.py | 3 +++ financetoolkit/toolkit_controller.py | 28 ++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/financetoolkit/historical_model.py b/financetoolkit/historical_model.py index 802783f..1d14791 100644 --- a/financetoolkit/historical_model.py +++ b/financetoolkit/historical_model.py @@ -234,6 +234,9 @@ def worker(ticker, historical_data_dict): reorder_tickers = [ticker for ticker in tickers if ticker in historical_data_dict] + if not historical_data_dict: + raise ValueError("No data found for the given tickers.") + historical_data = pd.concat(historical_data_dict).unstack(level=0) historical_data = historical_data.reindex(reorder_tickers, level=1, axis=1) diff --git a/financetoolkit/toolkit_controller.py b/financetoolkit/toolkit_controller.py index d941bbe..4685f90 100644 --- a/financetoolkit/toolkit_controller.py +++ b/financetoolkit/toolkit_controller.py @@ -2556,12 +2556,16 @@ def get_exchange_rates( else self._progress_bar ) - self._statement_currencies, self._currencies = helpers.determine_currencies( - statement_currencies=self._statistics_statement.xs( - "Reported Currency", axis=0, level=1 - ), - historical_currencies=self._historical_statistics.loc["Currency"], - ) + if not self._statistics_statement.empty: + ( + self._statement_currencies, + self._currencies, + ) = helpers.determine_currencies( + statement_currencies=self._statistics_statement.xs( + "Reported Currency", axis=0, level=1 + ), + historical_currencies=self._historical_statistics.loc["Currency"], + ) if self._daily_exchange_rate_data.empty or overwrite: self._daily_exchange_rate_data, _ = _get_historical_data( @@ -2992,9 +2996,9 @@ def get_income_statement( income_statement = helpers.convert_currencies( financial_statement_data=income_statement, financial_statement_currencies=self._statement_currencies, - exchange_rate_data=self.get_exchange_rates( - period="quarterly" if self._quarterly else "yearly" - )["Adj Close"], + exchange_rate_data=self._quarterly_exchange_rate_data["Adj Close"] + if self._quarterly + else self._yearly_exchange_rate_data["Adj Close"], items_not_to_adjust=[ "Gross Profit Ratio", "EBITDA Ratio", @@ -3160,9 +3164,9 @@ def get_cash_flow_statement( cash_flow_statement = helpers.convert_currencies( financial_statement_data=cash_flow_statement, financial_statement_currencies=self._statement_currencies, - exchange_rate_data=self.get_exchange_rates( - period="quarterly" if self._quarterly else "yearly" - )["Adj Close"], + exchange_rate_data=self._quarterly_exchange_rate_data["Adj Close"] + if self._quarterly + else self._yearly_exchange_rate_data["Adj Close"], financial_statement_name="cash flow statement", )