ranaroussi / yfinance

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

Duplicate data on period='1d' #573

Closed pratik-choudhari closed 2 years ago

pratik-choudhari commented 3 years ago

On running history(period='1d') for any stock, duplicate data is returned. Here is the screenshot of output. Everything is same except volume. Is this being done deliberately?

aapl_stock

HumanRupert commented 3 years ago

Facing the same issue.

# yfinance returns the same date twice if the period is 1d
if(period == "1d" and interval == "1d"):
  price_action = price_action.head(1)

Will do.

Should I make a pull request? @ranaroussi

pratik-choudhari commented 3 years ago

I dont think maintainers are active in this repo

scott-n58 commented 3 years ago

yeah . . . . . df = df[:-1] from here: https://stackoverflow.com/questions/26921651/how-to-delete-the-last-row-of-data-of-a-pandas-dataframe

i would strongly encourage Mr. Aroussi to better support his creations . . . . .

beglitis commented 3 years ago

Facing the same issue.

# yfinance returns the same date twice if the period is 1d
if(period == "1d" and interval == "1d"):
  price_action = price_action.head(1)

Will do.

Should I make a pull request? @ranaroussi

Can you point out where is the bug in the code?

scott-n58 commented 3 years ago

this is a problem whether period = '1d' or start_date = "YYYY-MM-DD", end_date = "YYYY-MM-DD"

the code result returns duplicate record of last trading day.

HumanRupert commented 3 years ago

Facing the same issue.

# yfinance returns the same date twice if the period is 1d
if(period == "1d" and interval == "1d"):
  price_action = price_action.head(1)

Will do. Should I make a pull request? @ranaroussi

Can you point out where is the bug in the code?

@beglitis It's an issue from Yahoo! Finance side.

Check this, e.g., https://query1.finance.yahoo.com/v8/finance/chart/TSLA?symbol=TSLA&interval=1d&range=1d

It returns two rows of data.

beglitis commented 3 years ago

I thought so that is why I asked where is the bug in the code. :)

HumanRupert commented 3 years ago

Yea but adding the if statement above fixes the problem.

On Wed, Feb 17, 2021, 1:02 PM beglitis notifications@github.com wrote:

I thought so that is why I asked where is the bug in the code. :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ranaroussi/yfinance/issues/573#issuecomment-780426228, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK7FVIVD4BKERHXIGRYVQLDS7OELLANCNFSM4W2NAQFA .

Victor-Botelho commented 3 years ago

Having the same problem for one ticker specifically. All others I've worked quite well. Been using the library everyday for a couple of weeks and just noticed this, so it might or might not have just started acting like this. Still not sure. Sure would be nice to have an official fix.

bbdc4

yiwenxu6 commented 3 years ago

The same issue here! Could the maintainer help solve this? It seems that whenever you try to download using period '1d' or '5d' (I also tested other intervals, and they all passed my tests) during the weekend set the start to be the Friday that just passed, it will duplicate. A related bug is that if you set the start to be Saturday, it will still include the data of Friday (but a single data). I guess that's the reason it duplicates: one indeed for Friday and the other for Saturday. The latter is definitely a bug!

It seems that this only occurs when you download the data during the weekend and your start is the closest Friday or Saturday. For example, now it is 6/13/2021 (Sunday), if I write

data = yf.download('AMC', start = '2021-06-11', end = '2021-06-13' , interval = '1d')

It will show image

But if I write (also start from a Friday end on a Sunday)

data = yf.download('AMC', start = '2021-06-04', end = '2021-06-06' , interval = '1d')

It shows correctly: image

A very simple way to solve this bug is as follows.

if data.shape[0] >= 2 and data.index[-1] == data.index[-2]:
    data = data[:-1]
mathieugouin commented 2 years ago

Just to chime in that I'm having the same issue.

ValueRaider commented 2 years ago

Is this still happening?