Vous êtes sur la page 1sur 10

Calculating Covariance For Stocks

November 15 2011| Filed Under Financial Theory, Portfolio Management, Statistics There are many elements of mathematics and statistics used in evaluating stocks. Covariancecalculations can give an investor insight into how two stocks might move together in the future. Looking at historical prices, we can determine if the prices tend to move with each other, or opposite each other. This allows you to predict the potential price movement of a two stock portfolio. You might even be able to select stocks that complement each other, which can reduce the overall risk, and increase the overall potential return. In introductory finance courses, we are taught to calculate the standard deviation of the portfolio as a measure of risk, but part of this calculation is the covariance of these two, or more, stocks. So, before going into portfolio selections, understanding covariance is very important.

TUTORIAL: Financial Concepts: The Optimal Portfolio

What Is Covariance? Covariance is a measure of how two variables move together. It measures if the two move in the same direction (a positive covariance) or in opposite directions (a negative covariance). In this article, the variables will usually be stock prices, but it can be anything. In the stock market, there is a strong emphasis placed on reducing the amount of risk taken on for the same amount of return. When constructing a portfolio, an analyst will select stocks that will work well together. This usually means that these stocks do not move in the same direction. Covariance can tell how the stocks move together, but to determine the strength of the relationship, we need to look at the correlation. (To Learn more, see Tales From The Trenches: Perfectly Negative Profitability.)

Calculating Covariance The calculation for covariance of a stock starts with finding a list of previous prices. This is

labeled as "historical prices" on most quote pages. Typically, the closing price for each day is used to find the return from one day to the next. Do this for both stocks, and build a list to begin the calculations. For example:

Day 1 2 3 4 5

ABC Returns (%) 1.1 1.7 2.1 1.4 0.2

XYZ Returns (%) 3 4.2 4.9 4.1 2.5

Table 1: Daily returns for two stocks using the closing prices
From here, we need to calculate the average return for each stock: For ABC it would be (1.1 + 1.7 + 2.1 + 1.4 + 0.2) / 5 = 1.30 For XYZ it would be (3 + 4.2 + 4.9 + 4.1 + 2.5) / 5 = 3.74 Now, it is a matter of taking the differences between ABC's return and ABC's average return, and multiplying it by the difference between XYZ's return and XYZ's average return. The last step is to divide the result by the sample size and subtract one. If it was the entire population, then you could just divide by the population size. Represented by this equation:

For example: = [(1.1 - 1.30) x (3 - 3.74)] + [(1.7 - 1.30) x (4.2 - 3.74)] + = [0.148] + [0.184] + [0.928] + [0.036] + [1.364]

= 2.66 / (5 - 1) = 0.665 In this situation, we are using a sample, so we divide by the sample size (five) minus one. You can see that the covariance between the two stock returns is 0.665, which means that they move in the same direction. When ABC had a high return, XYZ also had a high return. Using Microsoft Excel In Excel, you can easily find the covariance by using one the following functions:

= COVARIANCE.S() for a sample or = COVARIANCE.P() for a population You will need to set up the two lists of returns in vertical columns, just like in Table 1. Then, when prompted, select each column. In Excel, each list is called an "array," and there should be two arrays inside the brackets, separated by a comma. (To learn more, see Improve Your Investing With Excel.) Meaning In the example, there is a positive covariance so the two stocks tend to move together. When one has a high return, the other tends to have a high return as well. If the result was negative, then the two stocks would tend to have opposite returns; when one had a positive return, the other would have a negative return. Uses of Covariance Finding that two stocks have a high or low covariance might not be a useful metric on its own, but the covariance can be used to calculate the correlation. The correlation will give a measurement between -1 and 1, and adds a strength value on how the stocks move together. If the correlation is 1, they move perfectly together, and if the correlation is -1, the stocks move perfectly in opposite directions. If the correlation is 0, then the two stocks move in random directions from each other.(To know more about correlation and portfolio management, check out: Diversification: Protecting Portfolios From Mass Destruction .)

