Solved

Simple formula for calculating R-Squared between 2 stocks

Posted on 2016-08-19
8
80 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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 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

Technology Partners: 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

A Guide to the PMT, FV, IPMT and PPMT Functions In MS Excel we have the PMT, FV, IPMT and PPMT functions, which do a fantastic job for interest rate calculations.  But what if you don't have Excel ? This article is for programmers looking to re…
Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

636 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