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

Brian G. Peterson brian at braverock.com
Sat Apr 28 12:31:56 CEST 2012


On Sat, 2012-04-28 at 16:14 +0800, Haiping LAN wrote:
> Dear Brian,  Michael  and Db.
> 
> Thanks for all your suggests.
> I tried all your hints. But i found the problem remains, and still shows "
> order.by requires an appropriate time-based object"
> 
> it sounds strange.

If you are going to persist in suggesting that a bug exists, then please
provide a reproducible example.  

>From your original message and the suggestions you've received, the
complete example would be:

#########
require(quantmod)
getSymbols('^GSPC')

ex.model <- specifyModel(T.ind(GSPC) ~ Delt(Cly,k=1:3))

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.Cl <- specifyModel(T.ind(GSPC) ~ Delt(Cl(GSPC),k=1:3))
ex.model.Ad <- specifyModel(T.ind(GSPC) ~ Delt(Ad(GSPC),k=1:3))
#########

This works for me.  

Where, specifically, do you think there is still a problem?

I don't see any evidence of a bug here in quantmod, xts, or lm.

   - Brian

> On 23 April 2012 23:08, Brian G. Peterson <brian at braverock.com> wrote:
> 
> > On Mon, 2012-04-23 at 11:03 -0400, R. Michael Weylandt wrote:
> > > In addition to what's been said, you could much more easily write:
> > >
> > > GSPC <- getSymbols("^GSPC", from = "2000-01-01", auto.assign = F)
> >
> > I'll make it simpler still...
> >
> > getSymbols("^GSPC", from = "2000-01-01")
> >
> > which will create object 'GSPC' and avoids the frowned upon use of 'F'
> > for FALSE (which can easily collide with a variable)
> >
> > Regards,
> >
> >   - Brian



More information about the R-SIG-Finance mailing list