Description Usage Arguments Value Details Author(s) Examples
Function returns aggregated time series as xts object.
It can handle irregularly spaced timeseries and returns a regularly spaced one.
Use univariate timeseries as input for this function, and check out aggregateTrades
and aggregateQuotes
to aggregate Trade or Quote data objects.
1 2 | aggregatets(ts, FUN="previoustick", on="minutes", k=1, weights=NULL,
dropna=FALSE)
|
ts |
xts object to aggregate. |
FUN |
function to apply over each interval. By default, previous tick aggregation is done. Alternatively one can set e.g. FUN="mean". In case weights are supplied, this argument is ignored and a weighted average is taken. |
on |
character, indicating the time scale in which "k" is expressed. Possible values are: "secs", "seconds", "mins", "minutes","hours", "days", "weeks". |
k |
positive integer, indicating the number of periods to aggregate over. E.g. to aggregate a xts object to the 5 minute frequency set k=5 and on="minutes". |
weights |
By default, no weighting scheme is used. When you assign an xts object with wheights to this argument, a weighted mean is taken over each interval. Of course, the weights should have the same timestamps as the supplied time series. |
dropna |
boolean, which determines whether empty intervals should be dropped. By default, an NA is returned in case an interval is empty, except when the user opts for previous tick aggregation, by setting FUN="previoustick" (default). |
An xts object containing the aggregated time series.
The timestamps of the new time series are the closing times and/or days of the intervals. E.g. for a weekly aggregation the new timestamp is the last day in that particular week (namely sunday).
In case of previous tick aggregation, for on="seconds"/"minutes"/"hours", the element of the returned series with e.g. timestamp 09:35:00 contains the last observation up to that point, excluding the value at 09:35:00 itself.
Jonathan Cornelissen and Kris Boudt
1 2 3 4 5 6 7 8 9 10 11 | #load sample price data
data("sample_tdata");
ts = sample_tdata$PRICE;
#Previous tick aggregation to the 5-minute sampling frequency:
tsagg5min = aggregatets(ts,on="minutes",k=5);
head(tsagg5min);
#Previous tick aggregation to the 30-second sampling frequency:
tsagg30sec = aggregatets(ts,on="seconds",k=30);
tail(tsagg30sec);
|
Loading required package: xts
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
PRICE
2008-01-04 09:35:00 193.920
2008-01-04 09:40:00 194.630
2008-01-04 09:45:00 193.520
2008-01-04 09:50:00 192.850
2008-01-04 09:55:00 190.795
2008-01-04 10:00:00 190.420
Warning message:
timezone of object (GMT) is different than current timezone ().
PRICE
2008-01-04 15:57:30 191.790
2008-01-04 15:58:00 191.740
2008-01-04 15:58:30 191.760
2008-01-04 15:59:00 191.470
2008-01-04 15:59:30 191.825
2008-01-04 16:00:00 191.670
Warning message:
timezone of object (GMT) is different than current timezone ().
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.