I am using yfinance and ta-lib to pull in and manipulate index data from yahoo finance.
The daily data looks good but when I switch to weekly in yfinance i get some weird values.
I looked at the historical data on yahoo finance and indeed they for some reason show weekly data as of Monday instead of the previous Friday.
Does anyone know how to get around this in yfinance or maybe another way of getting the weekly data?
Thank you!
###################### EDIT: ######################
For weekly data yahoo shows 2 rows. First row is for the daily values while the second row is for the weekly values. The weekly data is as of Monday which is fine.
So the key in yfinance is to use the second to last row ([-2]) in the dataframe while for the daily data the last row ([-1]) in the dataframe works.
Tested this and it works and matches stockcharts.com
Also for weekly data you will need to remove the Nan from the dataframe. You can use.dropna() for that.
Why don't you just resample daily data to weekly with agg({"Open":"first", "Close":"last", "High":"max", "Low":"min", "Volume":"sum")
?
The weekly data interval represents not only the sampling of the data but also the range to utilize in determining open, high, low, close, etc. For example, the week of 5/18/20, you'll get the following data:
volume 133274700.000
close 318.890
open 313.170
low 310.320
high 320.890
adjclose 318.890
That data represents what that value was WITHIN that week, except for Volume which is just the sum of the volume for each day within that week. So, the open of 313.17 represents what the price was when trading opened that week. The low represents the absolute low value within that week. And, what you're looking for, the close represents what the price was at the close on Friday. So, if you're just looking for the close price on Friday, you can still use the weekly interval.
###################### ANSWER: ######################
For weekly data yahoo shows 2 rows. First row is for the daily values while the second row is for the weekly values. The weekly data is as of Monday which is fine.
So the key in yfinance is to use the second to last row ([-2]) in the dataframe while for the daily data the last row ([-1]) in the dataframe works.
Tested this and it works and matches stockcharts.com
Also for weekly data you will need to remove the Nan from the dataframe. You can use.dropna() for that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.