Learn R Programming

highfrequency (version 1.0.1)

gatherPrices: Make TAQ format

Description

Convenience function to gather data from one xts or data.table with at least "DT", and d columns containing price data to a "DT", "SYMBOL", and "PRICE" column. This function the opposite of spreadPrices.

Usage

gatherPrices(data)

Value

a data.table with columns DT, SYMBOL, and PRICE

Arguments

data

An xts or a data.table object with at least "DT" and d columns with price data with their names corresponding to the respective symbols.

Author

Emil Sjoerup

See Also

spreadPrices

Examples

Run this code
if (FALSE) {
library(data.table)
data1 <- copy(sampleTData)[,  `:=`(PRICE = PRICE * runif(.N, min = 0.99, max = 1.01),
                                               DT = DT + runif(.N, 0.01, 0.02))]
data2 <- copy(sampleTData)[, SYMBOL := 'XYZ']
dat1 <- rbind(data1[, list(DT, SYMBOL, PRICE)], data2[, list(DT, SYMBOL, PRICE)])
setkeyv(dat1, c("DT", "SYMBOL"))
dat1
dat <- spreadPrices(dat1) # Easy to use for realized measures
dat
dat <- gatherPrices(dat)
dat
all.equal(dat1, dat) # We have changed to RM format and back.
}

Run the code above in your browser using DataLab