Learn R Programming

highfrequency (version 0.7.0.1)

aggregateTrades: Aggregate a data.table or xts object containing trades data

Description

Function returns new time series as a data.table or xts object where first observation is always the opening price and subsequent observations are the closing prices over the interval.

Usage

aggregateTrades(
  tData,
  on = "minutes",
  k = 5,
  marketOpen = "09:30:00",
  marketClose = "16:00:00",
  tz = "GMT"
)

Arguments

tData

data.table or xts object to be aggregated, containing the intraday price series of a stock for possibly multiple days.

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 an 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".

Value

A data.table or xts object containing the aggregated time series.

Details

The timestamps of the new time series are the closing times and/or days of the intervals.

The output "PRICE" column is constructed using previous tick aggregation.

The variable "SIZE" is aggregated by taking the sum over each interval.

The variable "VWPRICE" is the aggregated price weighted by volume.

The timestamps of the new time series are the closing times of the intervals.

In case of previous tick aggregation or 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, including the value at 09:35:00 itself.

Examples

Run this code
# NOT RUN {
# aggregate trade data to 5 minute frequency
tDataAggregated <- aggregateTrades(sampleTData, on = "minutes", k = 5)
head(tDataAggregated)
# }

Run the code above in your browser using DataLab