A not so Random Walk: A Statistical Arbitrage technique

Sometimes one may come across, by simply eye-balling, a pair of stocks that perhaps move in tandem; almost rhythmically. The operative word then would be to look for cointegration and effectively Error Correction Models (ECM). One must employ cointegration rather than simply using correlation because standard regression analysis fails when dealing with non-stationary variables (~I(d)), leading to spurious regression that suggest relationships even when there are none. For example, if one regresses two independent random walks (with or without stochastic/deterministic drift) against each other, and tests for a linear relationship, a large percentage of the time, you are bound to find high R-squared values and low p-values when using standard OLS statistics, even though there’s absolutely no relationship between the two random walks.

Though its application has been prevalent in the equity arena, I decided to test this relationship on a probably cointegrated currency pair. Taking up from my previous post on the Kuwaiti Dinar(KWD) basket composition, I decided to assess if indeed the dominant currency is cointegrated with the KWD and could hypothetically help me generate trade signals.

My formation and test periods were 12 and 2 months respectively; with 15 minute tick data. Additionally, it is a bare bones test i.e. without taking into account transaction costs.

I. Determine a Hedge Ratio

Both USD and KWD are individually non-stationary time series that become stationary when differenced (these are called integrated of order one series, or I(1) series) such that some linear combination of KWD and USD is stationary (~I(0)), thus we say they are cointegrated. In other words, while neither USD nor KWD alone hovers around a constant value, some combination of them does.

Integration forms the basis of the pairs trading strategy. Our two series have a co-integrating relationship KWD – 3.548634 USD = ε, where ε is a stationary series of zero mean. This suggests the following trading strategy: if KWD – 3.548634 USD > d, for some positive threshold d, then we should sell KWD and buy USD (since we expect KWD to decrease in price and USD to increase), and similarly, if KWD – 3.548634 USD < -d, then we should buy KWD and sell USD.

Spread = KWD – 3.548634 USD
d = +/- 2SD of Spread or if taking Z score which is the (Spread- Mean of Spread))/(SD of Spread) then d =+/- 2

To detect co-integration I employ the Engle-Granger test, which works roughly as follows:

• Check that both KWD and USD are I(1), however a combination of them yields I(0)
• Estimate the cointegrating relationship KWD = αUSD+ε
• Check that the cointegrating residual ε is stationary (use unit-root test viz. the Augmented Dicky Fuller test)
• Find the hedge ratio i.e. a portfolio of both the series such that one buys the portfolio when it is less than d and sells/shorts the portfolio when d is high.

So, just to summarize a bit, cointegration is an equilibrium relationship between time series that individually aren’t in equilibrium (you can kind of contrast this with (Pearson) correlation, which describes a linear relationship), and it’s useful because it allows us to incorporate both short-term dynamics (deviations from equilibrium) and long-run expectations (corrections to equilibrium).

As seen below, the first two diagrams are a snapshot of the performance of the hedge ratio methodology over a test period of 2 months that we can see in the last diagram. When the spread breaks the +/- 2SD barriers, we know it’s time to generate a trade signal.

II. Cumulative Return (Gatev’s) methodology

Find out the cumulative return (cr) for the both the series. Then calculate the spread:
Spread = cr of KWD – cr USD

d = +/- 2SD (spread of the formation period) or if taking Z score which is the (spread- mean(spread of the formation period))/SD(spread of the formation period) then d =+/- 2

As seen below, the first two diagrams are a snapshot of the performance of the Gatev spread methodology over a test period of 2 months that we can see in the last diagram. When the spread breaks the +/- 2SD barriers, we know it’s time to generate a trade signal.

Suggested Software: Matlab, R Language, EVIEWS

R code

> library(“timeDate”)
> library(“zoo”)
> usdr <-as.data.frame(usd)
> kwdr <-as.data.frame(kwd)

> comb <- merge(usd, kwd, all=FALSE)
> c <- as.data.frame(comb)
> cat(“Range is”,format(start(comb)), “to”, format(end(comb)), “\n”)

Range is 1 to 34050

> library(“lmtest”)
> m <- lm(kwd ~ usd + 0, data=c)
> beta <- coef(m)[1]
> cat(“Assume hedge ratio is”, beta, “\n”)

Assume hedge ratio is 3.548634 (Long 1 KWD and Short 3.548634 USD)

> sprd <- c\$kwd – beta*c\$usd
> library(“tseries”)

