aggregateQuotes: Aggregate a 'data.table' or 'xts' object containing quote...

View source: R/dataHandling.R

aggregateQuotesR Documentation

Aggregate a data.table or xts object containing quote data

Description

Aggregate tick-by-tick quote data and return a data.table or xts object containing the aggregated quote data. See sampleQData for an example of the argument qData. This function accepts arbitrary number of symbols over an arbitrary number of days.

Usage

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

Arguments

qData

data.table or xts object to be aggregated, containing the intraday quote data of a stock for one day.

alignBy

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

alignPeriod

positive numeric, indicating the number of periods to aggregate over. E.g. to aggregate based on a 5 minute frequency, set alignPeriod to 5 and alignBy to "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 output "BID" and "OFR" columns are constructed using previous tick aggregation.

The variables "BIDSIZ" and "OFRSIZ" are aggregated by taking the sum of the respective inputs over each interval.

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

Please note: Returned objects always contain the first observation (i.e. opening quotes,...).

Value

A data.table or an xts object containing the aggregated quote data.

Author(s)

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

Examples

# Aggregate quote data to the 30 second frequency
qDataAggregated <- aggregateQuotes(sampleQData, alignBy = "seconds", alignPeriod = 30)
qDataAggregated # Show the aggregated data

jonathancornelissen/highfrequency documentation built on Jan. 10, 2023, 7:29 p.m.