Skip to content

Commit

Permalink
Introduce a fix that caused currency conversions to fail when all tic…
Browse files Browse the repository at this point in the history
…kers have the same currency
  • Loading branch information
JerBouma committed Aug 6, 2024
1 parent 7ddd6b1 commit 280f773
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions financetoolkit/toolkit_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2631,25 +2631,46 @@ def get_exchange_rates(
]

if self._daily_exchange_rate_data.empty or overwrite:
self._daily_exchange_rate_data, _ = _get_historical_data(
tickers=currencies_to_collect_data_for,
api_key=self._api_key,
source=self._historical_source,
start=self._start_date,
end=self._end_date,
interval="1d",
return_column=return_column,
risk_free_rate=pd.DataFrame(),
include_dividends=False,
progress_bar=progress_bar
if progress_bar is not None
else self._progress_bar,
fill_nan=fill_nan,
rounding=rounding if rounding else self._rounding,
sleep_timer=self._sleep_timer,
show_ticker_seperation=show_ticker_seperation,
tqdm_message="Obtaining exchange data",
)
if currencies_to_collect_data_for:
self._daily_exchange_rate_data, _ = _get_historical_data(
tickers=currencies_to_collect_data_for,
api_key=self._api_key,
source=self._historical_source,
start=self._start_date,
end=self._end_date,
interval="1d",
return_column=return_column,
risk_free_rate=pd.DataFrame(),
include_dividends=False,
progress_bar=progress_bar
if progress_bar is not None
else self._progress_bar,
fill_nan=fill_nan,
rounding=rounding if rounding else self._rounding,
sleep_timer=self._sleep_timer,
show_ticker_seperation=show_ticker_seperation,
tqdm_message="Obtaining exchange data",
)
else:
# In case there is no conversion needed, it should just create an empty DataFrame
self._daily_exchange_rate_data = pd.DataFrame(
index=pd.PeriodIndex(
pd.date_range(
start=self._start_date, end=self._end_date, freq="D"
)
),
columns=[
"Open",
"High",
"Low",
"Close",
"Adj Close",
"Volume",
"Return",
"Volatility",
"Cumulative Return",
],
)

# For exchange data, it is possible that a ticker such as USDUSD=X
# exists which should always be 1. This data is added here.
Expand Down

0 comments on commit 280f773

Please sign in to comment.