# How to calculate the weight of the stocks using the linear regression?

I do a simple example with the follow three series(stocks prices):

a = 1, 1.2, 1.8, 1.3, 0.9, 2
b = 56, 58, 63, 61.5, 57.6, 58
c = 105.6, 110, 106.9, 103, 101.2, 107


ok, so let assume those series are the prices of the three stocks, named A, B and C.

Now, I do the linear regression doing:

mod = lm(a ~ b + c + 0)


the result of the linear model is:

Call:
lm(formula = a ~ b + c + 0)

Coefficients:
b          c
0.030570  -0.004095

> mod\$residuals
1          2          3          4          5          6
-0.2795238 -0.1226474  0.3118110 -0.1583030 -0.4464512  0.6650691


Now we know the coefficients of b and c and here I have a doubt regarding, how can I understand reading these coefficients the weight of the stocks I need to buy.

With the weight I mean, example:

A: 10 stocks
B: 2 stocks
C: 16 stocks


I would like to create this spread and calculate the correct number of stocks.

IMPORTANT: This is only an example, I know that I need more tests to check the stability etc etc but with this example I only would like to understand:

How can I calculate the number of the stocks reading the linear regression coefficients?

Thank you!

-
Seven of your 11 questions on here have been closed. Given the sheer volume of warnings you've received, you should know by now what's considered appropriate level of material. –  chrisaycock May 25 '12 at 14:15
@chrisaycock thank you for downvote. –  Dail May 25 '12 at 14:16
add comment

## 1 Answer

If I understand correctly then you measure something that you actually do not look out for. Your regression tries to explain prices of stock A by using a linear combination of stocks B and C. The coefficients tell you the fraction of stocks you need to have in stocks B and C in order to arrive at the predicted price of stock A. Thus, 0.031 shares of stock B plus 0.0041 shares SHORT of stock C will output the predicted price of stock A. I doubt that is what you want UNLESS you are convinced that prices of stock B and C OVER TIME are a good predictor for prices in stock A. Generally I advise, however, you work with log returns and not absolute stock prices. Hope this helps.

-
Yes I know what the linear regression does, but with this question i'm asking how can apply the coefficients to my trades, I do a stupid example..... as you saw I have these coefficients: (0.030570 -0.004095) The question is that I can buy or sell 0.03 or 0.004 of a stock, I can but 1 2 3 4 etc etc stocks i can easily calculate the weight if i do a linear regression with two stock, mod = lm(a~b+0) but in this case i have 2 stocks (on the right) so what is the hedge ratio of this spread? I would like to know something like: A: 1 - B: 20 - C: 30 –  Dail May 25 '12 at 13:52
I need to understand how many stocks I need to buy or sell (it is not the point now ... the type of the trade). Know the coefficients are how many trade I need to buy for each A, but i can't buy 0.0041 stocks. So the question is how can I bring these numbers to the real trading number of stocks. –  Dail May 25 '12 at 13:58
calculate the lowest common denominator, that is your hedge ratio: In this example short 1 stock of stock C and buy 7.5 of stock B to hedge 250 units of stock A. Those are rough figures but about what your LM outputs. –  Matt Wolf May 25 '12 at 16:18
add comment