@Simon... I took a stab.. on it and encounter.. some Errors... KeyError: 6 wat am I.. missing...it stil wont work on a weekday... instead of year month. heres the code...
def initialize(context):
context.spy = sid(8554)
context.tlt = sid(23921)
context.week_ports = { 1: {context.tlt: 1.0, context.tlt: 0.0},
2: {context.spy: 1.0, context.spy: 0.0},
3: {context.tlt: 1.0, context.tlt: 0.0},
4: {context.spy: 1.0, context.spy: 0.0},
5: {context.tlt: 1.0, context.tlt: 0.0},
}
schedule_function(func=do_allocation,
date_rule=date_rules.week_start(),
time_rule=time_rules.market_close(),
half_days=False
)
def handle_data(context, data):
record(spy=context.portfolio.positions[context.spy].amount)
record(tlt=context.portfolio.positions[context.tlt].amount)
def do_allocation(context, data):
week = get_datetime().week
port = context.week_ports[week]
for (sid, weight) in port.iteritems():
if sid in data:
order_target_percent(sid, weight)