Solved

Simple formula for calculating R-Squared between 2 stocks

Posted on 2016-08-19
8
61 Views
Last Modified: 2016-08-24
Hello Experts, I'm a Delphi programmer writing a bit of a financial analysis program for myself and I'm having trouble with the calculation of R-Squared between the daily closing prices of 2 financial instruments. I thought I found a good formula on the net for doing it, but it doesn't yield sensible results. I'm no advanced statistics experts, but doesn't R-Squared have to be a value between 0 and 1? The formula I used yields values like 7.11 and 10.67... not making much sense. Here is the formula:

RSquared = (Covariance (x,y) * Covariance (x,y))   / (Variance(x) * Variance(y))

Could anyone offer any help please?

Thanks!
    Shawn
0
Comment
Question by:shawn857
  • 4
  • 3
8 Comments
 
LVL 26

Accepted Solution

by:
Fred Marshall earned 400 total points
ID: 41763797
Well, some definitions would put the correlation coefficient "r" in the range from -1 > +1.
So, yes,  r squared would be in the range 0 > +1.
This much tracks.

If your "formula" yields other values then one would have to know the formula and the data being put into it wouldn't one?
0
 

Author Comment

by:shawn857
ID: 41766244
Thanks Fred, yes I've come across that too on the net that the r-squared is no more than the Correlation Coefficient squared. That's simple enough - I'm already calculation correctly the Correlation Coefficient... but on some sites it describes r-squared differently and gives a different calculation. It's said that r-squared indicates of the "reliability" of the correlation coefficient... but to me, simply taking the CorrCoef and squaring it doesn't really offer any more insight. So I guess I'm just a little confused...

Thanks
   Shawn

P.S: I'm not sure what you mean by "This much tracks"...?
0
 
LVL 26

Expert Comment

by:Fred Marshall
ID: 41766317
I meant by "this much tracks" is that we agree on terms as I've re-stated them.

But how in the world do you get the numbers you get?  You haven't revealed the expressions being used.  That does *not* track.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:shawn857
ID: 41767811
Well Fred, googling around some time ago, here was a formula for RSquared I found in a financial analyiss article - so I figured it was what I wanted:

StockRsquared := Sqr(Covariance(x,y)) / ( Sqr(StdDev(x)) * Sqr(StdDev(y)));

That's the one that yielded the crazy numbers. But really - if RSquared is nothing more than Correlation Coefficient (...which I'm already calculating) squared, then I don't think I'm going to bang my head against the wall about this any more!

Thanks
   Shawn
0
 
LVL 26

Expert Comment

by:Fred Marshall
ID: 41767902
Then I guess we might look at some real numbers because the correlation coefficient can't be greater than 1.0 in magnitude.  I don't see anything wrong with the expressions.

While it may seem a bit simplisitic:  Here is a web page where one can calculate some cases and envision how it should go;

http://www.socscistatistics.com/tests/pearson/Default2.aspx
0
 
LVL 32

Assisted Solution

by:phoffric
phoffric earned 100 total points
ID: 41768170
Sometimes there are scaling factors that need to be taken into account.
When you do a help on Covariance (x,y))  and (Variance(x) in your programming language, what precisely are the equations that these functions boil down to. I just went through an exercise at work where in one language, the scaling factor were different than in a library.
0
 

Author Comment

by:shawn857
ID: 41769647
Guys I'm awfully sorry - I just found a grievous grievous error in my program I'm writing.  This was responsible for the crazy RSquared numbers. I corrected this andt he formula I mentioned a few posts earlier seems to be now yielding sensible results. Sorry for the false alarm!

Cheers
   Shawn
0
 

Author Closing Comment

by:shawn857
ID: 41769648
Thank you!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to Win a Jar of Candy Corn: A Scientific Approach! I love mathematics. If you love mathematics also, you may enjoy this tip on how to use math to win your own jar of candy corn and to impress your friends. As I said, I love math, but I gu…
This article provides a brief introduction to tissue engineering, the process by which organs can be grown artificially. It covers the problems with organ transplants, the tissue engineering process, and the current successes and problems of the tec…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question