initials_mpin | R Documentation |
Based on the algorithm in
\insertCiteErsan2016;textualPINstimation, generates
initial parameter sets for the maximum likelihood estimation of the MPIN
model.
initials_mpin(data, layers = NULL, detectlayers = "EG",
xtraclusters = 4, 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). |
layers |
An integer referring to the assumed number of
information layers in the data. If the value of |
detectlayers |
A character string referring to the layer
detection algorithm used to determine the number of layers in the data. It
takes one of three values: |
xtraclusters |
An integer used to divide trading days into
|
verbose |
a binary variable that determines whether information messages
about the initial parameter sets, including the number of the initial
parameter sets generated. No message is shown 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.
Returns a dataframe of initial parameter sets each consisting of
3J + 2
variables {\alpha
, \delta
, \mu
, \eb, \es}.
\alpha
, \delta
, and \mu
are vectors of length J
where
J
is the number of layers in the MPIN
model.
# There is a preloaded quarterly dataset called 'dailytrades' with 60
# observations. Each observation corresponds to a day and contains the
# total number of buyer-initiated trades ('B') and seller-initiated
# trades ('S') on that day. To know more, type ?dailytrades
xdata <- dailytrades
# Obtain a dataframe of initial parameter sets for estimation of the MPIN
# model using the algorithm of Ersan (2016) with 3 extra clusters.
# By default, the number of layers in the data is detected using the
# algorithm of Ersan and Ghachem (2022a).
initparams <- initials_mpin(xdata, xtraclusters = 3, verbose = FALSE)
# Show the six first initial parameter sets
print(round(t(head(initparams)), 3))
# Use 10 randomly selected initial parameter sets from initparams to
# estimate the probability of informed trading via mpin_ecm. The number
# of information layers will be detected from the initial parameter sets.
numberofsets <- nrow(initparams)
selectedsets <- initparams[sample(numberofsets, 10),]
estimate <- mpin_ecm(xdata, initialsets = selectedsets, verbose = FALSE)
# Display the estimated MPIN value
show(estimate@mpin)
# Display the estimated parameters as a numeric vector.
show(unlist(estimate@parameters))
# Store the posterior probabilities in a variable, and show the first 6 rows.
modelposteriors <- get_posteriors(estimate)
show(round(head(modelposteriors), 3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.