Solved

Simple formula for calculating R-Squared between 2 stocks

Posted on 2016-08-19
8
72 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
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!

 

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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Formula to Randomize Data Set for Time Series Visual 1 128
Relative frequency assesment method 2 65
Percentage 6 68
finding artist from picture(portrait) 5 152
We are taking giant steps in technological advances in the field of wireless telephony. At just 10 years since the advent of smartphones, it is crucial to examine the benefits and disadvantages that have been report to us.
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
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.
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…

739 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