Skip to content

Commit

Permalink
Bugfix for #128
Browse files Browse the repository at this point in the history
  • Loading branch information
JerBouma committed Apr 2, 2024
1 parent b244ff9 commit 8babe30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
3 changes: 3 additions & 0 deletions financetoolkit/historical_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
28 changes: 16 additions & 12 deletions financetoolkit/toolkit_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
)

Expand Down

0 comments on commit 8babe30

Please sign in to comment.