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

Bump yfinance to 0.2.4 and fix tests #3977

Merged
merged 13 commits into from
Jan 16, 2023
5 changes: 4 additions & 1 deletion openbb_terminal/futures/yfinance_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,14 @@ def get_historical_futures(symbols: List[str], expiry: str = "") -> pd.DataFrame

return yf.download(symbols_with_expiry, progress=False, period="max")

df = yf.download([t + "=F" for t in symbols], progress=False, period="max")
df = yf.download(
[t + "=F" for t in symbols], progress=False, period="max", ignore_tz=True
)
if len(symbols) > 1:
df.columns = pd.MultiIndex.from_tuples(
[(tup[0], tup[1].replace("=F", "")) for tup in df.columns]
)

return df


Expand Down
7 changes: 4 additions & 3 deletions openbb_terminal/portfolio/portfolio_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ def set_benchmark(self, symbol: str = "SPY", full_shares: bool = False):
start=self.inception_date - datetime.timedelta(days=1),
threads=False,
progress=False,
ignore_tz=True,
)["Adj Close"]

p_bar.n += 1
Expand Down Expand Up @@ -650,9 +651,9 @@ def __load_portfolio_historical_prices(self, use_close: bool = False):
p_bar = tqdm(range(len(self.tickers)), desc=" Loading price data")

for ticker_type, data in self.tickers.items():
price_data = yf.download(data, start=self.inception_date, progress=False)[
"Close" if use_close or ticker_type == "CRYPTO" else "Adj Close"
]
price_data = yf.download(
data, start=self.inception_date, progress=False, ignore_tz=True
)["Close" if use_close or ticker_type == "CRYPTO" else "Adj Close"]

# Set up column name if only 1 ticker (pd.DataFrame only does this if >1 ticker)
if len(data) == 1:
Expand Down
11 changes: 6 additions & 5 deletions openbb_terminal/stocks/backtesting/bt_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import yfinance as yf

from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import is_intraday
from openbb_terminal.common.technical_analysis import ta_helpers
from openbb_terminal.helper_funcs import is_intraday

logger = logging.getLogger(__name__)

Expand All @@ -32,13 +32,14 @@ def get_data(symbol: str, start_date: str = "2019-01-01") -> pd.DataFrame:
prices: pd.DataFrame
Dataframe of Adj Close with columns = [ticker]
"""
data = yf.download(symbol, start=start_date, progress=False)
data = yf.download(symbol, start=start_date, progress=False, ignore_tz=True)
close_col = ta_helpers.check_columns(data, high=False, low=False)
if close_col is None:
return pd.DataFrame()
prices = pd.DataFrame(data[close_col])
prices.columns = [symbol]
return prices
df = pd.DataFrame(data[close_col])
df.columns = [symbol]

return df


@log_start_end(log=logger)
Expand Down
17 changes: 12 additions & 5 deletions openbb_terminal/stocks/comparison_analysis/yahoo_finance_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_historical(
# To avoid having to recursively append, just do a single yfinance call. This will give dataframe
# where all tickers are columns.
similar_tickers_dataframe = yf.download(
similar, start=start_date, progress=False, threads=False
similar, start=start_date, progress=False, threads=False, ignore_tz=True
)[d_candle_types[candle_type]]

returnable = (
Expand Down Expand Up @@ -195,10 +195,16 @@ def get_1y_sp500() -> pd.DataFrame:
pd.DataFrame
DataFrame containing last 1 year of closes for all SP500 stocks.
"""
return pd.read_csv(
df = pd.read_csv(
"https://raw.githubusercontent.com/jmaslek/daily_sp_500/main/SP500_prices_1yr.csv",
index_col=0,
)
df.reset_index(inplace=True)
df["Date"] = pd.to_datetime(df["Date"], format="%Y-%m-%d", utc=True).dt.strftime(
"%Y-%m-%d"
)
df.set_index("Date", inplace=True)
return df


# pylint:disable=E1137,E1101
Expand Down Expand Up @@ -230,10 +236,11 @@ def get_sp500_comps_tsne(

# Adding the type makes pylint stop yelling
close_vals: pd.DataFrame = get_1y_sp500()

if symbol not in close_vals.columns:
df_symbol = yf.download(symbol, start=close_vals.index[0], progress=False)[
"Adj Close"
].to_frame()
df_symbol = yf.download(
symbol, start=close_vals.index[0], progress=False, ignore_tz=True
)["Adj Close"].to_frame()
df_symbol.columns = [symbol]
df_symbol.index = df_symbol.index.astype(str)
close_vals = close_vals.join(df_symbol)
Expand Down
1 change: 1 addition & 0 deletions openbb_terminal/stocks/due_diligence/ark_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def get_ark_trades_by_ticker(symbol: str) -> pd.DataFrame:
end=df_orders.Date.iloc[0],
start=df_orders.Date.iloc[-1],
progress=False,
ignore_tz=True,
)["Close"]

df_orders.set_index("Date", inplace=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ def get_mktcap(
start_date = (datetime.now() - timedelta(days=3 * 366)).strftime("%Y-%m-%d")

currency = ""
df_data = yf.download(symbol, start=start_date, progress=False, threads=False)
df_data = yf.download(
symbol, start=start_date, progress=False, threads=False, ignore_tz=True
)
if not df_data.empty:

data = yf.Ticker(symbol).info
Expand Down
5 changes: 4 additions & 1 deletion openbb_terminal/stocks/stocks_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,12 @@ def load_ticker(
>>> from openbb_terminal.sdk import openbb
>>> msft_df = openbb.stocks.load("MSFT")
"""
df_data = yf.download(ticker, start=start_date, end=end_date, progress=False)
df_data = yf.download(
ticker, start=start_date, end=end_date, progress=False, ignore_tz=True
)

df_data.index = pd.to_datetime(df_data.index)

df_data["date_id"] = (df_data.index.date - df_data.index.date.min()).astype(
"timedelta64[D]"
)
Expand Down
7 changes: 6 additions & 1 deletion openbb_terminal/stocks/stocks_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ def load_stock_yf(

# Adding a dropna for weekly and monthly because these include weird NaN columns.
df_stock_candidate = yf.download(
symbol, start=start_date, end=end_date, progress=False, interval=int_
symbol,
start=start_date,
end=end_date,
progress=False,
interval=int_,
ignore_tz=True,
).dropna(axis=0)

# Check that loading a stock was not successful
Expand Down
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ alpha-vantage = "^2.3.1"
finviz = "^1.3.4"
bs4 = "^0.0.1"
rapidfuzz = "^1.1.1"
yfinance = "^0.2.1"
yfinance = "0.2.4"
psaw = "^0.0.12"
praw = "^7.1.4"
Quandl = "^3.6.0"
Expand Down
2 changes: 1 addition & 1 deletion requirements-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,6 @@ xarray==2022.11.0; python_version >= "3.8"
xgboost==1.7.2; python_version >= "3.8"
xlsxwriter==3.0.3; python_version >= "3.7"
yarl==1.8.1; python_version >= "3.7" and python_full_version >= "3.7.0"
yfinance==0.2.3
yfinance==0.2.4
zipp==3.10.0; python_version >= "3.7" and python_full_version < "3.9.7" and python_version < "3.10" or python_full_version > "3.9.7" and python_version >= "3.7" and python_version < "3.10"
zope.interface==5.5.0; python_version >= "3.5" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.5"
Loading