[R-SIG-Finance] filter() on zoo objects

Gabor Grothendieck ggrothendieck at gmail.com
Thu Mar 27 18:06:59 CET 2008


Two points:

1. If you have a routine that accepts ts but not zoo then you have a problem
even beyond representations since the routine is assuming equally
spaced points.  Assuming your data is not equally spaced, e.g.
no data on weekends, then its up to you to figure out how you
want to map it to equally spaced points.  Two possibilities for
zoo object z are:

- as.ts(z) which will make it equally spaced by inserting NAs (e.g.
where weekends are)

- ts(coredata(z)) which uses the time base 1, 2, 3, ... or you can
use other args of ts to use a different time base.

If the routine you are calling returns a ts object, out,
then it may or may not be that as.zoo(out) or
zoo(coredata(out), time(z)) make sense.  It will all
depend on the situation.  You may have to write
a custom mapping to the time base or not use that
ts-only routine in the first place -- see first paragraph above.

2. Aside from rollapply and friends,  The last question in the zoo
faq gives a list of the packages that work with zoo objects --
there are now about 20 of them.  For example, dyn and dynlm
packages can perform regression on zoo series with lags
and diffs and keep track of the time base.  You want to stick
with zoo-capable routines if possible.

On Thu, Mar 27, 2008 at 6:17 AM, Vorlow Constantinos
<CVorlow at eurobank.gr> wrote:
> Dear all,
>
> Am I right in understanding you cannot directly apply functions such as
> loess() (filter() as well ?) to zoo objects and you need to use the
> rollapply/rollmean functions instead?
>
> For example:
>
> library("tseries")
> DJ<- get.hist.quote("^DJI", start = "1990-01-01", quote = "Close")
> DJret<-diff(log(DJ))
>
> # the
>
> loess(DJret, time(DJret))
>
> does not work(?). What am I understanding  wrong? I found a reply by
> Achim on a similar issue.
>
> http://finzi.psych.upenn.edu/R/Rhelp02a/archive/88599.html
>
> Is Achim's answer all there is to it?
>
> I.e., my problem is a little bit  more general:
>
> Say I want to produce fits and then forecasts on a time series (zoo
> mostly) using a non-zoo routine which "understands" ts or timeSeries
> objects (or simple vectors).  Do I always have to "translate" zoo
> objects to vectors or to ts/simeSeries ones, run the routines and then
> put back the zoo attribute with the appropriate dates so as to produce
> correct time-series plots (with dates etc, especially correct dates
> alligned to the forecast period - which could be postsample)?
>
> Is there an easier way to shift between zoo-ts/timeSeries objects and
> produce plots statistical analysis that will have the dates correctly
> aligned on (to account for example for irregularly sampled sequences
> such as stock prices with non-trading days etc. etc.)?
>
> Thanks in advance,
> Costas
>
>
>
> P Think before you print.
>
> Disclaimer:
> This e-mail is confidential. If you are not the intended recipient, you should not copy it, re-transmit it, use it or disclose its contents, but should return it to the sender immediately and delete the copy from your system.
> EFG Eurobank Ergasias S.A. is not responsible for, nor endorses, any opinion, recommendation, conclusion, solicitation, offer or agreement or any information contained in this communication.
> EFG Eurobank Ergasias S.A. cannot accept any responsibility for the accuracy or completeness of this message as it has been transmitted over a public network. If you suspect that the message may have been intercepted or amended, please call the sender.
>
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



More information about the R-SIG-Finance mailing list