My algo does re-balancing monthly, but I want the initial orders to be done now, not waiting for the next month.
Can I do this with schedule_function?
My algo does re-balancing monthly, but I want the initial orders to be done now, not waiting for the next month.
Can I do this with schedule_function?
Hello Valery,
Let's say your re-balancing function is
rebalance(context,data)
. To call it monthly, perhaps you'd use:
schedule_function(rebalance,date_rules.month_start(),time_rules.market_open(hours=1))
To handle the initialization (without waiting up to a month to re-balance), you could set a flag in initialize
as context.init = True
and schedule a daily initialization function:
schedule_function(rebalance_init,date_rules.every_day(),time_rules.market_open(hours=1))
The daily call would run rebalance
once:
def rebalance_init(context,data):
# run rebalance once
if context.init:
rebalance(context,data)
context.init = False
Something along these lines should do the trick. If not, just let me know.