aggregateQuotes: Aggregate an xts object containing quote data

Description Usage Arguments Value Details Author(s) Examples

View source: R/realized.R

Description

Function returns an xts object containing the aggregated quote data with columns "SYMBOL", "EX", "BID","BIDSIZ","OFR","OFRSIZ". See sample_qdata for an example of the argument qdata.

Usage

1
aggregateQuotes(qdata,on="minutes",k=5,marketopen,marketclose)

Arguments

qdata

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

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

Value

An xts object containing the aggregated quote data.

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.

For the variables "SYMBOL" and "EX" aggregation doesn't really make sense, thus the first value of the input is taken as the value for the complete output.

Column "MODE" is dropped because aggregating makes absolutely no sense.

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,...).

Author(s)

Jonathan Cornelissen and Kris Boudt

Examples

1
2
3
4
5
#load data
data("sample_qdata");
#aggregate quote data to the 30 second frequency
xx = aggregateQuotes(sample_qdata,on="seconds",k=30);
head(xx);

Example output

Loading required package: xts
Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

                    SYMBOL EX  BID       BIDSIZ  OFR       OFRSIZ 
2008-01-04 09:30:00 "XXX"  "N" "193.340" "  4.5" "193.890" " 11.5"
2008-01-04 09:30:30 "XXX"  "N" "193.470" " 17.5" "193.630" " 20.5"
2008-01-04 09:31:00 "XXX"  "N" "192.620" "108.5" "193.280" " 70.5"
2008-01-04 09:31:30 "XXX"  "N" "192.880" " 47.5" "193.000" " 67.5"
2008-01-04 09:32:00 "XXX"  "N" "192.400" " 23.5" "192.670" " 54.5"
2008-01-04 09:32:30 "XXX"  "N" "192.140" " 28.0" "192.380" " 61.0"
Warning message:
timezone of object (GMT) is different than current timezone (). 

highfrequency documentation built on May 2, 2019, 6:09 p.m.