Estimates the Volume-Synchronized Probability of Informed Trading as developed in Easley et al. (2011) and Easley et al. (2012) .
Usage
vpin(data, timebarsize = 60, buckets = 50, samplength = 50,
tradinghours = 24, verbose = TRUE)
Arguments
- data
A dataframe with 3 variables:
{timestamp, price, volume}
.- timebarsize
An integer referring to the size of timebars in seconds. The default value is
60
.- buckets
An integer referring to the number of buckets in a daily average volume. The default value is
50
.- samplength
An integer referring to the sample length or the window size used to calculate the
VPIN
vector. The default value is50
.- tradinghours
An integer referring to the length of daily trading sessions in hours. The default value is
24
.- verbose
A binary variable that determines whether detailed information about the steps of the estimation of the VPIN model is displayed. No output is produced when
verbose
is set toFALSE
. The default value isTRUE
.
Details
The dataframe data should contain at least three variables. Only the
first three variables will be considered and in the following order
{timestamp, price, volume}
.
The property @bucketdata
is created as in
Abad and Yague (2012)
.
The argument timebarsize
is in seconds enabling the user to implement
shorter than 1
minute intervals. The default value is set to 1
minute
(60
seconds) following Easley et al. (2011, 2012).
The parameter tradinghours
is used to eventually correct the duration per
bucket. The duration of a given bucket is the difference between the
timestamp of the last trade endtime
and the timestamp of the first trade
stime
in the bucket. If the first trade and the last trade in a
bucket occur in two different days, and the market trading session does not
cover a full day (24 hours)
; then the duration of the bucket will be
inflated. Assume that the daily trading session is 8 hours
(tradinghours=8)
, the start time of a bucket is 2018-10-12 17:06:40
and its end time is 2018-10-13 09:36:00
. A straightforward calculation
gives that the duration of this bucket is 59,360 secs
. However, this
duration includes the time during which the market is closed (16 hours)
.
The corrected duration takes into consideration only the time of market
activity: duration=59,360-16*3600= 1760 secs
, i.e., about 30 minutes
.
References
Abad D, Yague J (2012).
“From PIN to VPIN: An introduction to order flow toxicity.”
The Spanish Review of Financial Economics, 10(2), 74--83.
Easley D, De Prado MML, Ohara M (2011).
“The microstructure of the \" flash crash\": flow toxicity, liquidity crashes, and the probability of informed trading.”
The Journal of Portfolio Management, 37(2), 118--128.
Easley D, Lopez De Prado MM, OHara M (2012).
“Flow toxicity and liquidity in a high-frequency world.”
Review of Financial Studies, 25(5), 1457--1493.
ISSN 08939454.
Examples
# There is a preloaded dataset called 'hfdata' contained in the package.
# It is an artificially created high-frequency trading data. The dataset
# contains 100 000 trades and five variables 'timestamp', 'price',
# 'volume', 'bid' and 'ask'. For more information, type ?hfdata.
xdata <- hfdata
# Estimate VPIN model, using the following parameter set where the time
# bar size is 5 minutes, i.e., 300 seconds (timebarsize = 300), 50
# buckets per average daily volume (buckets = 50), and a window size of
# 250 for the VPIN calculation (samplength = 250).
estimate <- vpin(xdata, timebarsize = 300, buckets = 50, samplength = 250)
#> [+] VPIN Estimation started.
#> |-[1] Checking and preparing the data...
#> |-[2] Creating 300-second timebars...[~ 2 seconds]
#> |-[3] Calculating Volume Bucket Size (VBS) and Sigma(DP)...
#> |-[4] Breaking up large 300-second timebars' volume...
#> Error in mutate(., cum_duration = cumsum(duration), lag_cum_duration = lag(cum_duration, default = 0)): could not find function "mutate"
# Display a description of the estimate
show(estimate)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'show': object 'estimate' not found
# Plot the estimated VPIN vector
plot(estimate@vpin, type = "l", xlab = "time", ylab = "VPIN", col = "blue")
#> Error in eval(expr, envir, enclos): object 'estimate' not found
# Display the parameters of VPIN estimates
show(estimate@parameters)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'show': object 'estimate' not found
# Store the computed data of the different buckets in a dataframe 'buckets'.
# Display the first 10 rows of the dataframe 'buckets'.
buckets <- estimate@bucketdata
#> Error in eval(expr, envir, enclos): object 'estimate' not found
show(head(buckets, 10))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'show': object 'buckets' not found
# Store the daily VPIN values (weighted and unweighted) in a dataframe
# 'dayvpin'.
# Display the first 10 rows of the dataframe 'dayvpin'.
dayvpin <- estimate@dailyvpin
#> Error in eval(expr, envir, enclos): object 'estimate' not found
show(head(dayvpin, 10))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'show': object 'dayvpin' not found