Based on the algorithm in
Ersan (2016)
, generates
initial parameter sets for the maximum likelihood estimation of the MPIN
model.
Arguments
- 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
layers
isNULL
, then the number of layers is automatically determined by one of the following functions:detectlayers_e()
,detectlayers_eg()
, anddetectlayers_ecm()
. The default value isNULL
.- 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:
"E"
,"EG"
, and"ECM"
."E"
refers to the algorithm in Ersan (2016) ,"EG"
refers to the algorithm in Ersan and Ghachem (2022a) ; while"ECM"
refers to the algorithm in Ghachem and Ersan (2022a) . The default value is"EG"
. Comparative results between the layer detection algorithms can be found in Ersan and Ghachem (2022a) .- xtraclusters
An integer used to divide trading days into
#(1 + layers + xtraclusters)
clusters, thereby resulting in#comb(layers + xtraclusters, layers)
initial parameter sets in line with Ersan and Alici (2016) , and Ersan (2016) . The default value is4
as chosen in Ersan (2016) .- 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
verbose
is set toFALSE
. The default value isTRUE
.
Value
Returns a dataframe of initial parameter sets each consisting of
3J + 2
variables {\(\alpha\), \(\delta\), \(\mu\), \(\epsilon\)b, \(\epsilon\)s}.
\(\alpha\), \(\delta\), and \(\mu\) are vectors of length J
where
J
is the number of layers in the MPIN
model.
Details
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.
References
Ersan O (2016).
“Multilayer Probability of Informed Trading.”
Available at SSRN 2874420.
Ersan O, Alici A (2016).
“An unbiased computation methodology for estimating the probability of informed trading (PIN).”
Journal of International Financial Markets, Institutions and Money, 43, 74--94.
ISSN 10424431.
Ersan O, Ghachem M (2022a).
“Identifying information types in probability of informed trading (PIN) models: An improved algorithm.”
Available at SSRN 4117956.
Ghachem M, Ersan O (2022a).
“Estimation of the probability of informed trading models via an expectation-conditional maximization algorithm.”
Available at SSRN 4117952.
Examples
# 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))
#> 1 2 3 4 5 6
#> alpha.1 0.117 0.117 0.117 0.117 0.217 0.217
#> alpha.2 0.100 0.150 0.217 0.533 0.050 0.117
#> alpha.3 0.533 0.483 0.417 0.100 0.483 0.417
#> delta.1 0.286 0.286 0.286 0.286 0.231 0.231
#> delta.2 0.167 0.333 0.231 0.125 0.667 0.286
#> delta.3 0.094 0.034 0.040 0.000 0.034 0.040
#> mu.1 561.018 561.018 561.018 561.018 599.484 599.484
#> mu.2 644.362 762.236 973.023 1286.969 997.986 1254.732
#> mu.3 1462.722 1510.798 1520.959 1581.709 1510.798 1520.959
#> eps.b 336.143 336.143 336.143 336.143 336.143 336.143
#> eps.s 336.185 336.185 336.185 336.185 336.185 336.185
# 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),]
# \donttest{
estimate <- mpin_ecm(xdata, initialsets = selectedsets, verbose = FALSE)
# Display the estimated MPIN value
show(estimate@mpin)
#> [1] 0.5744481
# Display the estimated parameters as a numeric vector.
show(unlist(estimate@parameters))
#> alpha.layer.1 alpha.layer.2 alpha.layer.3 delta.layer.1 delta.layer.2
#> 2.166667e-01 5.000000e-02 4.833333e-01 2.307692e-01 6.666667e-01
#> delta.layer.3 mu.layer.1 mu.layer.2 mu.layer.3 eps.b
#> 3.448276e-02 6.028381e+02 9.864245e+02 1.506785e+03 3.369193e+02
#> eps.s
#> 3.358877e+02
# Store the posterior probabilities in a variable, and show the first 6 rows.
modelposteriors <- get_posteriors(estimate)
show(round(head(modelposteriors), 3))
#> post.N post.G[1] post.G[2] post.G[3] Post.B[1] Post.B[2] Post.B[3]
#> 1 1 0 0 0 0 0 0
#> 2 0 1 0 0 0 0 0
#> 3 0 0 1 0 0 0 0
#> 4 0 1 0 0 0 0 0
#> 5 0 1 0 0 0 0 0
#> 6 0 1 0 0 0 0 0
# }