[R] as.zoo behavior (

Mark.Leeds at MorganStanley.com Mark.Leeds at MorganStanley.com
Fri Nov 3 23:58:53 CET 2006


hi all : the code pasted below runs but then, a dput on
rollmeandifflogbidask gives me what is below the code. the structure of
rollmeandifflogbidask is a zoo object but with a "frequency"
so it's not the same structure as the original actual diff and this
really causes things to blow up in later code. i'm sure gabor and achim
know what to do but in the case that they
are not around, would someone else know ? the code for ewma is below the
structure of rollmeandifflogbidask in the case that someone wants
to run it themselves. thanks a lot.

#-----------------------------------------------------------------------
-----------------------------------------------------------

actualdiff<-structure(c(-1.45571955822987e-06, -7.27862957994319e-06,
-0.000109185801586698,
-0.000134158878632995, -9.98463614099165e-06, 0.000128544569886202,
5.33190241842618e-05, 1.5881826502806e-06, -2.23230209073222e-05,
-6.66190921299048e-05, -5.95638733376092e-05, -3.5740027046316e-05,
-0.000211818969710897, 0.000241006754088779, 5.89686385294996e-05,
-9.88290397652136e-05, 2.45716680487007e-05, -2.18414528943001e-05,
2.18414528943001e-05, 0, -2.18414528943001e-05, 1.45610216018000e-05,
-8.55490383084856e-05, -1.63825656738226e-05, 0.000101931603982308,
-1.45610216018000e-05, 2.18414528943001e-05, 0, -2.18414528943001e-05,
-6.5527221122963e-05), index = structure(c(1151884920, 1151884980,
1151885040, 1151885100, 1151885160, 1151885220, 1151885280, 1151885340,
1151885400, 1151885460, 1151885520, 1151885580, 1151885640, 1151885700,
1151885760, 1151885820, 1151885880, 1151885940, 1151886060, 1151886120,
1151886180, 1151886240, 1151886300, 1151886360, 1151886420, 1151886480,
1151886540, 1151886600, 1151886660, 1151886720), class = c("POSIXt",
"POSIXct")), class = "zoo")

temp<-ewma(actualdiff,.05),
rollmeandifflogbidask<-as.zoo(temp,index(actualdiff))

resulting structure of rollmeandifflogbidask

#-----------------------------------------------------------------------
------------------------------------------------------------------------
-----------------

structure(c(-7.27859779114937e-08, -4.33078158013078e-07,
-5.8707143294473e-06,
-1.22851225446247e-05, -1.21700982244430e-05, -5.13436481891078e-06,
-2.21169536875215e-06, -2.02170146780051e-06, -3.0367674397766e-06,
-6.21588367428301e-06, -8.88328315744932e-06, -1.02261203518926e-05,
-2.03057628198429e-05, -7.24013697441177e-06, -3.9296981992162e-06,
-8.67466527751607e-06, -7.01234861120523e-06, -7.75380382535997e-06,
NA, 0, 0, -1.09207264471500e-06, -3.09417932389255e-07,
-4.57139895119407e-06,
-5.1619572873255e-06, 1.92720776156187e-07, -5.4496634274162e-07,
5.74354619110464e-07, 5.45636888154941e-07, -5.73717600967809e-07,
-3.82139277706757e-06), index = c(1151884920, 1151884980, 1151885040,
1151885100, 1151885160, 1151885220, 1151885280, 1151885340, 1151885400,
1151885460, 1151885520, 1151885580, 1151885640, 1151885700, 1151885760,
1151885820, 1151885880, 1151885940, 1151886000, 1151886060, 1151886120,
1151886180, 1151886240, 1151886300, 1151886360, 1151886420, 1151886480,
1151886540, 1151886600, 1151886660, 1151886720), frequency =
0.0166666666666667, class = c("zooreg",
"zoo"))

it seems to be a zoo object but with a frequency that i think comes from
the fact that the ewma function produces a series of class ts.
I need the structure to be the EXACT same structure as the original
actual diff so i must be doing something wrong.

EWMA function

#-----------------------------------------------------------------------
------------------------------------------------------------------------
--------------------------------------------

ewma<-function(x,lambda = 1, init = 0) {

filter(lambda*x,filter=(1-lambda),method="recursive",init=init)

}



More information about the R-help mailing list