Description Usage Arguments Value Details Author(s) Examples
Function returns new time series as xts object where first observation is always the opening price and subsequent observations are the closing prices over the interval with as endpoint the timestamp of the result.
1 2 | aggregatePrice(ts,FUN = previoustick,on="minutes",k=1,
marketopen = "09:30:00", marketclose = "16:00:00", tz = "GMT")
|
ts |
xts object to be aggregated, containing the intraday price series of a stock for one day. |
FUN |
function to apply over each interval. By default, previous tick aggregation is done. |
on |
character, indicating the time scale in which "k" is expressed. Possible values are: "secs", "seconds", "mins", "minutes","hours". |
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". |
marketopen |
the market opening time, by default: marketopen = "09:30:00". |
marketclose |
the market closing time, by default: marketclose = "16:00:00". |
tz |
time zone used, by default: tz = "GMT". |
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.
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. An exception is marketclose (i.e. 16:00:00 ET by default), where the observation at 16:00:00 is included in the interval, since this is the end of a trading day at the NYSE.
Please input an object containing ONE day of data.
Jonathan Cornelissen and Kris Boudt
1 2 3 4 5 | #load data
data("sample_tdata");
#aggregate price data to the 30 second frequency
head(sample_tdata$PRICE)
head(aggregatePrice(sample_tdata$PRICE,on="secs",k=30));
|
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:30:27 "193.71"
2008-01-04 09:30:28 "193.59"
2008-01-04 09:30:29 "193.445"
2008-01-04 09:30:30 "193.38"
2008-01-04 09:30:31 "193.34"
2008-01-04 09:30:33 "193.52"
Warning message:
timezone of object (GMT) is different than current timezone ().
[,1]
2008-01-04 09:30:00 193.710
2008-01-04 09:30:30 193.380
2008-01-04 09:31:00 192.680
2008-01-04 09:31:30 192.880
2008-01-04 09:32:00 192.400
2008-01-04 09:32:30 192.415
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.