Skip to content

Instantly share code, notes, and snippets.

@vikrum vikrum/401k

Last active Jan 18, 2017
What would you like to do?
Quantopian 401K simplified SPY model; front loaded (4 pay cycles) VS throughout year (26 pay cycles) of $27k
def initialize(context):
# Reference to SPY
context.spy = sid(8554)
schedule_function(buySpread, date_rules.week_start(), time_rules.market_open())
def buyFront(context, data):
weekno = get_datetime('US/Eastern').isocalendar()[1]
# Invest in first 4 pay cycles
if (weekno % 2 == 0) and (weekno <=8):
if data.can_trade(context.spy):
order_value(context.spy, 6750) # $6750/pay
def buySpread(context, data):
weekno = get_datetime('US/Eastern').isocalendar()[1]
# Invest throughout the year
if (weekno % 2 == 0) and (weekno <= 52):
if data.can_trade(context.spy):
order_value(context.spy, 1038.461538) # $1038/pay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.