yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

Don't fix_Yahoo_returning_prepost_unrequested on Indian exhanges and 30m interval

Open ivan23kor opened this issue 2 years ago • 12 comments

Addresses #1436.

ivan23kor avatar Mar 09 '23 04:03 ivan23kor

@ValueRaider, the only problem I have is that fix_Yahoo_returning_prepost_unrequested won't be run for 15m intervals either, because we Ticker.history() overwrites the user-specified interval of 30m with 15m.

ivan23kor avatar Mar 09 '23 04:03 ivan23kor

the order of fix_Yahoo_returning_prepost_unrequested and downsampling doesn't matter in this case, as trading start date is 9:15 but the downsampling interval is 30m.

I don't understand, please elaborate.

ValueRaider avatar Mar 09 '23 12:03 ValueRaider

For 30m interval (15m, actually), the timestamps in the data just after fetching by requests look like this: 8:45, 9:00, 9:15, 9:30, 9:45, 10:00 ...

Now, the exchange start time is 9:15.

If you downsample first, you get 9:00, 9:30, 10:00, ..., then fix_Yahoo_returning_prepost_unrequested will remove 9:00.

If you fix_Yahoo_returning_prepost_unrequested first, you get 9:15, 9:30, 9:45, 10:00, ..., then downsampling removes 9:15.

In either case, 9:00 will be removed.

ivan23kor avatar Mar 09 '23 15:03 ivan23kor

@ValueRaider, changed the interval check to the user-provided interval, instead of the interval passed to requests, so now fix_Yahoo_returning_prepost_unrequested will be skipped for NSI and BSE only for the true 30m interval.

ivan23kor avatar Mar 09 '23 15:03 ivan23kor

In either case, 9:00 will be removed.

Wrong. I am running code now, if I reorder then yfinance returns downsampled interval 09:00 -> 09:30.

ValueRaider avatar Mar 09 '23 16:03 ValueRaider

You are right, that works! Pushed reordering.

ivan23kor avatar Mar 09 '23 17:03 ivan23kor

Good, that fixes the first interval. But I'm still not convinced aligning to HH:00 is the right choice. You said:

Yahoo Finance's frontend returns HH:00 timestamps for some reason and yfinance should follow that behaviour.

This is a terrible reason - Yahoo is US-centric and doesn't trade, so their reason is overruled by an Indian trader. I don't trade intraday so don't know a good authority on this. @AbhishekSRaut

ValueRaider avatar Mar 09 '23 22:03 ValueRaider

Tradingview for ^NSEI starts with 9:15. That's a good enough argument for me to shift the beginning of 30m data for NSE and BSE to HH:15.

ivan23kor avatar Mar 09 '23 23:03 ivan23kor

agreed with @ValueRaider other factors, like regional trading practices, should be considered when deciding on the best approach.

Tradingview for ^NSEI starts with 9:15. That's a good enough argument for me to shift the beginning of 30m data for NSE and BSE to HH:15.

this officialy mention here. you can read:

Normal / Limited Physical Market Open: 09:15 hrs Normal / Limited Physical Market Close: 15:30 hrs

thanks @ivan23kor and @ValueRaider to understand this and decide to fix it.

AbhishekSRaut avatar Mar 10 '23 06:03 AbhishekSRaut

@AbhishekSRaut do you want the intervals to be [9:15AM, 3:15PM] or [9:15AM, 3:30PM]?

@ValueRaider, I added [9:15AM, 3:15PM] for (NSI, BSE) and kept [9:30AM, 3:30PM] for other exchanges.

ivan23kor avatar Mar 15 '23 00:03 ivan23kor

Where in the code does 3:15pm vs 3:30pm matter?

ValueRaider avatar Mar 15 '23 14:03 ValueRaider

do you want the intervals to be [9:15AM, 3:15PM] or [9:15AM, 3:30PM]?

if you talking about starting time of each candle, then its surely starts from 9:15 AM, and last is 3:15PM 3:30 PM is closing time i.e. the "last candle" which starts at 3:15 PM, will end at 3:30 PM.

AbhishekSRaut avatar Mar 16 '23 07:03 AbhishekSRaut