Re: [R] Stock Price Correlation to Index Price Levels

2007-06-13 Thread Moshe Olshansky
Josh Kalish wrote:

Thanks to all of the people who responded.  What I
was trying to do is 
to
turn my matrix or frame containing index level
returns and stock 
returns
into a matrix of betas.  I don't really need to
worry about risk-free
interest rates.  I just need to be able to come up
with a number that 
shows
the expected index correlation.  

 

I was able finally to figure out how to use cor() to
get what I think 
is an
R^2 value.  But, I'm trying to also figure out the
ratio of 
correlation.
For example, some stocks correlate very well and
cor() returns a value 
of
.92.  But, how do you then figure out if the stock
should have a 1.5:1
correlation? 

 

The way I would do it by hand is to turn the closes
into daily returns 
and
then get the mean() return for each stock against the
index by day.  I 
can't
find an example as hard as I look, but this must be
very common.

 
If X is a vector of daily returns (today's close -
yesterday's close) for your index (in dollars) and Y
is the vector of daily returns for your stock (in
dollars), then to hedge 1 share of your stock you need
to hold u = -(1/r)*(Sy/Sx) units of the index, where r
is the correlation coefficient, Sx is the standard
deviation of daily returns of the index and Sy is the
standard deviation of daily returns of Y.
In R,
u - -(1/cor(X,Y))*(sd(Y)/sd(X))
 
In this case your stock is fully hedged by the index
(but the index of course is not fully hedged by the
stock, unless the correlation coefficient is +/- 1).

Hope this helps,

Moshe Olshansky.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Stock Price Correlation to Index Price Levels

2007-06-12 Thread Kalish, Josh
Hi,

This is probably trivial to most people out there, but I'm struggling with this.

I have a data set which contains the closing prices (properly adjusted for 
dividends and splits) for several hundred securities and the closing prices for 
a general stock market index (SP 500).  I have no problem getting it into R 
with RODBC and manipulating it.  There are no missing values.  I can easily 
turn the closing price series into a daily return series.

I'm trying to determine for each of the securities it's correlation to the 
index both in terms of an overall beta and the variance associated with the 
name.  For example a security might happen to average out to looking like it 
tracks the index, but the variance may be so high that it is not reliable.  I 
need to figure out how to score these names against the index.

I've looked at the cor() and cov() functions, but I couldn't figure out exactly 
how to use them to get this information.

I can put this data into excel and cover up with the mean of daily return for 
each name divided by the index return.  I can also come up with the variance of 
this, which is a good start.  I'd much rather do this in R, and I'm sure it's 
much more suited for this.  Also, there may be a better approach to this and I 
would be interested in any suggestions.

To give you a practical example, at the end of the day I may have long and 
short positions in twenty names in a trading account.   If there is a net 
exposure to the index then I can hedge it with index futures.  But, if there's 
low correlation, then I can't.  

Thanks,

Josh Kalish



==
Please access the attached hyperlink for an important electr...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Stock Price Correlation to Index Price Levels

2007-06-12 Thread Josh Kalish
Thanks to all of the people who responded.  What I was trying to do is to
turn my matrix or frame containing index level returns and stock returns
into a matrix of betas.  I don't really need to worry about risk-free
interest rates.  I just need to be able to come up with a number that shows
the expected index correlation.  

 

I was able finally to figure out how to use cor() to get what I think is an
R^2 value.  But, I'm trying to also figure out the ratio of correlation.
For example, some stocks correlate very well and cor() returns a value of
.92.  But, how do you then figure out if the stock should have a 1.5:1
correlation? 

 

The way I would do it by hand is to turn the closes into daily returns and
then get the mean() return for each stock against the index by day.  I can't
find an example as hard as I look, but this must be very common.

 

Thanks,

 

Josh


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.