Hi, I'm new to Quantopian and currently working on my first algorithm. I would like to calculate of the % price change in a stock over 20 days to the % price change in the SPY ETF over the same period of days. I currently have the following pipeline code:
def make_pipeline():
universe = QTradableStocksUS()
stock_returns = Returns(window_length=20) * 100 + 100
spy_returns = stock_returns[symbols('SPY')]
stock_returns_to_spy_returns = stock_returns / spy_returns * 100
return Pipeline(columns={'stock returns': stock_returns, 'stock returns to SPY': stock_returns_to_spy_returns, 'spy returns': spy_returns},
screen=universe
)
The problem is that this gives me an error for the spy returns column:
Cannot add column 'spy returns' with term NumExprFactor(...)[Equity(8554 [SPY])]. Adding slices or single-column-output terms as pipeline columns is not currently supported.
Does anyone know how to fix this? Ideally I would like to divide the values by each other indexed to 100. For example, if stock XYZ returns over a 20 day period are 10% and SPY returns over the same 20 day period are 5%, the stock returns to spy column should return 110/105*100=104.76~. Any different ways to achieve this would also be appreciated!