Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Applying constraint on minimum number of securities in final portfolio

I'm trying to create a portfolio out of S&P 500, adding some thematic constraints.
My objective is to minimize tracking error.

However, the number of securities in my final portfolio that are getting weight allocations is around 50-60.
I need to add a constraint, to allocate weights to at least 150 securities, with minimum threshold weight at 0.01%.

Any ideas on how to implement that? weights vector is a cvx variable.

Thanks a lot

2 responses

Could you attach a backtest showing the algorithm. That might help to troubleshoot.

Regards.

I agree with Dan but in the meantime, please let me know if this helps at all, dynamically setting PositionConcentration based on the number of securities.

    pconc = 1.0 / alpha.size  
    order_optimal_portfolio(  
        objective   = opt.MaximizeAlpha( alpha ),  
        constraints = [  
            opt.PositionConcentration.with_equal_bounds(-pconc, pconc),  

And then for someone who knows, it would be great to see a description of how MaximizeAlpha approaches allocations. I noticed as PositionConcentration moves toward zero, number of positions increase. Does it begin allocating to whatever it determines are likely the highest in alpha using PositionConcentration values and simply stop when it runs out of room?