Computes durations from a data.frame containing the time stamps of transactions. Trade durations, price durations and volume durations can be computed (if the appropriate data columns are given).
computeDurations(transactions, open = "10:00:00", close = "18:25:00",
rm0dur = TRUE, type = "trade", priceDiff = .1, cumVol = 10000)
a data.frame with columns:
the calander time of the start of each duration spell.
the volume weighted avrage price of the shares traded during the spell of the duration.
the volume (total shares traded) during the duration spell.
number of transactions done during the spell.
the computed duration.
a data.frame with, at least, transaction time in a column named 'time' (see Details)
the opening time of the exchange. Transactions done outside the trading hours will be ignored.
the closing time of the exchange.
if TRUE
zero-durations will be removed and transactions done on the same second will be aggregated, e.g. price will then be the volume weighted avrage price of the aggregated transactions.
the type of durations to be computed. Either "trade", "price", or "volume".
only if type = "price"
. Price durtions are (here) defind as the duration until the price has changed by at least 'priceDiff' in absolute value.
only if type = "cumVol"
. Volume durtions are (here) defind as the duration until the cumulative traded volume since the last duration has surpassed 'cumVol'.
Markus Belfrage
The data.frame must include a column named 'time' with the time of each transaction, in a time format recognizable by POSIXlt or strings in format "yyyy-mm-dd hh:mm:ss". If the column 'price' or 'volume' is included its also possible to compute price- and volume durations (see arguments priceDiff
and cumVol
)
if (FALSE) {
#only the first 3 days of data:
durDataShort <- computeDurations(transData[1:56700, ])
str(durDataShort)
head(durDataShort)}
Run the code above in your browser using DataLab