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

Chpt #6; Example stock returns: ystockquote is not working #540

Open
codeja3 opened this issue Feb 23, 2022 · 0 comments
Open

Chpt #6; Example stock returns: ystockquote is not working #540

codeja3 opened this issue Feb 23, 2022 · 0 comments

Comments

@codeja3
Copy link

codeja3 commented Feb 23, 2022

I could not make ystockquote to work no matter what I tried. Instead I used yahoo's yfinance package which has a straightforward api.
I'm recording the updated code here in case someone encounters the same problem.

import yfinance as yf
import pandas as pd

n_observations = 100 # we will truncate the the most recent 100 days.

stocks = ["AAPL", "GOOG", "TSLA", "AMZN"]

enddate = "2022-02-19"
startdate = "2021-07-01"

stock_closes = pd.DataFrame()

for stock in stocks:
x = yf.download(stock, startdate, enddate)
stock_closes[stock] = x['Close']

stock_closes
stock_returns = stock_closes.pct_change().iloc[1:, :]
stock_return = stock_returns.iloc[-n_observations:,:]

@codeja3 codeja3 changed the title Example stock returns: ystockquote is not working Chpt #6; Example stock returns: ystockquote is not working Feb 23, 2022
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

1 participant