I am new to the Q . I am doing my first algo and have some difficulty dealing with position concentration using the optimzealpha. When I run backtest, I meet 6/7 risk profiles except that I see a one day spike in positions. I am not sure how to fix that. Please help!
Here are some of the params/constraints I use:
Constraint Parameters
MAX_GROSS_LEVERAGE = 1.0
MAX_SHORT_POSITION_SIZE = 0.025 # 1.5%
MAX_LONG_POSITION_SIZE = 0.025 # 1.5%
MIN_BETA_EXPOSURE = -0.005
MAX_BETA_EXPOSURE = 0.005
MAX_SECTOR_EXPOSURE = 0.10
constraints = []
constrain_gross_leverage = opt.MaxGrossExposure(MAX_GROSS_LEVERAGE)
constraints.append(constrain_gross_leverage)
constrain_pos_size = opt.PositionConcentration.with_equal_bounds(
-MAX_SHORT_POSITION_SIZE,
MAX_LONG_POSITION_SIZE,
)
constraints.append(constrain_pos_size)
market_neutral = opt.WeightedExposure(
loadings=pd.DataFrame({'beta': context.returns.beta}),
min_exposures={'beta': -MAX_BETA_EXPOSURE},
max_exposures={'beta': MAX_BETA_EXPOSURE},
)
constraints.append(market_neutral)
dollar_neutral = opt.DollarNeutral(tolerance=0.001)
constraints.append(dollar_neutral)
sector_neutral = opt.NetGroupExposure.with_equal_bounds(
labels=context.sector,
min=-0.1,
max=0.1,
)
constraints.append(sector_neutral)
constrain_sector_style_risk = opt.experimental.RiskModelExposure(
context.risk_loading_pipeline,
version=opt.Newest,
)
constraints.append(constrain_sector_style_risk)
order_optimal_portfolio(
objective=objective,
constraints=constraints
)