Sunday, February 6, 2011

Closing the gap, part 2

I felt the need to verify the calculations in the previous post, just to be sure no coding error was made, or at least not a serious one. To do this, I've rewritten the strategy using vector operations rather than 'for' loops and I'm happy to say, the result still stands. Sharpe is a little lower at 1.13, but the curves are quite similar.
To make this post a worthy follow up, I've also included the code:
dumbGaps.m , download_hist_yahoo_data.m

The following remarks are still very appropriate:

  • It is very hard to get a fill at the opening price.
  • Results are frictionless.
  • All this is just a basic concept

Your feedback is very much appreciated.


  1. Hi,
    The quick tests have been performed for the list
    The first impression from the proposed strategy is negative.
    Thanks for your code

  2. @Jeanbou: This rough idea needs some work before it can become profitable. In any case, only a test based on intraday data could give you an idea of the strategy performance. The reason is that the market moves extremely fast in the first seconds after the open and your order fill will most probably happen at a different price, usually in a 'wrong' direction. However, the basic idea of retracing the previous days close could lead to a profitable strategy.

  3. Hi,
    If you change spy.close on spy.adj_close in your m-code you will get the Sharpe 33.3429 .

  4. @Jeanbou: If you take a closer look at how the adjusted price is calculated you'll understand why this happens. Try plotting the close and adj_close next to each other, you'll notice that the dividends cause a permanent offset in the adjusted price.

  5. Good day, I try to understand your code.
    In the line 25
    idx = (gap>0) & (spy.low<prevClose);
    How one can know in advance during the day of trading that spy.low can/cannot go lower than prevClose while the stock exchange is still open?
    Correct me if I'm wrong, please?

  6. @Anonymous: the strategy rules are: enter in the opposite direction to the gap. For an up gap, exit at the level of previous close. If the previous close level is not reached, exit at days close. In this case the strategy wins. The expression looks for winning dates.

  7. I don't really understand why you said it's difficult to get a fill in the openings. In general, you can always do a pre-market trade just a few seconds before. Your execution price shouldn't be more than a few pennies from the official opening price.
    Also, did you exclude the ex-dividend dates? A gap down because of ex-dividend shouldn't be seen as a trade signal.