I had this same problem with one of my codes, what you need to do is implement the risk model constraints, then increase the rebalance frequency. The way I did this was:
for i in range(1, 300, 50):
schedule_function(allocate, date_rules.every_day(), time_rules.market_open(minutes=i+1))
This allows rebalancing to happen more than once per day.
The risk model is implemented like this:
constrain_sector_style_risk = opt.experimental.RiskModelExposure(
risk_model_loadings=context.risk_loading_pipeline,
version=opt.Newest,
min_momentum = 0.0,
max_momentum = 0.0,
min_short_term_reversal = -0.00001,
max_short_term_reversal = 0.00001,
min_value = 0.0,
max_value = 0.0,
min_size = 0.0,
max_size = 0.0,
min_volatility = 0.0,
max_volatility = 0.0,
)
constrain_gross_leverage = opt.MaxGrossExposure(MAX_GROSS_LEVERAGE)
constrain_pos_size = opt.PositionConcentration.with_equal_bounds(
-MAX_SHORT_POSITION_SIZE,
MAX_LONG_POSITION_SIZE,
)
market_neutral = opt.DollarNeutral()
sector_neutral = opt.NetGroupExposure.with_equal_bounds(
labels=pipeline_data.sector,
min=-0.00001,
max=0.00001,
)
order_optimal_portfolio(
objective=objective,
constraints=[
constrain_gross_leverage,
constrain_pos_size,
market_neutral,
sector_neutral,
constrain_sector_style_risk,
],
)