Back to Community
Trade SPY on options expiration date

strategy came from this AQR paper...

https://www.aqr.com/library/aqr-publications/putwrite-versus-buywrite-yes-put-call-parity-holds-here-too

short SPY at the open on the 3rd friday of every month (expiration day for index options) and cover the short in the early afternoon (this algo covers at noon but it looks like the AQR paper says 1pm?). l used 3x leverage

I'm relatively new to python so I'm not 100% sure if it only trades on that 3rd Friday (also, if a holiday falls on the third friday then opex happens the day before... not sure how to code that). Returns slowed down in past 3 years but pretty decent returns overall for only having exposure to the market for 2.5 hours every month

Clone Algorithm
11
Loading...
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
"""
This is a template algorithm on Quantopian for you to adapt and fill in.
"""
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import AverageDollarVolume
from quantopian.pipeline.filters.morningstar import Q1500US
from datetime import datetime
def initialize(context):
    """
    Called once at the start of the algorithm.
    """   
    # Rebalance every day, 1 hour after market open.
    schedule_function(cover, date_rules.week_start(days_offset=4), time_rules.market_close(hours  = 4))

    schedule_function(sell_short, date_rules.week_start(days_offset=4), time_rules.market_open())
        

                     
def sell_short(context,data):
    if 14 < get_datetime().day  < 22:
        order_target_percent(sid(8554), -3.0)

                      
                      
def cover(context,data):
    if 14 < get_datetime().day  < 22:
    	order_target_percent(sid(8554), 0)



                  
There was a runtime error.