Data from yahoo finance

Hi, when I retreive a data from finance yahoo (yfinance), for stocks the matplotlib shows also a data (which is non) between close and open next day time. Can someone share I can fix that with no getting a time horizon between close and open?

1 Like

It is not showing data, it is only using straight lines to connect all the data points that it has.

There are many options you can use for the plot function to control how it draws the points and lines. But if you ask it not to draw lines in between, then it will also not connect the real data points.

If you want to pretend that there was no actual time between the market close and the market open, you can change the time data, or just replace it with a sequence of numbers 0, 1, 2 etc., or you can skip them completely and only give the price values.

(By the way, it is not correct to say “close prices” if you are checking the price every 5 minutes. The “close” price only means the very last price recorded for each day.)

Bar data typically has open, high, low, and close values for each bar. Just pointing out that the OP isn’t really out of line referring to close prices for five minute bars.

Fair enough.

I don’t suppose you know a way to make it conditionally not connect specific adjacent points?

Your suggestion of sequentially numbering the in-session data seems reasonable to me. You’d then need to map the sequence numbers to displayable timestamps. I’m not sure how you’d do that in matplotlib, but I’m sure there’s a way to accomplish that feat. I never worried too much about it for my own personal plotting and never needed it professionally (I was in finance for a long while).

Actually… I wonder if it would work to separate the data into separate chunks per day (each labelled with the appropriate timestamps) and then just overlay the plots?

(Just thinking out loud…)

If one session ends Wednesday at 15:00 CST and the next session begins Thursday at 8:30am CST, wouldn’t simply overlaying the two plots leave a gap? You’d still have to know about the 17.5 hour gap and offset the next day’s plot accordingly. Same for weekends and holidays. Don’t forget shortened sessions (as often exist on the last trading day before a holiday). Oh, and then there are unexpected market closures (as you sometimes see for an ex-president’s funeral). You’d also have to compute the min and max prices over the entire data set so all y axes are scaled correctly. Certainly doable, just tedious. (You’d need a real good trading calender, if nothing else.)

Yes; I’m proposing a chart that just leaves the gaps there, so that the x-axis still shows time flowing linearly. For all I know, that’s what the OP actually wants. If each plot has its own time data I think they would all be plotted in the right places.

Thanks both. I have basic knowledges on python, as a I am just a financial :slight_smile:
Did change to Karl’s recommendation with a sequence of numbs it has fixed with no lines.