[R-SIG-Finance] about an error of xts

R. Michael Weylandt michael.weylandt at gmail.com
Mon Apr 23 17:03:21 CEST 2012


In addition to what's been said, you could much more easily write:

GSPC <- getSymbols("^GSPC", from = "2000-01-01", auto.assign = F)

which will give names that are (directly) compatible with other
quantmod functions and would seem to avoid your problem in the first
place.

Michael


On Mon, Apr 23, 2012 at 4:50 AM, Haiping LAN <haipinglan at gmail.com> wrote:
> *Hallo, lists:*
> *
> *
> *  I came to an error for xts package : * "order.by requires an appropriate
> time-based object".
> * It seems there is no explicit solution to this problem, so would you
> please do me a favor and give me some further advice ?*
> *My current version for R is 2.14.0, and relevant codes are as follows :*
>
> library(tseries)
>
> library(quantmod)
>
> GSPC <- as.xts(get.hist.quote("^GSPC",start="2000-01-02",
>          quote=c("Open", "High", "Low", "Close","Volume","AdjClose")))
>
> T.ind <- function(quotes,tgt.margin=0.025,n.days=10) {
>  v <- apply(HLC(quotes),1,mean)
>
>  r <- matrix(NA,ncol=n.days,nrow=NROW(quotes))
>  for(x in 1:n.days) r[,x] <- Next(Delt(v,k=x),x)
>
>  x <- apply(r,1,function(x) sum(x[x > tgt.margin | x < -tgt.margin]))
>  if (is.xts(quotes)) xts(x,time(quotes)) else x
> }
>
> ex.model <- specifyModel(T.ind(GSPC) ~ Delt(Cl(GSPC),k=1:3))
>
> *
> *
> *Best,*
> *Haiping Lan /Guosen Securities Co.*
>
> *
> *
>
> --
>  Haiping LAN
>
>        [[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