[R-SIG-Finance] xts and sapply

R. Michael Weylandt michael.weylandt at gmail.com
Sun Apr 1 20:34:47 CEST 2012


Just a guess, but you are missing a comma in the GSPC part of the "y <- " line.

Your bigger problem is that you don't need sapply() in the first place
here (best I remember): I think this works:

y <- merge(Ad(FNMIX), Ad(DBLTX), Ad(AGG), Ad(GSPC))
ROC(y) # Note that you don't need sapply() because ROC handles
everything nicely for you.

Michael

On Sun, Apr 1, 2012 at 2:24 PM, Eric Thungstom
<eric.thungstrom at gmail.com> wrote:
> I have prices for several securities in a data frame. I'm wondering how to
> calculate returns for each of them in a vectorized fashion.
>
> require(quantmod)
> group <-c('FNMIX','DBLTX','AGG','^GSPC')
> getSymbols(group, src="yahoo", from="2012-01-01", to=Sys.Date())
> y <- merge(FNMIX[,4],DBLTX[,4],AGG[,4],GSPC[4])
> x <-sapply(y[,1:4], dailyReturn)
>
> When I execute the above code I get an "error in arrary" message that
> indicates that the "length of dim names [1] not equal to array extent".
>
> What am I doing wrong ?
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.



More information about the R-SIG-Finance mailing list