aggregateTrades {highfrequency}R Documentation

Aggregate a data.table or xts object containing trades data´

Description

Aggregate tick-by-tick trade data and return a 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. This function accepts arbitrary number of symbols over an arbitrary number of days.

Usage

aggregateTrades(
  tData,
  alignBy = "minutes",
  alignPeriod = 5,
  marketOpen = "09:30:00",
  marketClose = "16:00:00",
  tz = NULL
)

Arguments

tData

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

alignBy

character, indicating the time scale in which alignPeriod is expressed. Possible values are: "secs", "seconds", "mins", "minutes", "hours". To aggregate based on a 5 minute frequency, set alignPeriod = 5 and alignBy = "minutes".

alignPeriod

positive numeric, indicating the number of periods to aggregate over. For example, to aggregate based on a 5 minute frequency, set alignPeriod = 5 and alignBy = "minutes".

marketOpen

the market opening time, by default: marketOpen = "09:30:00".

marketClose

the market closing time, by default: marketClose = "16:00:00".

tz

fallback time zone used in case we we are unable to identify the timezone of the data, by default: tz = NULL. We attempt to extract the timezone from the DT column (or index) of the data, which may fail. In case of failure we use tz if specified, and if it is not specified, we use "UTC"

Details

The time stamps 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 time stamps of the new time series are the closing times of the intervals.

In case of previous tick aggregation or alignBy = "seconds"/"minutes"/"hours", the element of the returned series with e.g. time stamp 09:35:00 contains the last observation up to that point, including the value at 09:35:00 itself.

Value

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

Author(s)

Jonathan Cornelissen, Kris Boudt, Onno Kleen, and Emil Sjoerup.

Examples

# Aggregate trade data to 5 minute frequency
tDataAggregated <- aggregateTrades(sampleTData, alignBy = "minutes", alignPeriod = 5)
tDataAggregated

[Package highfrequency version 1.0.1 Index]