Intermarket Whac-A-Mole

[This article was first published on Milk Trader, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Every trader that looks at more than one market throughout the day will recognize that there is a certain symmetrical relationship between certain markets at certain times. The confounding thing about these intermarket relationships is that they are fleeting. Sometimes the Euro dances with the S&P 500, and sometimes Gold butts in. Standing in line to get their chance are Crude, US Bonds or the Yen. Statisticians dub this phenomenon correlation. And they’ve even gone to the trouble of representing it as a mathematical formula. Lucky for us that we don’t need to derive it every time we wish to see if there is something there or if it’s just our imagination.

Thinking it may be helpful to get a graphical representation about intermarket relationships, I decided to pre-process some data in Excel, save the file as a csv, and then run in through R to draw up some graphs. The basic idea is to match up the closing prices of two markets, calculate their Pearson correlation based on a 30-day lookback, and then plot the number. I did this first with two markets that I know must be correlated, the SPX and OEX. They must be correlated because the SPX (top 500 US companies) is essentially the OEX (top 100 US companies) plus 400. First I find at what date we can match these two datasets up with and I came up with 1984. Then I utilized the =Pearson (array1,array2) Excel function to create a vector that holds this data. Then it’s a simple plotting exercise in R after reading in the file. The R code is so simple, here it is:

################### Call packages

#### non required, just use the base

################### Read Data

SPX <- read.csv ("C:/R/TESTDATA/SPX30Y.csv", header = TRUE, sep =",")

tail (SPX)

################## Define Vectors

COR <- SPX$X

################# Plot the sucker, with nice titles of course

hist(COR, main =”SPX/US Bond Correlation from 1977 to 2010″, xlab=”Pearson Correlation (30) at the End of Day”)



Some quick notes. I print the tail of the file with the tail (SPX) command because I did not label the correlation vector in the Excel file, so I need to know what R decided to call it so I could create an independent variable for manipulation purposes. In any case, behold below what we find.


Good, this is what we expected. The correlation is high most days during the years of data we examined. Now let’s turn our attention to the correlation between the S&P 500 and the famed OEX put/call ratio. This is a metric that has been touted in the past as having some predictive value, so let’s take a look-see.

 

 The daily result hovers around the zero line, which means that they are as un-correlated as you can get. I thought this graph would be much more concentrated in the middle than it actually is. The tails (less amount of days) are somewhat positively and negatively correlated, but mostly uncorrelated overall. 

Now let’s take a peek at the intermarket correlation between the S&P 500 and the US 30-year Bond yield. Before you look, take a guess as to how you think this should look.

Space inserted for contemplation.

Another space to prevent inadvertent data snooping.


Okay, here it is:





The relationship leans towards being negatively correlated, but you can see that there is a fair amount of positively correlated days, enough to wipe out an account that bets on this relationship to place trades.

The field of intermarket relationships is intriguing, but it clearly is not something that can be relied upon for primary trading signals. This is a first look, of course, and it may prove interesting to conduct a cross correlation study to see if correlation improves by shifting the days in the time series. I’ve found some C++ code that does this, but I’m still searching for an R package that will be able to do it. I’ll find it later, but for now I’m putting my attention back to the matter of rationalizing to myself why I still need to be short the Euro/Dollar pair. 




To leave a comment for the author, please follow the link and comment on their blog: Milk Trader.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)