Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to access history volume by time?

hello everyone,

I am new here, and trying to access the history data-set by time for example:

exchange_time = pd.Timestamp(get_datetime()).tz_convert('US/Eastern')

vol_first15minutes = history(20*390, '1m','volume')  

for v in vol_first15minutes:  
    if exchange_time.hour == 9 and (exchange_time.minute >= 30 and exchange_time.minute <= 45):  
   # I want to get the volume if that bar was between 9:30 and 9:45  

Any help is highly appreciated

2 responses

Ok I found a way, here it is

dframe = history(390, '1m', 'volume')  # pandas dataframe

# loop through all stocks  
for stock in data:  
        # loop through the whole series  
        for i in range(0,len(dframe)):  
            if dframe[stock].index.hour[i] == 9+4 and dframe[stock].index.minute[i] == 45:  
                print dframe[stock][i]  

if any one got a more efficient way please share

another more efficient way is to use the between_time pandas method

for stock in data:  
        vol_frame = history(20*390, '1m', 'volume')[stock]  
        context.vol_dict['9:30-9:45'] = vol_frame.between_time('13:30','13:45').cumsum()