-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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