# correlation for portfolio of stocks

I have a portfolio of stocks and all I want to do is to make sure that I'm not trading one big position, so I would like to monitor some type of metric that gives me a rough idea of what the overall correlation in the portfolio is and how it is changing day to day thru movement in prices. I want to get it down to one number a day, but I'm not sure how to do it. let's say I have three stocks a,b,c. Do I just take the correlation between a and b, b and c, a and c, then average it? What is the correct way to do it?

Would it be possible to give a simple example? Let's say a,b,c stocks and the weights are 20%,30%,50% respectively. The 3 day daily returns are

day  a  b  c
1   0% 2% 2%
2   1% -1% 0%
3   2% 1% 0%


How do I apply your formula?

And also just curious is there a package in python that does these calculation for you? I imagine I'm asking a pretty standard question, one would think it is a pre-package solution in a library somewhere. Would pandas have something?

• A very warm welcome to Quant.SE and thank you for your question :-) – vonjd Feb 26 '15 at 7:57
• ...edited my answer according to your additional request of how to do it in python - hope this helps :-) – vonjd Feb 26 '15 at 8:24

I think you might be looking for the portfolio return variance: $$\sigma_p^2 = \sum_i \sum_j w_i w_j \sigma_i \sigma_j \rho_{ij},$$ where $\rho_{ij}$ is the Pearson product-moment correlation coefficient between the returns on assets $i$ and $j$ and $\rho_{ij} = 1$ for $i=j$.

In your case you could either weigh the assets equally or according to the real weights in your portfolio and recalculate that metric daily.

Generally, the lower the correlation between securities in your portfolio, the lower the portfolio variance - which is what you intend to measure.

Edit
Since I do not work with python I did a quick google-search and found the following relevant question/answer how to actually do the calculation in python: https://stackoverflow.com/questions/7409108/portfolio-variance-of-a-portfolio-of-n-assets-in-python

• haha, was gonna make the same edit! – SRKX Feb 26 '15 at 8:07

In their paper on their S&P 500 Implied Correlation Index the CBOE has defined a measure for the market-capitalization weighted average correlation of the S&P 500 index which could be applied to portfolios in general. The equation

$$\rho_{av} = \frac{\sigma^2 - \sum_{i=1}^N w_i^2\sigma_i^2}{2 \sum_{i=1}^N \sum_{j>i}^N w_i w_j \sigma_i \sigma_j}$$

has also been discussed in this post on this forum. Like the correlation between two-assets, this correlation approaches one when all assets become correlated (e.g. market crashes) and decreases and can even become negative as assets become less correlated. I've found computing it on a weekly basis using the past month's daily data can be useful for monitoring relatively short-term changes in long-only portfolio correlation.

I don't know of a published implementation of this equation but it's straightforward to code it in R.

• Thanks for the response. I will take a look. Might come back to you with some more questions. – jason Feb 27 '15 at 2:21