Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Custom Minute Time Frame Bars

For a strategy that I am attempting to write I need to reference the custom bars history along with 1 minute data. The custom previous bars that I need to reference are just high/low from the first 300 minutes of trading day of the 5 previous days. What is the best/fastest way to create these custom price time frames to reference?

2 responses

Maybe something like this


my_stock = symbol('AAPL')  
minutes_in_5_days = 390*5

# Get the highs  
my_highs = data.get_history(my_stock, 'high', minutes_in_5_days, '1m')

# Add a column with just the date  
my_highs['date']= my_highs.index.date

# Group by the date and take the 300 first (ie head) minutes of each date  
just_first_300_min = my_highs.groupby(['date']).head(300)

If you're just getting a single stock then the 'get_history' method returns a dataframe and this approach works fine. If you are getting multiple stocks it will be similar but not exactly the same.

see attached notebook.

Thanks Dan, this seem like a more stable approach than I was taking which was manually storing previous days. It does not recognize get_history as a function for some reason which may be because I am using futures. If I use just the regular history function, the groupby is giving me the error that the grouper and axis must be the same length.