Hi,
I'm curious if it's possible to rebalance daily AND weekly in the same strategy, using Optimize API with different alpha factors? The reason I'm asking is because one may have some factors that are predictive with high IC during a 1 day holding period, and other factors that are only predictive (with alpha) on a longer holding period (e.g. 5 days, or weekly)?
I've tried something like the below, but I believe it still rebalances everything daily (and the weekly positions gets thrown out the next day essentially). Is there any way to have the daily_rebalance ignore the weekly_positions? How would one go about doing this in the same strategy? Appreciate any help or advise I can get on this.
def initialize(context):
schedule_function(
weekly_rebalance,
date_rules.week_start(),
time_rules.market_open(),
)
schedule_function(
daily_rebalance,
date_rules.every_day(),
time_rules.market_open(),
)
attach_pipeline(
make_pipeline(),
'data_pipe'
)
attach_pipeline(
risk_loading_pipeline(),
'risk_pipe'
)
def weekly_rebalance(context, data):
objective = opt.MaximizeAlpha(
context.output.weekly_alpha
)
constrain_pos_size = opt.PositionConcentration.with_equal_bounds(
-context.short_pos_size,
context.long_pos_size
)
dollar_neutral = opt.DollarNeutral()
leverage = opt.MaxGrossExposure(1.0)
factor_risk_constraints = opt.experimental.RiskModelExposure(
context.risk_factor_betas,
version=opt.Newest,
)
order_optimal_portfolio(
objective=objective,
constraints=[
leverage,
dollar_neutral,
constrain_pos_size,
factor_risk_constraints,
]
)
def daily_rebalance(context, data):
objective = opt.MaximizeAlpha(
context.output.daily_alpha
)
constrain_pos_size = opt.PositionConcentration.with_equal_bounds(
-context.short_pos_size,
context.long_pos_size
)
dollar_neutral = opt.DollarNeutral()
leverage = opt.MaxGrossExposure(1.0)
max_turnover = opt.MaxTurnover(0.20)
factor_risk_constraints = opt.experimental.RiskModelExposure(
context.risk_factor_betas,
version=opt.Newest,
)
order_optimal_portfolio(
objective=objective,
constraints=[
leverage,
dollar_neutral,
constrain_pos_size,
max_turnover,
factor_risk_constraints,
]
)