Strategy Diversification in R

In my last post, I looked at the correlations of different instruments. Understanding the correlations of instruments is important when developing a strategy and selecting the assets to include. In theory, selecting highly correlated instruments for a portfolio or strategy will be more volatile than a portfolio or strategy with several uncorrelated instruments. This sounds great in theory, but can be difficult to apply in real life. Why? – correlations change over time and just diversifying among instruments is not enough. Just take a look at the graph below from my post on correlations as well as Systematic Investor’s analysis of Cross Sectional Correlation.

Correlations are changing over time and markets are becoming more correlated in recent times. As the correlations between markets and instruments increases, the impact of diversification decreases. You may be asking yourself (like I am), “If I can’t diversify among assets, what else can I do to diversify?” My answer to this is to diversify in as many ways as you can – trade multiple strategies, multiple timeframes, multiple risk levels, multiple markets, multiple instruments, etc.

To demonstrate this, I will take two strategies:

  • Strategy1 – longer term strategy
  • Strategy2 – shorter term strategy

(Yes… I realize that I am being very vague about the strategies at this point, more on the strategy details later in the post.)

Here are the outcomes of each strategy using quantstrat to backtest.

Strategy 1

6.599 -36.358 0.182


Strategy 2

2.637 -9.637 0.274


How does each strategy correlate to eachother?


The chart above shows that Strategy 1 is not very strongly correlated with Strategy 2.

Now for more information on the strategies.

  • Strategy 1 and Strategy 2 both trade the same universe of instruments¬†(“XLY”, “XLP”, “XLE”, “XLF”, “XLV”, “XLI”, “XLK”, “XLB”, “XLU”)
  • Strategy 1 is a 52 week moving average strategy and trades 1000 contracts per trade*
  • Strategy 2 is a RSI(2) on weekly data strategy and trades 100 contracts per trade*
  • *Note on position sizing. Normally I would do a volatility based position sizing, but the RSI(2) strategy took about 20 minutes to complete the test because of the looping in the order sizing function. So for brevity and testing purposes I used fixed contract sizes as stated above for each strategy.

Are you surprised that two strategies that trade the exact same set of instruments would not have a higher correlation? I was!

This example reinforces how diversification can be achieved in more ways than one.

In follow-up posts, I will share the R code for the strategies and show how I plotted the correlations.

Hello world!

Welcome to the first post of the RB Research blog. Inthis blog, I will focus on quantitative research, trading strategy ideas, and backtesting; primarily in the Foreign Exchange (FX) and equity markets. In the past, I had done nearly all of my testing and analysis in microsoft excel, but over the past 6 months I have been “bitten” by the programming bug. My language of choice is the R language because of the vast amount of contributed packages and tremendous support community. It has been frustrating, insightful, and rewarding all at the same time. My initial inspiration for moving my testing to R from excel, was a series of posts over at FOSS Trading. If you haven’t checked out his blog, I highly recommend it! Other blogs that have been influential are:

  • Timely Portfolio for his excellent posts and sharing his R code
  • World Beta for a plethora of research ideas and articles
  • and many others

As stated earlier, the themes of my post will be research driven using the R programming language and maybe even some I consider myself a beginner programmer and hope that through this blog my programming skills will continue to develop by sharing my work with others.

Stay tuned…