Optimize API RecipesΒΆ

This example calculates the optimal portfolio for the alpha factor expected_returns. It requests that the maximum gross exposure is constrained to W_max, and each position has concentration at least min_weights with at most max_weights.

Note the use of the objective MaximizeAlpha, as well as the MaxGrossExposure and PositionConcentration constraints.

import quantopian.optimize as opt

objective = opt.MaximizeAlpha(expected_returns)
constraints = [
    opt.PositionConcentration(min_weights, max_weights),
optimal_weights = opt.calculate_optimal_portfolio(objective, constraints)