Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Help creating an Algorithm that trades based on predicted returns

Hey all, I wanted to reach out and see if someone could help me. I don't have much coding experience and have tried really hard to figure out how to do this but am having no success.

What I want to do is build an algorithm that uses an ARMA model to forecast stock returns for the next day. I want to make it so the algorithm goes long the top quantile of forecasted returns and short the bottom quantile. My problem is actually implementing this into an algorithm. I don't understand the IDE too much so I don't know how to actually connect the outputs of the model to the algorithm. I know how to do the computations but don't know if I should be doing this through the pipeline with a CustomFactor, or just using the pipeline to bring in daily returns and running the model on the Q500US for example. If the latter is the best way to go, I don't really get how to actually connect it to the algorithm to make the trades based on the results. I've tried reading the tutorials and lectures but I don't have a good grasp on the dynamics of the IDE.

Can someone point me in the right direction of how to do this? Maybe tutorials or example algorithms of people doing something similar where the algorithm trades based on a model output. Thank you!

1 response

Here is what I was trying to do with the pipeline but I probably did not do it right.

class compute_ARMA_forecast(CustomFactor):  
    window_safe = True  
    def compute(self, today, asset_ids, out, values):  
        model = tsa.ARMA(values, order=(1,1))  
        result = model.fit()  
        return result.forecast(steps=1)

from quantopian.pipeline.factors import Returns, DailyReturns

def make_pipeline():  
    universe=QTradableStocksUS()  
    returns = DailyReturns(mask=universe)  
    forecast = compute_ARMA_forecast(inputs=returns, mask=universe)  
    pipe = Pipeline(  
        columns={  
            'returns' : returns,  
            'forecast' : forecast  
    },  
        screen = universe)  
    return pipe

When I run_pipeline I get an error saying "Daily Returns does not have multiple outputs". I feel like I set up the CustomFactor class wrong.