The covariance can also be used to find the standard deviation of a multi-stock portfolio. The standard deviation is the accepted calculation for risk, and is extremely important when selecting stocks. Typically, you would want to select stocks that move in opposite directions. If the chosen stocks work well together, then the risk will be lower given the same amount or potential return. Conclusion Covariance is a common statistical calculation which can show how two stocks tend to move together. We can only use historical returns so there will never be complete certainty about the future. Also, it should not be used on its own. Instead, it can be used in other, more important, calculations such as correlation, or standard deviation. (For additional reading, check out:

A Pairs Trading Example


by LU MIL O G on JULY 26, 2008

Note: Please read the disclaimer. The author is not providing professional investing advice.

While waiting for results from the CFA exam to come in, I thought Id cover an example of a trading technique Ive recently begun test driving, pairs trading. Pairs trading was something I thought Id invented! Alas like many of my so-called brilliant flashes of insight, a little googling revealed that not only had others come up with it decades earlier, but their techniques were more elegant and robust than my first stab.

The basic idea behind pairs trading is this: 1. Find a pair of stocks (or ETFs) whose prices tend to move together. 2. If the price movements are indeed highly correlated, then on most days the price per share of Stock A divided by the price per share of Stock B should come out to be about the same number, within a small range. 3. But occasionally, you might notice a significant divergence from this average ratio. If you do, enter a pairs trade. This will involve simultaneously shorting one of the stocks while taking a long position in the other. 4. At some time in the future when the price ratio (hopefully) reverts to the mean, exit the pair trade, wire that (almost) riskless profit to your checking account, and take your wife out to a nice dinner. Now anyone familiar with the basic workings of the stock market knows that you can make money in either an up or down market, by using both long and short positions. But the catch is, you have to know which way the market is headingin order to know which to use. Easier said that done, even for the pros. But with pairs trading, you are performing trades that are (theoretically, at least)market neutral. As long as the pair ratio reverts to the mean, you make money regardless of whether you re-arrive at the mean by the short decreasing in price, the long increasing in price, or both. You dont have to know or even care which way the market is heading. A second benefit is that pair trade positions can be viewed as a nice additional asset class for ones portfolio, since they

should be relatively uncorrelated with your traditional asset classes consisting of long positions in various domestic and international indexes. So lets illustrate pair trading by an example. Its January 1, 2007 and Im thinking of trying out some pair trading in the new year. Now I could code up a script to perform correlations between the historical price movements of hundreds of stocks in order to find those that move together, but I have a simpler idea. I have an inkling that Lowes (LOW) and Home Depot (HD) might be highly correlated. To me at least, they are roughly equivalent businesses, and which one I go to depends solely on which one is closer when I need something. Lets examine their closing price-per-share data from the previous year

They definitely do seem to move together. And I could compute a correlation on the price movements to confirm what I see visually. But perhaps a more important question is

not is the relationship between LOW and HD highly correlated, but rather is it mean-reverting. Because my making a profit depends upon this. So I now plot the price of LOW divided by the price of HD, what well call the LOW/HD pair ratio

and this indeed seems to be what I was looking for a price ratio (blue curve) that appears to oscillate around a mean (purple line). And Ive also added the 1-, 2-, and 3-standard deviation lines just to get a feel for how far away from the mean the oscillations might go. So, we appear to know the habits and patterns of this animal. Time to set a trap and lie in wait But this creature is dangerous and could eat us alive, so we have to be careful. We see that in 2006 the pair ratio often makes excursions 1 or 2 standard deviations above or below the mean. We could spring the trap then but we might end up

making lots of trades for tiny profits, and the commissions could eat us alive too. Examining the figure above, we do see one time when the ratio appeared to go almost 3 standard deviations from the mean. Therefore that will be our criteria for 2007. If we see an excursion +/- 3 standard deviations from the mean, well enter a pair trade. And whenever the ratio returns to the mean, well exit both positions. And heres what 2007 ended up looking like.

On July 10, the LOW/HD ratio fell 3 standard deviations below the mean, so we buy LOW long at $29.46 and sell HD short at $38.98. And a little over a month later, on August 16, 2007, the ratio reverted to the mean so we exited both positions. This turned out to mean selling LOW at $26.42 and covering our HD short at $31.79.

So our long LOW position was a 10.3% loss but the short HD position was a 22.6% gain. Therefore our equal dollar positions averaged out to a 6.1% gain. Were now back in cash and ready to spring the trap again should a new opportunity arise. And indeed it shortly does. On September 24, 2007 the ratio has now gone 3 standard deviations above the mean. So this time we end up doing the reverse as the previous time. We take a long position in HD at $33.02 and sell short LOW at $30.10. And a little less than 2 months later, the ratio has once again reverted to the mean. On November 20, 2007 we sell our long HD position at $27.78 and cover our short LOW position at $22.25. So we take a 15.9% loss on HD but get a 35.3% gain on LOW. This averages to a9.7% gain. And this is the last time we get to pounce in 2007. Thus our two pair trades compounded to a +16.5% annual return! Not bad, considering buy-and-hold would have given you a 27% loss in LOW and 31% loss in HD. (I told you their prices move together) And further, we were only committed to a pair trade about 3 months of the whole year. While we were waiting we could have kept our money in a low-volatility bond index fund (e.g. VFISX or VBMFX) to generate fixed income in the mean time. I havent run the exact dates but these returned 8% and 7% respectively if youd held them for all of 2007. So maybe it isnt unrealistic to assume that this would have pushed our +16.5% past the 20%+ return mark. In balance, though this example used real historical data, its probably making pair trading look easier than it is. Some

companies diverge and dont mean revert. And should your mean and standard deviations be based on last year or multiple years? A fixed start and stop date or a moving average? Should you jump in at 2, 2.5, or 3 standard deviation excursions and when do you exit (for both profit and for stop loss). Backtest to derive your own optimized parameters and have fun.

Vous aimerez peut-être aussi