Can someone show me how to modify this algo to trade once every 3 months?
Thanks,
Troy
Can someone show me how to modify this algo to trade once every 3 months?
Thanks,
Troy
Troy ,
Try this:
def initialize(context):
schedule_function(rebalance, date_rules.month_start(0), time_rules.market_open( minutes = 90))
context.counter = 0
def rebalance(context, data):
freq_month = 3
context.counter += 1
if context.counter == freq_month:
trade(context, data)
context.counter = 0
def trade(context, data):
# ---------------------------------------------------
security_list = symbols('VHT', 'VDC', 'VGT', 'TQQQ',)
weights = 0.99/len(security_list)
# ---------------------------------------------------
if get_open_orders(): return
for sec in security_list:
if data.can_trade(sec):
order_target_percent(sec, weights)
exchange_time = get_datetime('US/Eastern')
log.info("Rebalanced to target portfolio weights at %s" % str(exchange_time))
record(leverage = context.account.leverage)