ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.89k stars 2.44k forks source link

Fix 30min interval of ^NSEI #2026

Closed aleksfasting closed 3 months ago

aleksfasting commented 3 months ago

Fix 30min interval of ^NSEI and indian exchange

Regarding #1436 and #1447

Summary

The Indian stock exchange opens at 09.15, so when requesting the history of '^NSEI' by 30 minute intervals, the resampling will not include the first 15 minutes of the day. Note: This only happens to 30 min intervals because of the specific handling of 30 min.


Solution

@ivan23kor created a pull request some time ago to solve the issue, but the solution is now outdated.

I propose a solution that checks what time the exchange opens and adds that to the offset that ivan suggested:

exchangeStartTime = pd.Timestamp(self._history_metadata["tradingPeriods"][0][0]["start"], unit='s')
offset = str(exchangeStartTime.minute % 30)+"min"
quotes2 = quotes.resample('30min', offset=offset)
aleksfasting commented 3 months ago

2027 was merged. Issue is closed