adjpin | R Documentation |
Estimates the Adjusted Probability of Informed Trading
(adjPIN
) as well as the Probability of Symmetric Order-flow Shock
(PSOS
) from the AdjPIN
model of Duarte and Young(2009).
adjpin(data, method = "ECM", initialsets = "GE", num_init = 20,
restricted = list(), ..., verbose = TRUE)
data |
A dataframe with 2 variables: the first corresponds to buyer-initiated trades (buys), and the second corresponds to seller-initiated trades (sells). |
method |
A character string referring to the method
used to estimate the model of \insertCiteDuarte09;textualPINstimation.
It takes one of two values: |
initialsets |
It can either be a character string referring to
prebuilt algorithms generating initial parameter sets or a dataframe
containing custom initial parameter sets.
If |
num_init |
An integer specifying the maximum number of
initial parameter sets to be used in the estimation.
If |
restricted |
A binary list that allows estimating restricted
AdjPIN models by specifying which model parameters are assumed to be equal.
It contains one or multiple of the following four elements
|
... |
Additional arguments passed on to the function |
verbose |
A binary variable that determines whether
detailed information about the steps of the estimation of the AdjPIN model
is displayed. No output is produced when |
The argument 'data' should be a numeric dataframe, and contain
at least two variables. Only the first two variables will be considered:
The first variable is assumed to correspond to the total number of
buyer-initiated trades, while the second variable is assumed to
correspond to the total number of seller-initiated trades. Each row or
observation correspond to a trading day. NA
values will be ignored.
If initialsets
is neither a dataframe, nor a character string from the
set {"GE",
"CL",
"RANDOM"}
, the estimation of the AdjPIN
model is
aborted. The default initial parameters ("GE"
) for the estimation
method are generated using a modified hierarchical agglomerative
clustering. For more information, see initials_adjpin()
.
The argument hyperparams
contains the hyperparameters of the ECM
algorithm. It is either empty or contains one or two of the following
elements:
maxeval
: (integer
) It stands for maximum number of iterations of
the ECM
algorithm for each initial parameter set. When missing, maxeval
takes the default value of 100
.
tolerance
(numeric
) The ECM
algorithm is stopped when the
(relative) change of log-likelihood is smaller than tolerance. When
missing, tolerance
takes the default value of 0.001
.
Returns an object of class estimate.adjpin
.
# We use 'generatedata_adjpin()' to generate a S4 object of type 'dataset'
# with 60 observations.
sim_data <- generatedata_adjpin(days = 60)
# The actual dataset of 60 observations is stored in the slot 'data' of the
# S4 object 'sim_data'. Each observation corresponds to a day and contains
# the total number of buyer-initiated transactions ('B') and seller-
# initiated transactions ('S') on that day.
xdata <- sim_data@data
# ------------------------------------------------------------------------ #
# Compare the unrestricted AdjPIN model with various restricted models #
# ------------------------------------------------------------------------ #
# Estimate the unrestricted AdjPIN model using the ECM algorithm (default),
# and show the estimation output
estimate.adjpin.0 <- adjpin(xdata, verbose = FALSE)
show(estimate.adjpin.0)
# Estimate the restricted AdjPIN model where mub=mus
estimate.adjpin.1 <- adjpin(xdata, restricted = list(mu = TRUE),
verbose = FALSE)
# Estimate the restricted AdjPIN model where eps.b=eps.s
estimate.adjpin.2 <- adjpin(xdata, restricted = list(eps = TRUE),
verbose = FALSE)
# Estimate the restricted AdjPIN model where d.b=d.s
estimate.adjpin.3 <- adjpin(xdata, restricted = list(d = TRUE),
verbose = FALSE)
# Compare the different values of adjusted PIN
estimates <- list(estimate.adjpin.0, estimate.adjpin.1,
estimate.adjpin.2, estimate.adjpin.3)
adjpins <- sapply(estimates, function(x) x@adjpin)
psos <- sapply(estimates, function(x) x@psos)
summary <- cbind(adjpins, psos)
rownames(summary) <- c("unrestricted", "same.mu", "same.eps", "same.d")
show(round(summary, 5))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.