jugaad-py / jugaad-data

Download live and historical data for Indian stock market
https://marketsetup.in/documentation/jugaad-data/
373 stars 150 forks source link

Missing data while pulling historical stock prices #41

Open thebigdataplayer opened 1 year ago

thebigdataplayer commented 1 year ago

Issue description

Below is the code for downloading historical stock data for a company to a CSV file

from datetime import date from jugaad_data.nse import stock_csv stock_csv(symbol="NATIONALUM", from_date=date(2020,1,1), to_date=date(2023,1,18), series="EQ", _output="D:\\Stock\\NALUM.csv")

NSE Symbol : NATIONALUM From Date : 1/1/2020 To Date : 1/18/2023

This should've pulled the data for all the 760 trading days in that time range into the CSV file. However the data is missing for the time period 10/6/2021 to 31/5/2022

This isn't a standalone issue for this particular company. All of them have the same issue of missing data for a particular period within the expected time range nationalum.txt NALUM.csv

Example Code

from datetime import date
from jugaad_data.nse import stock_csv

# Download data and save to a csv file
stock_csv(symbol="NATIONALUM", from_date=date(2020,1,1),
            to_date=date(2023,1,18), series="EQ", output="D:\\Stock\\NALUM.csv")

Error snippet

Not an error. Missing data in the output file as explained in the description
sevakram commented 1 year ago

Can you please help us with debugging.

  1. Can you please share the output of break_dates for the given date range, this function is in util.py https://github.com/jugaad-py/jugaad-data/blob/master/jugaad_data/util.py It is supposed to break the dates on month

  2. If the above step is ok, then please check if you are getting correct data from nse website for 1/6/2021 to 31/6/2021, 1/7/2021 to 30/7/2021.. randomly for few months

  3. If 2 is ok, check .cache folder in your home directory does it have data for those symbols

vaibhavsegat commented 11 months ago

I faced the same problem with the below input:

  1. 'symbol': BBOX
  2. 'from_date': 01-07-2021
  3. 'to_date': 31-07-2021
  4. 'series': EQ

With the below snippet, I got an empty DataFrame as a response.

from jugaad_data.nse import stock_df

df = stock_df('BBOX', from_date=from_date, to_date=to_date, series=series)

On looking at the data on the NSE website, I found that the series changed from EQ to BE on 2021-06-09 and onwards until 2021-11-22. bbox_nse_data

This can be fixed by changing the interface of NSEHistory._stock to accept a tuple of series, i.e. def _stock(self, symbol, from_date, to_date, series=("EQ",)):, and its usages. See the below snippets. This can be made backwards compatible relatively easily by converting series if it is a string to a tuple of string.

jugaad_data_issue1

jugaad_data_fix