Why date dont match with my query?
Yahoo finance has the data from 1998.
https://finance.yahoo.com/quote/XLU/history?period1=914284800&period2=1600819200&interval=1d&filter=history&frequency=1d
@pyquant Here is the generic routine:
from dateutil import parserfrom datetime import timedeltafrom datetime import datetimeimport mathimport time
def date_range(start, end, intv): start = datetime.strptime(start,"%Y-%m-%d") end = datetime.strptime(end,"%Y-%m-%d") diff = (end - start ) / intv for i in range(intv): yield (start + diff * i).strftime("%Y-%m-%d") yield end.strftime("%Y-%m-%d")
def get_daily(rics,fields,start,end): for ric in rics: interval = math.ceil((parser.parse(end) - parser.parse(start)).days / 3000) l = list(date_range(start,end,interval)) df1 = pd.DataFrame() df = pd.DataFrame() for i in range(interval): ts = ek.get_timeseries(rics=ric,fields=fields, start_date=l[0+i],end_date=l[1+i], interval='daily') df = df.append(ts) time.sleep(0.4) return df
rics = ['.GDAXI'] # Just for one ric at the moment I will extend this for multi-ricfields = ['OPEN', 'HIGH', 'LOW', 'CLOSE']start = '1990-06-04'end = '2018-06-04'df = get_daily(rics,fields,start,end)df
I hope this can help.
Hi @pyquant Thanks for your question - the reason is because the timeseries API is limited to 3000 rows per interday request. You can see the limits for each in this document.
You can of course iterate these calls as you are already doing for each RIC. But you can also achieve this with 2 calls per RIC.
df1 = ek.get_timeseries(i, ['CLOSE'],start_date="1999-01-02", end_date="2008-10-22")df2 = ek.get_timeseries(i, ['CLOSE'],start_date="2008-10-23")df = pd.concat([df1, df2], axis=0)
I hope this can help - I have a generic routine for the date calcs somewhere I will add it when i find it.
Thanks. I will give it a try.