make_bars: 'make_bars'

Description Usage Arguments Details Author(s) References Examples

View source: R/bars.R

Description

Creates financial 'bars' (also known as 'candlesticks') from raw trade data. One may construct either time, volume, unit, tick, tick-runs, tick-imbalance (TIBs) volume-imbalance (VIBs), unit-imbalance (DIBs), or CUSUM-bars.

Usage

1
make_bars(x, type, by = c(1, "days"))

Arguments

x

A data.frame of raw tick data. The object must contain columns: timestamp(POSIXct), price(numeric), size(numeric), and side(character).

type

One of either: time, volume, unit, tick, tick runs, tick imbalance volume imbalance, unit imbalance, or CUSUM bars. See details for further information.

by

An integer (or in the case of type='time', an integer and interval) specifying the sampling frequency. See details for further information.

Details

'make_bars' creates an OHLCV (Open/High/Low/Close/Volume) matrix of class 'xts' The function requires an input of class 'data.frame' or 'matrix' with the following columns:

timestamp: time of observation; will be used as the xts index

price: the price of the transacted units

size: number of transacted units

side: an integer vector of 1L(buy) or -1L(sell)

Type may be one of either time, volume, unit, tick runs, tick imbalance volume imbalance, unit imbalance, or CUSUM bars.

time: sampled every 'by' units of time; must be a vector of length two, and corresponding to [units, interval]; for example, 'by=c(1, "days")' or 'by=c(1, "secs")'. Default is c(1, "days")

tick: sampled every 'by' number of ticks

volume: sampled every 'by' units of volume

unit: sampled every 'by' units(dollars) of units (e.g., every $10,000)

*NOTE* 'tick runs', 'tick imbalance', 'volume imbalance', 'unit imbalance', and 'CUMSUM' are not yet supported

Author(s)

Nathan Matare <email: nmatare@chicagobooth.com>

References

Lopez de Prado, Marcos, Advances in Financial Machine Learning (2018)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
df <- data.frame(
 timestamp=seq(from = as.POSIXct("2018-01-21"), 
               length.out = 100, by = "secs"),
 price=rnorm(100,65,5),
 size=rnorm(100,10,1),
 side=rep(c(1L, -1L), 50)
)

result <- make_bars(x=df, type='time', by=c(5, "mins"))
result


## End(Not run)

nmatare/quanttools documentation built on May 23, 2019, 9:32 a.m.