Skip to content

Instantly share code, notes, and snippets.

@vikrum
Last active January 18, 2017 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikrum/1b156c6b10c258677fe984345a6be906 to your computer and use it in GitHub Desktop.
Save vikrum/1b156c6b10c258677fe984345a6be906 to your computer and use it in GitHub Desktop.
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