A Junior Quant's Guide to Statistical Arbitrage [Code Included]
The hardest way to make an easy living...
Not too long ago, we began modeling and replicating some of the cash-cow strategies deployed by major quantitative hedge funds. So far, we’ve tightened a headlock on trend-following and momentum strategies, going as far as re-factoring them into a proprietary (and working) short vol strategy.
However, there’s one more, major cash cow we haven’t explored yet.
The big 3 strategies deployed by quant shops are trend following, momentum, and you guessed it… statistical arbitrage.
So, we’ll be venturing into these waters to find out exactly how it works, why it works, and exactly how much money it can make. As you’ll see shortly, successful stat arb is a lot more involved than just trading Pepsi and Coca-Cola.
Without spending another second, let’s get right into it.
WTH Is Stat Arb Anyway?
At its core, statistical arbitrage (stat arb) is a mean-reversion strategy that profits when one asset becomes over -or-under valued compared to another, similar asset. Now, even for companies that are nearly identical, there’ll always be differences in the prices you pay. Stat arb comes in when this divergence of prices becomes too far from the average. The strategy simply bets that over time, this divergence will decrease back to normal levels.
However, in order for the strategy to work, it is essential that we first make sure that the relationship between the assets are truly mean-reverting in the first place. To do this, we’ll go with the industry-standard Engle-Granger two-step method.
Assume we have 2 stocks we want to test, Stock A and Stock B.
First, we run a simple regression model that uses the price of Stock A to predict the price of Stock B. In theory, if the prices of these stocks truly moved together, then a regression model should be able to accurately predict the stock price with minimal errors.
Once the regression model is run, we then pull all of the errors the model made. For instance, if the model predicted stock B’s to be up 2%, but the real value was 1%, the error (the residual) is 1. When looking at the residuals, if we find that they tend to be around a certain mean with relatively stable variance, we can classify these residuals as stationary. A stationary time-series essentially means that data points tend to fluctuate right around the mean and tend to revert when they experience a divergence — exactly what we need.
As a stat arb trader, your profits come from trading stationary relationships when the divergence becomes out of whack and reverts back to the mean. If the time series is non-stationary (see second sub-graph), you take losses as you await a reversion that never comes.
We test for this stationarity by running an Augmented Dickey-Fuller (ADF) test which returns a p-value letting us know whether the series is stationary or not. Our desired p-value of less than 0.05 essentially translates to “there is a 5% chance that this relationship is spurious (random) and non mean-reverting”.
Once we’ve run our tests and found a suitable pair, we can then move onto making actual trades.
How The Money Is Made
To begin, let’s take 2 closely related stocks; Ametek, Inc (NYSE: AME) and Dover Corp (NYSE: DOV). Both companies provide industrial electronic equipment, have overlapping market share, and are similarly priced:
Visually, you can see that when one over/underperforms relative to the other, that spread tends to shrink back down in the future. Here’s a visual representation of that spread:
After running an ADF Test on these returns, we learn that the P-Value is ~0.01 which confirms that the mean-reverting nature of the spread is statistically significant. Remember, the spread doesn’t need to have an average of 0 (identical returns), it just needs to have an average, say 10%, that the series normally reverts to.
Okay, so we know that the pair is both fundamentally linked and more importantly, stationary, but how do we know when to make a trade?
One school of thought is to use a fixed value, say; “initiate a trade when the spread is above 20”. The problem with this is that we would choose that value based on look-ahead bias — we only know that 20 is the usual limit by looking directly at those past observations from the future. Additionally, if we wanted to apply this strategy to a different pair, that fixed value may not be applicable.
Alternatively, we can go with an approach that initiate trades when the spread increases n-deviations above a rolling window. For example, “if the spread increases by more than 1 standard deviation above the 200-day average, we initiate a trade.”
Here’s what that would look like:
In the above image, our trading signal would trigger when the spread goes above the orange line. When that happens, we would buy the underperforming stock and simultaneously short the overperforming stock. If and/or when that spread falls back beneath the orange line, we’d realize a profit.
In stat arb, we wouldn’t necessarily make trades when the spread is lower than average (betting on a future divergence), but we would make trades when that spread is higher than average (betting that the divergence will decrease).
Let’s see how that simple strategy performed:
Take a look at some of the recent trades:
In the period from January 2015 to April 2024, the strategy traded 58 times with a win rate of ~84% for a ~47% return (gross, not inclusive of transactions + borrowing costs).
Now, there are a few things about trading stat arb that we must address:
Like most high win-rate strategies, stat arb has a negative, left-tail skew — on average we make money, but every once in a while, we take outsized losses. As we discussed in our short volatility experiment, this isn’t an inherently negative characteristic, but it should be noted.
Despite each trade lasting from a few days to a few weeks, the returns for statistical arbitrage are relatively low due to its market-neutral nature. 47% isn’t exactly peanuts, but when you annualize it over the trading period, that amounts to a less impressive ~4.37% annual return.
While these returns are low compared to the traditional S&P 500 benchmark, the power comes from the lower volatility and use of leverage. As a fund, you get access to leverage sources like SPAN margin that determine how much leverage you get based on the volatility of the portfolio.
A market neutral statistical arbitrage trade generally has bond-like volatility, so although your fund might get 3x margin for a standard long equity trade, you can potentially access leverage ratios in excess of 10x:
The necessary short leg increases operational complexity. Going short a stock generally comes with a borrow fee that consists of a benchmark rate (e.g., 4% APR) plus/minus a modifier dependent on how difficult it is to locate shares for the stock. Now, because the trades last for just a few days to a few weeks, these fees are manageable (and model-able in advanced) even on some hard-to-borrow stocks.
However, if it takes an extended period (e.g., months) for the spread to revert, we can reach a point where the interest paid on the short leg overpowers any profit to be made.
So, that represents the big-picture idea and process behind a common form of stat arb. In practice, a fund deploying a stat arb strategy wouldn’t just make 1 or 2 trades like this, but rather hundreds at the same time. As we know from Modern Portfolio Theory, having multiple uncorrelated positions results in significantly lower volatility and with that lower volatility comes access to even greater amounts of leverage and thus greater amounts of profits.
With a sufficiently diverse portfolio of stat arb trades, the strategy can effectively become a money printer that rarely loses.
Now, although we’ve covered the gist of it, there’s no need to stop here.
Where Do We Go From Here?
Our example used a relatively obscure but co-integrated pair of stocks, AME and DOV. However, we can replicate the experiment with basic, more intuitive pairs. For instance, FedEx and UPS:
The p-value for this pair indicates a 27% chance that the relationship is not stationary, so although it it’s above our desired 5%, it still shows that profits can be made even if the stocks involved aren’t perfectly co-integrated (85% w/r).
Now, at this point, one can reasonably make the argument for adding an element of stat arb to our portfolio of strategies for extra stability and returns. However, while we’ve demonstrated possible success, we’ve also demonstrated that stat arb in equities is a hard way to make an easy living. We can reasonably make money, but after costs, our returns will essentially be close to the return of a risk-free treasury bond (assuming max leverage of x2 for retail traders).
However, each time we explore one of these strategies, it comes in handy later — so we’re not writing off stat arb yet. Already, the curiosity in us is beginning to ask: “If we have a way of determining if a time-series is truly mean-reverting, what other kinds of relationships follow the same pattern?”. Surely, there are relationships other than valuation(s) that tend to mean-revert, right?
Code
The repository for this contains code that will allow you to replicate all of the above outputs for any ticker pairing(s) of your choice. Just replace “FDX” and “UPS” with your desired ticker(s) and run the rest of the file.
https://github.com/quantgalore/statistical-arbitrage
Happy trading! 😄
by the way very interesting this stat arb path, looking forward to your insights
in my personal experience, cointegration on equities does not lead to any interesting results. Once I discovered that cointegration was useless, I tried to think about pairs that made sense from an economic point of view and instead of single stocks, I considered ETFs and futures. For instance, one can think of a lead-lag relationship between natural gas and ETF of gas supplier firms.
Doing so, the results were much more interesting.