Solved

Simple formula for calculating R-Squared between 2 stocks

Posted on 2016-08-19
8
46 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 25

Accepted Solution

by:
Fred Marshall earned 400 total points
Comment Utility
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
Comment Utility
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 25

Expert Comment

by:Fred Marshall
Comment Utility
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
 

Author Comment

by:shawn857
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 25

Expert Comment

by:Fred Marshall
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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.
Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now