[R-sig-finance] using yahoo and other data to calculate CAPM and FF betas
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Apr 7 05:53:50 CEST 2006
I mentioned omitting the missing values via na.omit and the poster
below mentioned using linear approximation. Note that
the zoo package actually has 4 missing value routines:
na.omit - omit missing values
na.approx - replace missing values with linear approximations
na.locf - replace missing values with the last occurrernce carried forward
na.contiguous - remove all but a contiguous stretch of non-missing values
> library(zoo)
> z <- zoo(c(1,NA,3,NA,5))
> na.omit(z)
1 3 5
1 3 5
> na.locf(z)
1 2 3 4 5
1 1 3 3 5
> na.approx(z)
1 2 3 4 5
1 2 3 4 5
> na.contiguous(z)
3
3
On 4/6/06, Krishna Kumar <kriskumar at earthlink.net> wrote:
> Gabor Grothendieck wrote:
>
> >On 4/6/06, Andrew West <jgalt70 at yahoo.com> wrote:
> >
> >
> >>I haven't been able to figure
> >>out how to prevent the function from crashing when one
> >>of the companies in the list has a late start or
> >>missing data. Aligning multiple time series into a
> >>panel data dataframe is tough for non-programmers like
> >>me!
> >>
> >>
> >
> >If t1 and t2 are two ts class time series or two zoo series
> >then cbind(t1, t2) will create a multivariate series (2 columns)
> >In the case of zoo, merge(t1, t2) will also work.
> >
> >na.omit(cbind(t1, t2)) or na.omit(merge(t1,t2))
> >will eliminate rows that have any NAs in the case of zoo series.
> >
> >_______________________________________________
> >R-sig-finance at stat.math.ethz.ch mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> >
> >
> >
>
> To add to Gabor's suggestion you could do the following to get an
> approximated series..
> so if mydata is a vector with "NA" 's then doing
>
> >mydata<-approx(mydata,xout=seq(along=mydata))$y
>
> this would approximate the series and then you can do a ts.union
>
> Also there was a very interesting paper that showed that the Fama-French
> effect was not really a anamoly when you estimate using
> Robust regression instead of OLS. I can't remember the reference but it
> was Doug Martin and someone else from UW ...
> R has some nice facilities with rrcov to do the robust regressions!!
>
> Best,
> Krishna
>
>
>
>
More information about the R-sig-finance
mailing list