## R Code for Correlation Matrix and Heatmap

In response to a comment, here is the R code used to generate the data and the heat maps in the preceding post.  Lots of explanatory comments added.

## All the same market?

I once was a subscriber to Bob Prechter's Elliott Wave Theorist, though not for a couple of years. One of his themes at the time (and probably still) was "All the same market". He commented on the way in which more and more assets were moving with greater correlation than in the past.

I have been exploring portfolio-level correlation filters for my trading system. This is not for risk-control per se, it is aimed at reducing portfolio volatility so I can increase cumulative average growth rate (see Ralph Vince's "Leverage Space Trading Model", pp50-54).

Correlations change over time, so I wanted to take a look to see how much and how fast so I can get a handle on how frequently I need to check correlations. This is some interesting data I found ...

## Harmony Search - How Does It Work?

I presented the Harmony Search (HS) Algorithm, a genetic search optimization algorithm in a previous post. I now want to investigate in more depth how it behaves and why.

I will start by looking at an extremely simple hypothetical to get a sense of the mechanics of the algorithm. Then I will set up a test case using the same surface as in my previous post. I will set up a base case set of algorithm tuning parameters and see what happens as each parameter value is varied.

I want to arrive at some guidelines for choosing the main tuning parameters for the algorithm. Here they are:

## Harmony Search Algorithm

Even with only a few parameters controlling a trading system, the optimization search space gets big, quickly. How do I find an optimal set of parameters via back-testing when my poor laptop takes an hour for 500 back-tests?

I believe genetic optimization algorithms may provide a good solution. They work with discrete and continuous variables, they don't care how "rough" the optimization surface is and they are resistant to being trapped by local maxima. A nice feature is the fact that, aside from the max and min values for each parameter, the algorithm looks where it pleases - no data snooping on my part!

My proposal is that I use a genetic search algorithm implemented in R to create each generation of parameter sets in a file. Read the file into TradingBlox Builder which steps through the parameter sets, writing results out to a file which will be passed back to the genetic algorithm. Repeat...

The process of setting up TBB to do stepped parameter tests outside of the built-in method will be covered in a another post, here I will outline my first experience with a simple genetic algorithm: "The Harmony Search Algorithm"
Get widget