> ht <- adf.test(sprd, alternative=”stationary”, k=0)
In adf.test(sprd, alternative = “stationary”, k = 0) : p-value smaller than printed p-value

> cat (“ADF p-value is”, ht\$p.value, “\n”)
ADF p-value is 0.01

> if (ht\$p.value< 0.05) {cat(“The spread is likely mean-reverting\n”)} else{cat(“The spread is not mean-reverting.\n”)}
The spread is likely mean-reverting

For EVIEWS/MATLAB code, drop me an email.

References

Gatev, E., Goetzmann, W.N., Rouwenhorst, K.G., 2006. Pairs Trading: Performance of a Relative Value Arbitrage Rule. The Review of Financial Studies.

Brooks, C., 2008. Introductory Econometrics for Finance. Cambridge University Press

© 2013 Tanya Rawat. By posting content to and from this blog, you agree to transfer copyright to blog owner.

© Melu Saasta Photography

18 responses on “A not so Random Walk: A Statistical Arbitrage technique”

1. excellent observation, its true that whenever we find any “Lead-lag Relationship” between two data series i.e. series is cointegrated , we must avoid any linear assessment like correlation which in itself is a mere indicatior of a relationship and not caausation.
going through your codes ,you have taken care of all the statistical tests,but i feel is it possible that we can account for clustering (as cleary evident by the fig# 2). a GARCH analysis perhaps will also account for non-linearity ?

• GARCH estimates are based on a time-varying correlation model; that has been deemed imperfect by us.

2. Good try! Just two questions.
First, what’s your estimate sample and test sample? Was the hedge ratio rollovered?
Second, what’ s your exit signal?

• Test sample will vary depending on the frequency of your data. I used 15 minute tick data on a test sample of 12 months. If I understand your question correctly, no it wasn’t rolled over as the hedge ratio was meant to be calculated for the entire sample period and then applied to an out-of-sample period.

Exit signals will depend on the robustness of your model, your personal P&L targets and obviously how close the spread reverts back to the mean. Generally a good exit signal would be when the spread is within absolute value of 1 SD of its mean.

3. Thanks for your reply. I mean, in practice, is there any method to moniter sample fracture so that the historical estimated hedge ratio can be applied to the new generated data? What is the period character for each transaction?

• Yes, if I remember correctly, there do exist such methods. This article however, was meant to highlight the existence of stat arb in a currency pair. Indeed, I shall look forward to your analysis into the finer details.

4. It is appropriate time to make some plans for the future and it is time to be happy. I have read this post and if I could I want to suggest you some interesting things or tips. Perhaps you could write next articles referring to this article. I want to read more things about it!

• Hey, sure thing. I am more than willing to take suggestions for future articles. Thank you for your input.

5. Hello just wanted to give you a brief heads up and let you know a few of the pictures aren’t loading properly. I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers and both show the same outcome.

6. Thanks for the sensible critique. Me & my neighbor were just preparing to do some research about this. We got a grab a book from our local library but I think I learned more from this post. I am very glad to see such excellent info being shared freely out there.

7. I have to convey my gratitude for your generosity for those who have the need for help with the idea. Your very own commitment to passing the message throughout had become extraordinarily good and have continuously allowed guys and women much like me to achieve their objectives. Your entire important information can mean this much a person like me and somewhat more to my office workers. Thank you; from each one of us.

• Hey Wenyi,

Thank you for the kinds words. I have emailed it across to you. Have fun!

8. I do accept as true with all the ideas you’ve presented in your post. They are really convincing and will definitely work. Nonetheless, the posts are too brief for newbies. May you please prolong them a bit from next time? Thank you for the post.

9. You really make it seem so easy with your presentation but I find this matter to be really something that I think I would never understand. It seems too complex and extremely broad for me. I’m looking forward for your next post, I’ll try to get the hang of it!

10. I simply want to say I am just very new to blogging and absolutely enjoyed you’re web page. Almost certainly I’m planning to bookmark your site . You surely come with exceptional articles and reviews. Regards for sharing with us your blog.

11. hi. i see you determine the hedge ratio using regression, right? problem is how to you decide the best time horizon? i am doing something similar, it looks quite sensitive to the parameters.
thx

• Hello, Charles. Yes, I did employ regression. The times scales will vary depending on your data set. I suggest using the ‘bottom-up’ approach whereby you start with the intra-day data for a second, eventually moving on to a minute, an hour and so forth. Then examine them in tandem to determine which data set fit your trading goals the best taking into consideration brokerage costs.