Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Total volume for given basket of securities

I am trying to find the total volume for a basket of securities but have been unable to.

Any help would be appreciated.

4 responses
assets =symbols('XLV', 'XLK', 'XLI', 'XLP',)  
    current_volume = data.history(assets, 'volume', 2, '1d').iloc[-1]  
    TVOL=0  
    for asset in assets:  
        TVOL+= current_volume[asset]  

Sorry - I posted the wrong backtest. I need the total to come from the pipeline as I believe it is called. What I was thinking was that the volume could be summed through the "Asset" class I made. So the previous day's volume for what would be all securities. Or alternatively - from what I have called "context.output"

Here's an example. You should be able to compute the total volume with:

class VolTot(CustomFactor):  
    inputs = [USEquityPricing.volume]  
    window_length = 1  
    def compute(self, today, assets, out, volume):  
        out[:] = np.nansum(volume,axis=1)  

I can't sort out how to index the Pandas dataframe, results, or I'd confirm that the sum is correct by sampling a few days.

Thanks team!