Skip to contents

Estimates the Probability of Informed Trading (PIN) using Bayesian Gibbs sampling as in Griffin et al. (2021) and the initial sets from the algorithm in Ersan and Alici (2016) .


pin_bayes(data, xtraclusters = 4, sweeps = 1000, burnin = 500,
                 prior.a = 1, prior.b = 2, verbose = TRUE)



A dataframe with 2 variables: the first corresponds to buyer-initiated trades (buys), and the second corresponds to seller-initiated trades (sells).


An integer used to divide trading days into #(2 + xtraclusters) clusters, thereby resulting in #comb(1 + xtraclusters, 1) initial parameter sets in line with Ersan and Alici (2016) . The default value is 4.


An integer referring to the number of iterations for the Gibbs Sampler. This has to be large enough to ensure convergence of the Markov chain. The default value is 1000.


An integer referring to the number of initial iterations for which the parameter draws should be discarded. This is to ensure that we keep the draws at the point where the MCMC has converged to the parameter space in which the parameter estimate is likely to fall. This figure must always be less than the sweeps. The default value is 500.


An integer controlling the mean number of informed trades, such as the prior of informed buys and sells is the Gamma density function with \(\mu\) ~ Ga(prior.a, \(\eta\)). The default value is 1. For more details, please refer to Griffin et al. (2021) .


An integer controlling the mean number of uninformed trades, such as the prior of uninformed buys and sells is the Gamma density function with \(\epsilon\)b ~ Ga(prior.b, \(\eta\)), and \(\epsilon\)s ~ Ga(prior.b, \(\eta\)). The default value is 2. For more details, please refer to Griffin et al. (2021) .


A binary variable that determines whether detailed information about the steps of the estimation of the PIN model is displayed. No output is produced when verbose is set to FALSE. The default value is TRUE.


Returns an object of class


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.

The function pin_bayes() implements the algorithm detailed in Ersan and Alici (2016) . The higher the number of the additional clusters (xtraclusters), the better is the estimation. Ersan and Alici (2016) , however, have shown the benefit of increasing this number beyond 5 is marginal, and statistically insignificant.

The function initials_pin_ea() provides the initial parameter sets obtained through the implementation of the Ersan and Alici (2016) algorithm. For further information on the initial parameter set determination, see initials_pin_ea().


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.

Griffin J, Oberoi J, Oduro SD (2021). “Estimating the probability of informed trading: A Bayesian approach.” Journal of Banking & Finance, 125, 106045.


# Use the function generatedata_mpin() to generate a dataset of
# 60 days according to the assumptions of the original PIN model.

sdata <- generatedata_mpin(layers = 1)
xdata <- sdata@data

# Estimate the PIN model using the Bayesian approach developed in
# Griffin et al. (2021), and initial parameter sets generated using the
# algorithm of Ersan and Alici (2016). The argument xtraclusters is
# set to 1. We also leave the arguments 'sweeps' and 'burnin' at their
# default values.
# \donttest{
estimate <- pin_bayes(xdata, xtraclusters = 1, verbose = FALSE)

# Display the empirical PIN value at the data, and the PIN value
# estimated using the bayesian approach

setNames(c(, estimate@pin), c("data", "estimate"))
#>       data   estimate 
#> 0.09952897 0.09828283 

# Display the empirial and the estimated parameters

#>        alpha        delta           mu        eps.b        eps.s 
#>    0.9500000    0.2982456  543.3565891 2178.5000000 2491.6279070 
#>        alpha        delta           mu        eps.b        eps.s 
#>    0.9355609    0.3017664  544.0439733 2178.9130334 2490.8920330 

# Find the initial set that leads to the optimal estimate
optimal <- which.max(estimate@details$likelihood)

# Store the matrix of Monte Carlo simulation for the optimal
# estimate, and display its last five rows

mcmatrix <- estimate@details$markovmatrix[[optimal]]
show(tail(mcmatrix, 5))
#>                alpha     delta       mu    eps.b    eps.s        PIN
#> sweep.996  0.8832949 0.3002861 560.6728 2180.076 2480.667 0.09605141
#> sweep.997  0.9516718 0.2902960 561.8070 2170.475 2482.992 0.10305380
#> sweep.998  0.9721418 0.2846517 562.1195 2168.186 2479.898 0.10519881
#> sweep.999  0.9107871 0.1989271 562.1673 2163.602 2493.339 0.09905573
#> sweep.1000 0.9586183 0.2998332 568.3618 2179.672 2483.822 0.10460962

# Display the summary of Geweke test for the Monte Carlo matrix above.
#>               mean geweke.z-score geweke.p-value
#> alpha 9.355609e-01  0.030183187     -0.1958055     0.42238119
#> delta 3.017664e-01  0.059844082      1.6181527     0.05281485
#> mu    5.440440e+02 10.576046345      0.5995463     0.27440431
#> eps.b 2.178913e+03  8.682568277      1.0083589     0.15664110
#> eps.s 2.490892e+03  7.063115245      1.1008466     0.13548170
#> PIN   9.827154e-02  0.003368919     -0.2689427     0.39398687
# }