Correlation Matrix:

Discussions about the testing and simulation of mechanical trading systems using historical data and other methods. Trading Blox Customers should post Trading Blox specific questions in the Customer Support forum.
Post Reply
aj1
Contributor
Contributor
Posts: 4
Joined: Thu Aug 31, 2006 12:27 pm

Correlation Matrix:

Post by aj1 » Wed Jul 21, 2010 5:49 am

Correlation Matrix:

So I have a portfolio of say 6 instruments. I am interested in looking at their correlation matrix. Can someone please tell me how I can produce a correlation matrix for these 6 instruments – thanks.

babelproofreader
Roundtable Knight
Roundtable Knight
Posts: 138
Joined: Wed Nov 10, 2004 4:36 pm

Post by babelproofreader » Wed Jul 21, 2010 7:58 am


sluggo
Roundtable Knight
Roundtable Knight
Posts: 2986
Joined: Fri Jun 11, 2004 2:50 pm

Post by sluggo » Wed Jul 21, 2010 8:06 am

Since I don't trade stocks, I haven't calculated a stock correlation matrix myself. However I do imagine that the correlations you want to compute, require some price data for each of the stocks. Probably you, the analyst, will need to choose
  • The start date (and start time, if using intraday data)
  • The end date (and end time, if using intraday data)
  • The granularity of the data: monthly? weekly? daily? 60 minute bars? 10 minute bars?
Then you would need to assemble this price data for all stocks in the portfolio to be analyzed, and make sure there are no missing data points (due to trading halts, data vendor glitches, different holidays at different exchanges, etc).

Then you, the analyst, will need to decide whether to calculate correlation upon PRICES, or upon PRICE RETURNS. It is a topic that sometimes inflames powerful emotions and/or strong opinions; here is a discussion of the topic on another quant site http://www.wilmott.com/messageview.cfm? ... adid=42932

Finally, for the correlation calculation itself, you could use the =CORREL() function built into Microsoft Excel (ref.1) (ref.2) (ref.3). Or if you decide to calculate it another way, you can double-check your results on a few examples or test cases. You could calculate them (your way) and also calculate them (with Excel), to reassure yourself that your computations aren't buggy.

aj1
Contributor
Contributor
Posts: 4
Joined: Thu Aug 31, 2006 12:27 pm

Post by aj1 » Wed Jul 21, 2010 10:39 am

Thank you sluggo & babelproofreader, for your comments & response.

I am perhaps guilty of not making my question clear. My question is:

I am putting some serious thoughts to portfolio composition whilst I develop a system to trade a collection of Futures instruments. The portfolio consists of Indices, currencies & metals – I wish to examine a correlation matrix in order to make some rational decisions about portfolio composition.

My question is – does TB provide a facility for displaying a correlation matrix for a given portfolio of instruments. TB is perhaps the most extensive tool in the market I am surprised this facility is not standard.

sluggo I will most likely also test out the correlation values in excel.
I am looking to pull together a diversified portfolio with low correlation to each other whilst maintaining the integrity of the system (i.e. positive mathematical expectation).

Any thoughts most graciously accepted.
Thanks.

LeviF
Roundtable Knight
Roundtable Knight
Posts: 1428
Joined: Mon Dec 22, 2003 12:24 pm
Location: Des Moines, IA
Contact:

Post by LeviF » Wed Jul 21, 2010 10:46 am

If you have access to the blox marketplace there is a block there that may do what you want.

Mats
Roundtable Knight
Roundtable Knight
Posts: 133
Joined: Thu Feb 28, 2008 2:59 am
Location: Stockholm

Use Blox Builder

Post by Mats » Tue Aug 03, 2010 8:23 am

There is a blox named "Update Dynamic Correlations, you can modify that blox and dump the correlation matrix.

Of course you must have the builder edition to do this modification and some programming skills.

/Mats

Tim Arnold
Site Admin
Site Admin
Posts: 8537
Joined: Tue Apr 06, 2004 1:41 pm
Location: Boston, MA
Contact:

Re: Correlation Matrix:

Post by Tim Arnold » Tue Aug 03, 2010 2:47 pm

aj1 wrote:Correlation Matrix:

So I have a portfolio of say 6 instruments. I am interested in looking at their correlation matrix. Can someone please tell me how I can produce a correlation matrix for these 6 instruments – thanks.
This block will print your current correlation matrix:

viewtopic.php?t=3214

You can set the correlations manually in the Futures Dictionary or you can dynamically compute the correlations using the Update Dynamic Correlations block. Note that the bars used to compute the correlation is important since what is correlated over the last 20 years is not necessarily correlated over the last 20 bars. And when things go really bad, everything becomes correlated.

dwitkin
Contributor
Contributor
Posts: 2
Joined: Fri Feb 18, 2011 2:56 pm

Correlations on CSI

Post by dwitkin » Mon Feb 21, 2011 5:11 pm

If your correlation issue isn't resolved, CSI has a correlation-only offering for $99 per year. Its not perfect -- gives 2, 5, 10, 15, and 20 year correlations, so you should question the relevance for short term systems. Also, their system doesn't allow you to indicate that you are short a given instrument, which changes the correlation of the overall portfolio. You can get a sense visually of how going short would impact the portfolio, but its imperfect.

I'm having some developers build a solution for me using VBA in Excel to allow shorter-term futures portfolio VaR calculations (based on Monte Carlo analysis), among other functions -- should be more accurate than correlations. Send me a message if you're interested and I can shoot you a note when it is completed.

Eventhorizon
Roundtable Knight
Roundtable Knight
Posts: 229
Joined: Thu Jul 08, 2010 2:36 pm
Location: Boulder, CO
Contact:

Post by Eventhorizon » Mon Feb 21, 2011 5:25 pm

It is trivial to use R to open your actual futures files and generate a complete correlation matrix and displayit as a heat map.

With a few lines of code you can do a Monte Carlo analysis to estimate VAR.

It is worth examining the covariance of the outliers to get a sense of what happens when the market gets into crisis mode - I am working on a post discussing how to do this.

dwitkin
Contributor
Contributor
Posts: 2
Joined: Fri Feb 18, 2011 2:56 pm

Using R for Monte Carlo / Correlation Analysis

Post by dwitkin » Tue Feb 22, 2011 7:44 am

I'll look forward to reading it... please let me know when it's ready / where it is posted.
Eventhorizon wrote:It is trivial to use R to open your actual futures files and generate a complete correlation matrix and displayit as a heat map.

With a few lines of code you can do a Monte Carlo analysis to estimate VAR.

It is worth examining the covariance of the outliers to get a sense of what happens when the market gets into crisis mode - I am working on a post discussing how to do this.

kianti
Roundtable Knight
Roundtable Knight
Posts: 335
Joined: Fri May 02, 2003 6:10 am
Location: Florence - Italy

Post by kianti » Tue Feb 22, 2011 8:30 am

Excel could do the job as well.
Attachments
corr1.jpg
corr1.jpg (372.49 KiB) Viewed 4246 times
corr2.jpg
corr2.jpg (430.76 KiB) Viewed 4246 times

bobsyd
Roundtable Knight
Roundtable Knight
Posts: 376
Joined: Wed Nov 05, 2008 2:49 pm

Post by bobsyd » Tue Feb 22, 2011 3:11 pm

Or, if you can use Marketplace blox, you might want to try Print_Correlations_Date rev3.tbx in the Correlation & Risk Limiter Blox thread.

Post Reply