I'm trying to fetch weekly EOD data in python using yfinance module. I wanna use the same format of the excel code given below. gives me weekly closes (Friday)
=GOOGLEFINANCE("NIFTY_50", "close", DATE(2021,2,15), DATE(2022,5,16), "weekly")
Date Column from Excel output
2/19/2021 15:30:00
2/26/2021 15:30:00
3/5/2021 15:30:00
3/12/2021 15:30:00
3/19/2021 15:30:00
3/26/2021 15:30:00
4/1/2021 15:30:00
4/9/2021 15:30:00
4/16/2021 15:30:00
4/23/2021 15:30:00
4/30/2021 15:30:00
5/7/2021 15:30:00
5/14/2021 15:30:00
5/21/2021 15:30:00
5/28/2021 15:30:00
6/4/2021 15:30:00
6/11/2021 15:30:00
6/18/2021 15:30:00
6/25/2021 15:30:00
7/2/2021 15:30:00
7/9/2021 15:30:00
7/16/2021 15:30:00
7/23/2021 15:30:00
7/30/2021 15:30:00
8/6/2021 15:30:00
8/13/2021 15:30:00
8/20/2021 15:30:00
8/27/2021 15:30:00
9/3/2021 15:30:00
9/9/2021 15:30:00
9/17/2021 15:30:00
9/24/2021 15:30:00
10/1/2021 15:30:00
10/8/2021 15:30:00
10/14/2021 15:30:00
10/22/2021 15:30:00
10/29/2021 15:30:00
11/12/2021 15:30:00
11/18/2021 15:30:00
11/26/2021 15:30:00
12/3/2021 15:30:00
12/10/2021 15:30:00
12/17/2021 15:30:00
12/24/2021 15:30:00
12/31/2021 15:30:00
1/7/2022 15:30:00
1/14/2022 15:30:00
1/21/2022 15:30:00
1/28/2022 15:30:00
2/4/2022 15:30:00
2/11/2022 15:30:00
2/18/2022 15:30:00
2022-02-25
3/4/2022 15:30:00
3/11/2022 15:30:00
3/17/2022 15:30:00
3/25/2022 15:30:00
4/1/2022 15:30:00
4/8/2022 15:30:00
4/13/2022 15:30:00
4/22/2022 15:30:00
4/29/2022 15:30:00
5/6/2022 15:30:00
5/13/2022 15:30:00
I have tried to reproduce the same in python
attempt
periods=pd.date_range(start='2021-2-19',periods=67,freq='W')
start = periods[0].strftime('%Y-%m-%d')
end = periods[-1].strftime('%Y-%m-%d')
#y=x+pd.offsets.WeekOfMonth(week=0,weekday=4) #week0=first week ; week3=last week
#periods = pd.date_range(end=datetime.datetime.today(), periods=60, freq='M')
start = periods[0].strftime('%Y-%m-%d')
end = periods[-1].strftime('%Y-%m-%d')
#print(start, end)
print(start,end)
with open('/Users/ifinder/Coding/Projects/DEMO/Stock_market/Nifty_500_candlestick-screener/datasets/symbols.csv') as f:
for line in f:
if "," not in line:
continue
symbol = line.split(",")[0]
df = yf.download(symbol, start=start, end=end,retry_count=3,interval="1wk")
#print(df)
Problem : Yfinance interval"1wk" defaulted to Monday where as Google Finance dataset is based on Friday closing data. So I am looking for some help to display Friday weekly closing prices instead of Monday.
Additional Condition : I need the row count to be exactly as in the excel sheet and needs to be populated every week.
Start= -65th friday closing price (eg: 2/19/2021 15:30:00)
End= Current week's friday close (eg: 5/13/2022 15:30:00)
So on a typical Sat night , when I run the program, I'll be able to see the last 65 weeks Closing prices(FRIDAY) as an output.
Thanks!