Is there a way to create Bollinger Bands without having to loop on the observations of a time serie? Any help appreciated Thanks
On Mon, 2003-11-24 at 09:19, Arnaud_Amsellem at ssga.com wrote:> Is there a way to create Bollinger Bands without having to loop on the > observations of a time serie? > > Any help appreciated > > ThanksHave you considered matlines() or matplot()? Each will generate a plot or add lines to an existing plot based upon matrices of values. See the examples in ?matlines or ?matplot to get a feel for what they can do. HTH, Marc Schwartz
I assume you are looking to apply some function, f, over the last k points of your time series for each point in the series (except for the first k-1 points). Let z be a vector that represents your time series. Then the j-th column of zl <- matrix(c(z,NA),length(z),k)[-seq(k-1),] # ignore warning is z lagged by j-1. Now apply f to the rows: apply(zl,1,f) --- Date: Mon, 24 Nov 2003 15:19:10 +0000 From: <Arnaud_Amsellem at ssga.com> To: <r-help at stat.math.ethz.ch> Subject: [R] Bollinger Bands Is there a way to create Bollinger Bands without having to loop on the observations of a time serie? Any help appreciated Thanks
You might wish to have a look at the 'its' package for irregular time-series on CRAN. If your prices are in an its called price, then the following will get you on your way. Since it is not efficient either in storage or computation, I offer it because it might be convenient for display, further processing, etc. library(its) ... tmp <- lagdistIts(diff(log(price)),1,20) rollvol <- its(as.matrix(sqrt(apply(tmp,1,var,na.rm=TRUE)))) - Giles> -----Original Message----- > From: Arnaud_Amsellem at ssga.com [mailto:Arnaud_Amsellem at ssga.com] > Sent: 24 November 2003 15:19 > To: r-help at stat.math.ethz.ch > Subject: [R] Bollinger Bands > > > Is there a way to create Bollinger Bands without having to loop on the > observations of a time serie? > > Any help appreciated > > Thanks > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >********************************************************************** This is a commercial communication from Commerzbank AG.\ \ T...{{dropped}}