Applying a Sector Filter to a Mean-Reversion Strategy

In this article I will begin with testing a simple mean-reversion strategy on S&P500 stocks.

I will then apply a filter to the strategy which accounts for the short-term weakness of the sector which a stock belongs to.

I’m interested to discover whether the following mean-reversion strategy might be improved if the trader only buys oversold stocks if they also belong to an oversold sector.

Baseline Strategy Rules

  • If the 2 period Cumulative IBS value crosses below 10
  • Buy next day open.
  • Exit open position if close price is higher than previous day high price.

The following screenshot illustrates the entry and exit. Note that the bottom pane plots the value of the 2 period cumulative IBS.



Strategy Performance Metrics

To test the performance of the strategy I ran it against the historical constituent watch-list of S&P 500 stocks provided by NorgatePremium.

The maximum number of open positions allowed at a time is 10. If there are more signals than available open positions, signals will be ranked in order of the lowest IBS first.

Each new position receives an allocation of 10% of available equity.

I’m only interested in the performance of the strategy this year, so the sample period used is 01/01/2016 – 20/11/2016.

The results of the test are as below…

  • No. of trades = 207
  • % of Winners  = 65.22%
  • Average P/L% per trade = -0.02%
  • Average hold time = 4 days
  • Annualised return = -0.95%
  • Maximum drawdown = -9.65%
  • CAR/MDD = -0.10
  • Exposure = 33.74%

The equity curve and monthly breakdown of returns is as follows…


As you can see from the above graph and table, this particular strategy has been a loser during 2016.

The best and worst trade from the sample period are shown below…



Applying an Oversold Sector Filter

For the next test I applied a filter which would only permit a trade if on the day of the signal the sector which a stock belongs to has a 2 period RSI below 10.

For example, the above 26.63% loss in CHK could have been avoided because on the day of the signal (05/05/16) the energy sector index was not oversold…


The most recent signal found was $MNK on 18/11/2016.

However, because the healthcare sector index was not oversold on the day of the signal we would not have been permitted to buy the stock:



So to recap, the strategy rules are now as follows:

  • If the 2 period Cumulative IBS value crosses below 10
  • AND the index ticker of the sector that the stock belongs to has an RSI(2) value below 10.
  • Buy next day open.
  • Exit open position if close price is higher than previous day high price.

Strategy with Filter Performance Metrics

  • No. of trades = 87
  • % of Winners  = 78.16%
  • Average P/L% per trade = 0.87%
  • Average hold time = 4 days
  • Annualised return = 8.77%
  • Maximum drawdown = -7.00%
  • CAR/MDD = 1.25
  • Exposure = 11.47%

The equity curve and monthly breakdown of returns is as follows…


The above results show that the simple mean-reversion system presented in this article could have been improved during 2016 if only trading stocks belonging to an oversold sector.


  • Matt Haines

    Reply Reply November 26, 2016

    Hi Llewelyn! Hope you’re doing well. I was wondering if this oversold sector approach shows is better than looking at the overall market’s RSI. Have you compared?

    • Llewelyn James

      Reply Reply November 26, 2016

      Hi Matt,

      I did compare. The results of the test if using the SPX RSI(2) as the filter were as follows:

      No. of trades = 63
      % of Winners = 71.43%
      Average P/L% per trade = 0.55%
      Average hold time = 4 days
      Annualised return = 3.81%
      Maximum drawdown = -7.00%
      CAR/MDD = 0.48
      Exposure = 9.79%

      Kind regards,

      Llewelyn James


  • Larry Panos

    Reply Reply November 28, 2016

    Another great post Llewelyn. I think it leads to a follow-up study that if you pass the sector filter, then the equities within that sector could be ranked.

    In your mean reversion example, the most oversold equity (or several equities) would then be the candidates for Long entry. It would require the ability to identify which equities are in which sectors but I am confident that is within AmiBroker’s capability.

    Your thoughts?

    Thanks, keep up the great work.


    • Llewelyn James

      Reply Reply November 30, 2016

      Hi Larry,

      Thanks for reading the article. I’m Sorry for the late reply to your comment.

      I use Norgate Premium data (Alpha) and they very handily assign the appropriate GICSID() to each ticker. Their data also includes sector index tickers such as $SPXE for energy sector, $SPXD for consumer discretionary sector, and so on.

      The following Amibroker exploration should provide you with an idea of the logic that I used (Note that I have changed the rules in order to provide more signals for you to analyse)….

      Filter = 1;


      Energy = Foreign(“$SPXE”,”C”);
      ConsDisc = Foreign(“$SPXD”,”C”);


      SIRSIT = 50;


      EnergyOS = RSIa(Energy,2) < SIRSIT;
      ConsDiscOS = RSIa(ConsDisc,2) < SIRSIT;

      //Ticker Sector Oversold?//
      TSOS = IIf(InGics(“10”),EnergyOS,IIf(InGics(“25”),ConsDiscOS,0));

      FiveDayLowC = cross(Ref(LLV(L,5),-1),C);

      BuySetup = FiveDayLowC AND TSOS;


      Sector = WriteIf(InGICS(“10″),”Energy”,WriteIf(InGICS(“25″),”ConsDisc”,””));


      Addcolumn(IIF(InGICS(“10”),RSIA(Energy,2),IIf(InGics(“25″),RSIa(ConsDisc,2),0)),”SectorIndex RSI(2)”,1.2);




      I hope that helps.

      Kind regards,


Leave A Response

* Denotes Required Field