Kevin_in_GA 4,599 posts msg #89319 - Ignore Kevin_in_GA |
3/9/2010 1:54:28 PM
In StockFetcher, that is.
There is a function in the yepher documentation called "r-squared" which returns the correlation coefficient for a single stock (how close to a straight line has the price been trending over a given period of time).
I would like to determine how well correlated two different stocks are - for example QQQQ and SPY, or GLD and SLV. I have not yet figured out a trick to do this.
My first though was to simply define the ratio of the stock price to the price of the SPY as a new data set, and use something like the following:
set{priceratio, close / ind(SPY, close)}
then use the r-squared function on the new variable priceratio:
set{correlation, ind(priceratio, r-squared(30))}
but as you can see this doesn't really work:
They all are the same - even SPY with itself, which should be a perfect fit.
Any thoughts on how one can get this correlation?
|
Kevin_in_GA 4,599 posts msg #89323 - Ignore Kevin_in_GA |
3/9/2010 3:17:42 PM
Thanks, Chet. I looked at this one already, and what it does is to compare the %gain in the individual stock for the period defined against the gain in the SPX for the same period. If it is above 1, the stock perfomed better than the index.
What it explicitly states is that it is not a pattern matching tool, which is another way of saying the two stocks move in an identical fashion over a set period of time (high correlation between price).
I am trying to find a way to measure correlations between two similar stocks, and be able to play a hedged strategy based on a change in the correlation (which historically will revert to the mean for proper pairs).
|