Hi,
how to get past 20 days historical 5 minutes data starting from yesterday using request_historical_data?
Thanks
Hi,
how to get past 20 days historical 5 minutes data starting from yesterday using request_historical_data?
Thanks
I'm not aware of a method called "request_historical_data". If you are wanting this data in a notebook then probably use the "get_pricing" method. If you are are looking to implement this in an algorithm then use the "data.history" method.
So, first, which environment are you working in? Second, is the issue how to get 5 minute data or how to get data for only yesterday and the previous 19 days?. Consider using the "date_range" method in pandas to create a range with a freq of 5 minutes starting 20 days ago. Then simply use the "loc" method to return only rows in that range. Perhaps use the "resample" method instead of specifying a freq if you want more control over how data is resampled,
I am using quantopian, looking for OHLCV data ranging from( last trading day upto lookback 20days)
Could you assist me to correct this ?
history_20d= data.history(context.security, , 'open','high', 'low' 'close','?', '5m').resample('20').last()
Try this (which assumes context.security is a single security)
min_in_20_days = 20 * 390 # this won't exactly work if there are any half trading days
history_20d = data.history(
context.security,
fields= ['open','high', 'low' 'close'],
bar_count=min_in_20_days,
frequency='1m'
)
history_20d_5m = resample('1M').last()
This doesn't resample exactly correctly because you probably want the highest high and the lowest low and not simply the last one. Take a look at this post for resampling to accomplish that https://www.quantopian.com/posts/how-do-i-get-monthy-data-from-daily-data .
Also, if you are using this in an algo and truly want the previous 20 days, put this code into the 'before_trading_start' method. That ensures you don't get any of the current days data.