I want to control the weekly turnover. I want to get a weekly turnover of 30% I tried to control it with rebalance, but it didn't work.
def initialize(context):
"""
Called once at the start of the algorithm.
"""
context.max_turnover = 0.03
schedule_function(
rebalance,
date_rules.week_start(),
time_rules.market_close(hours=2),
)
attach_pipeline(make_pipeline(context), 'pipeline')
def rebalance(context, data):
output = pipeline_output('pipeline')
factor = output.factor
max_turnover = opt.MaxTurnover(context.max_turnover)
order_optimal_portfolio(
constraints=[max_turnover],
)