Back to Community
Russell 2000 - Statistical Arbitrage with Hedged Stock Pairs - Mean Reversion Strategy

Please take a look at my StatArb strategy algo and feel free to modify it and improve it. Some might say sharing is caring and I think the same.

Regardless of the liquidity problems that it may incounter, what do you think about it? It's a personal strategy and, because I spent only 2 days playing with the algo's conditions and constants, it certainly needs more than one brain to make it work beautifully.

Search for 'A' type & 'B' type stocks that gained 20% in the past five days. An 'A' type stock has a last month bearish trend and a 'B' type stock has a bullish trend for the last month. Short A, long B with a hedge ratio close to 1 and voilĂ , you have a StatArb Reversion strategy. Expect the closing of the A versus B gap to make money.
But something is missing: feel free to play with the different parameters and check for new patterns to add in the position opening/closing conditions and share the new backtests.

Clone Algorithm
Backtest from to with initial capital
Total Returns
Max Drawdown
Benchmark Returns
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
# Backtest ID: 55b09b0a47f0c50c61e17cc3
There was a runtime error.
12 responses

Good starting point.
First thing that popped into my mind was to sort stocks into sectors and try and match stocks within each sector.
Will have a bit of a play and see how it goes.

Thanks for the reply, Max! But, because it's about quantitative trading, I prefer technical analysis to fundamental. Patterns in the price data. No disrespect. Cheers!

It's not totally unreasonable to try and neutralize sector-specific risk factors. It would help isolate the source of your returns, whether you are making bets on idiosyncratic stock time-series momentum, or broader sector momentum, in which case one might more efficiently implement it using sector ETFs.

I agree with Simon. Using the sector ETFs wouldnt be a bad test

Check logs and you will find a pattern
Buying ABEO at 2.77 and then selling for 7.60
Buying ADXS at 7 then selling for 17

Need to fix stock list and remove bias

OK, thank you all for the feedback. I will try to upgrade it with your suggestions.

Could you explain this line of code ? If I get it right you are checking if the price change for past 5 days was more than +20% and for the last 30 days was less than -3% ?

 barCnt2 = 30  
  dif2 = 0.03  
  barCnt1 = 5  
  dif1 = 0.2  
  if get_datetime().hour == 17 and get_datetime().minute == 40:  
       positions = context.portfolio.positions  
       for stock in context.RUS_1:  
         s1 = stock  
         if not get_open_orders(s1):  
           if s1 not in positions:  
             A_history_close = history(bar_count=barCnt2,frequency='1d', field='price')  
             close_A_past2 = A_history_close[stock][-barCnt2]  
             close_A_past1 = A_history_close[stock][-barCnt1]  
             close_A_1 = A_history_close[stock][-1]  
             A_move_2 = close_A_past2 / close_A_1 - 1  
             A_move_1 = close_A_past1 / close_A_1 - 1  
             if A_move_1 > dif1:  
               if A_move_2 < -dif2:

Does anyone know of a place to scrape a historical russell 2000 list?

@ Yatharth
Exactly. If it was a positive percentual change ( A_move_2 > 0% ) in the last 30 workdays, it means the trend for the stock is not bearish, but bullish for the last 30 days. Yes, it seems a little bit ticky, but practically the algo checks if the current price of the stock is not higher than 30 days ago, even with the 20%+ rise in price.

Dear Mr. Yolo,

check out this post by James:

The Russell indices have relatively clear definitions so you can build off of James' post there to create your own simulation of the 2000 using fundamentals.


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

I guess this would be only possible with extreme moves in volatile stocks. If a stocks was down say 7-8% in past 1 month , 20% positive move in last 5 days would definitely cover it up. Only a large move in past one month such as 15-16% down and then 20% up in past 5 days would satisfy this condition.

@Max - Russell 2000 historical prices are available at^RUT as an HTML page with a table containing dates and open, high, low, and close levels, volumes, and adjusted close levels. You can extract the data with BeautifulSoup.

At the bottom of the page, there is a link containing a Web query for the same data in CSV format. When you reverse-engineer the query format, you should be able to load that data for any given date range via Fetcher.

Frankly, I think index levels are such a basic necessity that Quantopian should provide them as non-tradable Securities.