[R-SIG-Finance] applying to.period on matrices
jeff.a.ryan at gmail.com
jeff.a.ryan at gmail.com
Wed Feb 27 21:28:21 CET 2008
Murali,
The core issue with to.period is that it is aggregating a series by period and tabulating the opening, closing, max (high) and min (low) value over these periods.
The resultant object is by necessity an OHLC object. Currently Volume is summed if available too, but that isn't required.
Applying to a matrix is sort of ill-defined for this - as I am not too sure what the output would look like. A list of OHLC objects?
Subsetting an xts does indeed result in another xts object. Internally xts, like zoo, is just a matrix - with an index attribute. So technically the columns aren't xts.
If you are just looking to calculate something -along- a period, say a maximum weekly value or a function applied periodically - look at period.apply.
Jeff
Sent via BlackBerry from T-Mobile
-----Original Message-----
From: Murali Menon <feanor0 at hotmail.com>
Date: Wed, 27 Feb 2008 14:26:05
To:<r-sig-finance at stat.math.ethz.ch>
Subject: [R-SIG-Finance] applying to.period on matrices
Folks,
I understand that the to.weekly (etc.) functions work only on univariate series or OHLC objects, so I thought that the standard apply(x, 2, to.weekly) technique might work. Unfortunately, it doesn't. What am I doing wrong? Please advise.
> xx <- matrix(rnorm(1000), ncol=10)> xts.ts <- xts(xx, as.Date(13514:13613), origin="1970-01-01")> is.xts(xts.ts)[1] TRUE> to.weekly(xts.ts)Error in to.period(x, "weeks", name = name, ...) : 'x' must be a single column or an OHLC type object> apply(xts.ts, 2, to.weekly)Error in UseMethod("as.xts") : no applicable method for "as.xts"
I'm guessing that the individual columns of the xts.ts object are not themselves xts objects? The index info is lost?
I'm using R2.6.1 on Windows XP, and xts_0.0-10, zoo_1.4-1
Thanks,
Murali
_________________________________________________________________
Climb to the top of the charts! Play the word scramble challenge with star power.
[[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