Learn R Programming

dwtools (version 0.8.3.9)

vwap: OHLC and VWAP

Description

Perform OHLC and VWAP on tick trades.

Usage

vwap(x, units, trunc_ceiling = "trunc")

Arguments

x
data.table of tick trades, columns: date, price, amount, tid, type.
units
time units period to aggregate.
trunc_ceiling
character, default trunc, also possible ceiling.

Value

data.table aggregated to specified time units, price column is VWAP.

Details

Rows where amount==0 (normally should not happened) should be filtered before passing the tick data to the function.

Examples

Run this code
suppressPackageStartupMessages(library(dwtools))

# populate tick data
suppressPackageStartupMessages(library(Rbitcoin))
tick = market.api.process("hitbtc",c("BTC","USD"),"trades")[["trades"]]
print(tick)

# ohlc + vwap
DT = vwap(tick, "30 mins")
print(DT)

# same with timing
DT = timing(vwap(tick, "30 mins"), nrow(tick))
get.timing()

# ohlc + vwap, aggregate using ceiling
DT = vwap(tick, "30 mins", "ceiling")
print(DT)

Run the code above in your browser using DataLab