Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple formula for calculating R-Squared between 2 stocks

Posted on 2016-08-19
8
Medium Priority
?
96 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 1600 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article seeks to propel the full implementation of geothermal power plants in Mexico as a renewable energy source.
Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
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‚Ķ
Suggested Courses

824 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