Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to convert buy probability to optimal alph

I was attending the contest, now my model can be used to predict buy of sell, but I do not know how to use the new optimization api, like MaximizeAlpha, i mean what parameter should i pass to this API, if i know which stocks to buy or sell.

1 response

Hi Xiong,

Have a look at Optimize API and the MaximizeAlpha class in the documentation. Also have a look at the Long/Short equity template to see MaximizeAlpha implemented in a strategy.

In short, you set the objective to maximize alpha based on an alpha factor that you pass in. The higher the value in the factor, the stronger the buy, and vice versa for sells. Something like this.

    objective = opt.MaximizeAlpha(  
      context.pipeline_output.alpha_factor  
    )  

Then you order_optimal_portfolio passing in your objective and any constraints you've defined. Something like this:

    order_optimal_portfolio(  
        objective=objective,  
        constraints=[  
            leverage,  
            dollar_neutral,  
            constrain_pos_size,  
            # min_turnover,  
            factor_risk_constraints,  
        ]  
    )

See the template as an example. Good luck!