Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
prior close to next open comparison

Here's an algo that I originally posted on https://www.quantopian.com/posts/interpretation-of-difference-between-minutely-open-price-and-prior-close-price. I thought I'd re-post as a separate thread in case anyone is interested in fiddling with it. The basic outline is:

  1. Trade intraday only; close open positions before the end of the trading day.
  2. On a minute-by-minute basis for SPY, compute the difference between the prior closing price and the immediately following open price (delta_oc).
  3. Accumulate the differences over 390 minutely bars, and then compute the mean (delta_oc_mean) and standard deviation (delta_oc_std).
  4. Apply trading rules:
if delta_oc > delta_oc_mean + 3*delta_oc_std:  
    order_target_percent(context.spy, -1) # short  
elif delta_oc < delta_oc_mean - 3*delta_oc_std:  
    order_target_percent(context.spy, 1) # long  

Notes:

  1. No commissions (set_commission(commission.PerTrade(cost=0)).
  2. Custom slippage model with settings that may idealize the algo performance (but not make it ridiculous).
  3. The code could be re-factored, making better use of history, Pandas, etc., so if you're needing to learn, give it a shot!
  4. It takes awhile to run, so if you make adjustments to the code, you might try a shorter timeframe first.
  5. It's probably not at all realistic, but maybe it'll spawn some insights.

Any idea if the margin is correct going short with order_target_percent(context.spy, -1)? Or would this exceed typical margin rules?