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.

Clone Algorithm
1
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58717adb388c2961ef747377
There was a runtime error.
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]  
Clone Algorithm
2
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5871b819e1ed92623e4ce131
There was a runtime error.

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"

Clone Algorithm
1
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 58727b041c62d65e6f0d3a29
There was a runtime error.

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.

Loading notebook preview...
Notebook previews are currently unavailable.

Thanks team!