# 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),]
# \donttest{
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))
# }
Run the code above in your browser using DataLab