Markov Chain Monte Carlo Algorithms for Bayesian Estimation of Microstructure Models

Computational Appendix to "Liquidity in the futures pits:
    Inferring market dynamics from incomplete data"

Joel Hasbrouck
May, 2002

Introduction

This appendix describes the Markov Chain Monte Carlo (MCMC) estimation of microstructure models with bid/ask spreads, discreteness, clustering and trade impacts. In all cases, the data are presumed to consist solely of trade prices and (optionally) trade volumes. The exposition discusses models of increasing complexity. The appendix is distributed in two forms: a text document, and a Mathematica notebook in which derivations are interspersed with the text.

The appendix presumes some exposure to Bayesian MCMC techniques. Textbook level discussions are given in Carlin and Louis (1996), Tanner (1996), Gamerman (1997), and Kim and Nelson (2000). Casella and George (1992), Chib and Greenberg (1995), and Chib and Greenberg (1996) also provide useful expositions.

(Mathematica initializations)

Evaluate this section first.

Miscellaneous intializations

Standard packages

Turn off spelling warnings.

The following defines a transormation that formats " -> " as "=". (It just reworks the rule into a more familiar notation.)

RuleToEquals = 
        Rule[a_, b_] :> 
          HoldForm[
            HoldForm[a] "=" HoldForm[b]];
  
{c -> 4, d -> 3} /. RuleToEquals // TableForm

Normal density and distribution functions

The expression ϕ[μ, σ, x] denotes the normal density function for random variable x, with mean μ and standard deviation σ. The following rule expands this definition.

For example,

ϕ[m, s, z] /. ϕDef

Similarly, the expression Φ[μ, σ, a, 
          b] ≡ (∫_a^b) ϕ[μ, σ, 
              x] dx , i.e., the cumulative normal distribution function evaluated between a and b. The following rule replaces this with the formula:

For example,

Φ[2, 1, 1.5, 1.8] /. ΦDef

The following rule is useful to tell Mathematica that (Subscript[σ, u]) is a real, positive number.

Finding the parameters of a normal density.

Sometimes we have a density that we know is proportional to a normal density, but working out the exact correspondence is algebraically tedious. In such situations, the following function (GetNormalForm) is useful.  That is, given a random variable v and its density function f (which is assumed proportional to a normal density), GetNormalForm finds μ and σ such that v is normal with mean μ and standard deviation σ. Traditionally, this is done by "completing the square" of the exponent of e.  Mathematica's symbolic equation solving makes the process easier.

For example suppose we know that a density f(z) is normal and proportional to (e^(((-(z^2))/10) + (z/3))). Then

GetNormalForm[(E^(((-(z^2))/10) + (z/3))), z]

or

GetNormalForm[(E^(((-(z^2))/10) + (z/3))), z, MyMean, MySD]

gives the mean and standard deviation for the distribution.  The implied density is

ϕ[MyMean, MySD, z] /. ϕDef /. %

Notation and conventions

A time-series variable written without a time subscript denotes the full sample, e.g., q = {(Subscript[q, 1]), (Subscript[q, 2]),  ... , (Subscript[q, T])}. The subscript "\(TraditionalForm\`\(\(\\)\(t\)\)\)" indicates the full sample except for the observation at time t, e.g., \(TraditionalForm\`q\_\(\(\\)\(t\)\) = {q\_1,  ... , q\_\(t - 1\), 
          q\_\(t + 1\),  ... , q\_T}\).

"Draw x | y, z" is shorthand for "draw x from f(x | y, z)."

The expression ϕ[μ, σ, x] denotes the normal density function for random variable x, with mean μ and standard deviation σ. For example, we denote the normal density for a random variable z with mean m and standard deviation s as ϕ(m,  s,  z). Fully expanded,

ϕ(m, s, z)=\(e\^\(-\(\((z - m)\)\^2\/\(2\ s\^2\)\)\)\/\(\@\(2\ π\)\ s\)\)

Similarly, the expression Φ[μ, σ, a, 
          b] ≡ (∫_a^b) ϕ[μ, σ, 
              x] dx , i.e., the cumulative normal distribution function evaluated between a and b.

Basic Roll model

Model description

The basic Roll model is:

(Subscript[m, t]) = (Subscript[m, t - 1]) + (Subscript[u, t]) where (Subscript[u, t]) is distributed as N(0,(Subscript[σ, u]^2))
(Subscript[p, t]) = (Subscript[m, t]) + c (Subscript[q, t])

where (Subscript[m, t]) is the log efficient price, (Subscript[q, t]) is the buy/sell (trade direction) indicator variable, (Subscript[q, t]) ∈ {-1, +1}, c is the is the half-spread, and (Subscript[p, t]) is the log transaction price. The increment to the log efficient price, (Subscript[u, t])~N(0, (Subscript[σ, u]^2)); c and (Subscript[σ, u]^2) are constant parameters. The (Subscript[q, t]) are independent of (Subscript[u, t]) = Δ (Subscript[m, t]), so trade directions are not informative.
	The data consist of a sample of (log) transaction prices p = {(Subscript[p, 1]),  ... , (Subscript[p, T])}. The Gibbs sampler iterates over parameter draws and latent data draws. There are two parameters in the model, {(Subscript[σ, u]), c}. There are 2  T latent data items, {q, m}.

Moment estimates

The price difference is

Δ (Subscript[p, t]) = 
        (Subscript[u, t]) + c Δ (Subscript[q, t])

The variance and first-order autocovariance are:

\(TraditionalForm\`γ\_0 ≡ 
          Var(Δ p\_t) = \(σ\_u\%2 + \(c\^2\) \(Var(Δ q\_t)\) = σ\_u\%2 + 
            2  c\^2\)\)
	\(TraditionalForm\`γ\_1 ≡ 
          Cov(Δ p\_t, Δ p\_\(t - 1\)) = \(\(c\^2\) 
            EΔ \(q\_t\) Δ q\_\(t - 1\) = \(-c\^2\)\)\)

Solving:

(Subscript[σ, u]^2) = (Subscript[γ, 0]) + 2  (Subscript[γ, 1]) and c = (Sqrt[-(Subscript[γ, 1])])

Note that Mathematica returns complex solutions

MomentSolutions = 
      Solve[{(Subscript[γ, 0]) == (Subscript[σ, u]^2) + 
              2  (c^2), (Subscript[γ, 1]) == -(c^2)}, {c, (Subscript[σ, u])}]

Here are the solutions for (Subscript[σ, u]^2) and c:

Union[
      Simplify[{(Subscript[σ, u]^2), c} /. 
          MomentSolutions, {(Subscript[γ, 1]) ∈ Reals, (Subscript[γ, 1]) < 0, 
          c ∈ Reals}]]

Overview of the Bayesian sampler

In the Gibbs sampler, we start with any feasible set of values (a sample path) for q. We then iterate over

1. Parameter draw. Generate a random draw of c, (Subscript[σ, u]) | p, m, q.

2. Latent data draw. Generate a random draw of m, q | c, (Subscript[σ, u]), p.

In the parameter draw, we condition on the most-recently drawn values of the latent data; in the latent data draw, we condition on the most recent parameter draw. We now discuss each of these draws in greater detail.

Parameter draws

The prior and posterior densities for the parameters are standard Bayesian results covered in most basic treatments, such as Carlin and Louis (1997), Tanner (1997).  Kim and Nelson (2000) discuss these results in a state-space context.

The draw for c.

Given all of the other parameters and latent data \(TraditionalForm\`Δ p\_t = Δ m\_t + 
          c Δ q\_t\). Therefore, c can be interpreted as the coefficient in the regression specification

Δ (Subscript[p, t]) = 
        c Δ (Subscript[q, t]) + (Subscript[u, t]).

The classic Bayesian regression model is

y = Xβ + u, where \(TraditionalForm\`E u u\^′ = Ω\_u\).

If the prior distribution on the coefficients is normal: \(TraditionalForm\`β~\(N(μ\_β\%Prior, Ω\_β\%Prior)\)\), then the posterior distribution for the coefficients is \(TraditionalForm\`β | 
        y~\(N(μ\_β\%Posterior, Ω\_β\%Posterior)\)\), where (Subscript[μ, β]^Posterior) = D d, (Subscript[Ω, β]^Posterior) = (D^(-1)), \(TraditionalForm\`D\^\(-1\) = \(X\^′\) \(Ω\_u\%\(-1\)\) 
            X + \((Ω\_β\%Prior)\)\^\(-1\)\) and \(TraditionalForm\`d = \(X\^′\) \(Ω\_u\%\(-1\)\) 
            y + \(\((Ω\_β\%\(P  rior\))\)\^\(-1\)\) μ\_β\%Prior\).

In the present case, y = [Δ (Subscript[p, t])], the column vector of price changes, X = [Δ (Subscript[q, t])], and Ω = (Subscript[σ, u]^2). We might take (Subscript[μ, β]^Prior) = 0, and (Subscript[Ω, β]^Prior)=some large number like (10^6). We would then compute \(TraditionalForm\`μ\_β\%Posterior\ and\ Ω\_β\%Posterior\), and make a random draw from the coefficient posterior.

On economic grounds, it is sensible to impose a non-negativity restriction on c. The easiest way to do this is to let the prior be \(TraditionalForm\`c~\(\(N\^+\)(0, Ω\_c\%Prior)\)\), where the "+" superscript denotes restriction of the density to [0, +∞). The posterior is then \(TraditionalForm\`\(N\^+\)(μ\_c\%Posterior, Ω\_c\%Posterior)\), where the parameters are computed exactly as in the unrestricted case.

(The nonnegativity restriction on c is attractive from an economic perspective. It is also necessary for identification. The regression in eq. () is observationally equivalent if c  and  q are replaced with -c and  - q.)

The draw for (Subscript[σ, u])

With normal (Subscript[u, t]), a natural prior for (Subscript[σ, u]^2) is the inverted gamma distribution, denoted IG[(α^Prior), (β^Prior)]. Then, given u = {(Subscript[u, 1]),  ... , (Subscript[u, T])}, the posterior is IG[(α^Posterior), (β^Posterior)], where (α^Posterior) = (α^Prior) + T/2 and \(TraditionalForm\`β\^Posterior = β\^Prior + Σ u\_t\%2/2\).

Latent data draws

There are two latent series, q and m, but one of these is redundant. (The p are known, and p = m + c q.) It suffices therefore to draw q | p, c, (Subscript[σ, u]). At this stage, c and (Subscript[σ, u]) are known, so for notational economy, these parameters will be dropped from the explicit conditioning set. To set up the draw:

Pr(q | p)=f(p | q)×Pr(q)×(1/(f(p)))

Since the q are discrete random variables and the p are continuous, the joint distribution is written as f(p | q)×(Pr(q) to avoid writing an improper density function like "f(p, q)". In eq. () the last factor does not depend on q. Furthermore, since buys and sells are unconditionally equally probable, Pr(q) = (((1/2))^T). Therefore:

Pr(q | p)∝f(p | q)=\(\(f(m)\)\( | \_\(m = p - c q\)\)\)

where f(m) is the unconditional distribution of the m. From the structure of the model, f(
          m) = f((Subscript[m, 1])) (∏_(t = 2)^T) f((Subscript[u, t])) where (Subscript[u, t]) = Δ (Subscript[m, t]). The distribution of the initial realization of m is taken as uniform in the region of interest, so this can be impounded into the constant of proportionality.

The direct approach to making the draw would be to enumerate all possible sample paths for q, compute the unnormalized (i.e., up to the factor of proportionality) probabilities; normalize. Finally, we'd make the draw on the resulting discrete probability space. Given that the number of sample paths is (2^T), the direct approach is not feasible.

Fortunately, it is not necessary to fully characterize Pr(q | p) to make the draw. The next section describes a Gibbs sampler approach to the problem.

The Gibbs sampler

At this stage, we assume that c and (Subscript[σ, u]) are known, so for notational economy, these parameters will be dropped from the explicit conditioning set. Furthermore, since the p are known, given q, the m are redundant. In the Gibbs sampler, (Subscript[q, t]) draws are made sequentially. To distinguish the newly drawn (Subscript[q, t]) from those left over from the previous draw, I denote the newly drawn values \(TraditionalForm\`\(q\_t\%*\)\). The steps are then:

1. \(TraditionalForm\`Draw\ \(q\_1\%*\) 
        from\ \(Pr(q\_1 | p, q\_2, q\_3,  ... , q\_T)\)\)

2. \(TraditionalForm\`Draw\ \(q\_2\%*\) 
        from\ \(Pr(q\_2 | p, \(q\_1\%*\), q\_3,  ... , q\_T)\)\)

⋮

3. \(TraditionalForm\`Draw\ \(q\_T\%*\)\ from\ \(Pr(
          q\_T | p, \(q\_1\%*\), \(q\_2\%*\),  ... , \(q\_\(T - 
                1\)\%*\))\)\)

Note that at each step, we use the fresh \(TraditionalForm\`\(q\_t\%*\)\) as they become available. The individual draws all follow a similar pattern. We will first consider the general case, the draw for \(TraditionalForm\`q\_t | p, q\_\(\(\\)\(t\)\)\) for 1 < t < T. The endpoint draws (at t = 1 and t = T) follow as simple modifications.

Given the structure of the model, \(Pr(q\_t | p, q\_\(\(\\)\(t\)\)) = 
            Pr(q\_t | p\_t, m\_\(t - 1\), m\_\(t + 1\))\). That is, once we know (Subscript[p, t]), (Subscript[m, t - 1]), and (Subscript[m, t + 1]), the additional variables in the full conditioning set are not informative. To analyze Pr((Subscript[q, t]) | (Subscript[p, t]), (Subscript[m, t - 1]), (Subscript[m, t + 1])), note that by conventional conditional probability calculations

Pr((Subscript[q, t]) | (Subscript[p, t]), (Subscript[m, t - 1]), (Subscript[m, t + 1]))=((f((Subscript[p, t]) | (Subscript[q, t]),  (Subscript[m, t - 1]),  
                  (Subscript[m, t + 1])) ×Pr((Subscript[q, t]) | (Subscript[m, t - 1]), 
                  (Subscript[m, t + 1])))/(f((Subscript[p, t]) | (Subscript[m, t - 1]), 
                (Subscript[m, t + 1]))))

When we actually need to evaluate this, (Subscript[p, t]) is known, so the denominator can be treated as a proportionality constant. Next, because the trade directions are independent of the efficient price evolution, Pr((Subscript[q, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]))=Pr((Subscript[q, t]))=1/2. Therefore,

Pr((Subscript[q, t]) | (Subscript[p, t]), (Subscript[m, t - 1]), 
          (Subscript[m, t + 1])) ∝ 
        f((Subscript[p, t]) | (Subscript[q, t]), (Subscript[m, t - 1]), (Subscript[m, t + 1])).

To evaluate the r.h.s., note that

f((Subscript[m, t]) | (Subscript[m, t - 1]), 
            (Subscript[m, t + 1])) ∝ f((Subscript[m, t + 1]) | (Subscript[m, t])) f(
              (Subscript[m, t]) | (Subscript[m, t - 1])) = ϕ(0, (Subscript[σ, u]), 
            (Subscript[m, t]) - (Subscript[m, t - 1])) ϕ(0, (Subscript[σ, u]), 
            (Subscript[m, t + 1]) - (Subscript[m, t]))

The last expression is:

ff = ϕ[0, (Subscript[σ, u]), (Subscript[u, t])] ϕ[0, (Subscript[σ, u]), 
              (Subscript[u, t + 1])] /. 
          (Subscript[u, t])_ -> (Subscript[m, t]) - (Subscript[m, t - 1]) /. ϕDef

This implies

f((Subscript[m, t]) | (Subscript[m, t - 1]), 
        (Subscript[m, t + 1])) = ϕ((Subscript[μ, t]), (Subscript[σ, t]), 
        (Subscript[m, t]))

where

mParams = 
        GetNormalForm[ff, 
          (Subscript[m, t]), (Subscript[μ, t]), (Subscript[σ, t])];
mParams /. RuleToEquals // TableForm

Since (Subscript[p, t]) = (Subscript[m, t]) + c (Subscript[q, t]),

f((Subscript[p, t]) | (Subscript[q, t]), (Subscript[m, t - 1]), 
            (Subscript[m, t + 1])) = ϕ((Subscript[μ, t]), (Subscript[σ, t]), 
            (Subscript[p, t]) - c (Subscript[q, t]))

PQ = ϕ[(Subscript[μ, t]), (Subscript[σ, t]), (Subscript[p, t]) - c (Subscript[q, t])] /. 
          mParams;
((PQ /. (Subscript[q, t]) -> +1)/((PQ /. (Subscript[q, t]) -> +1) + (PQ /. (Subscript[q, t]) -> -1)))

This simplifies to

% /. ϕDef // Simplify

Given (Subscript[p, t]),  (Subscript[m, t - 1]),  (Subscript[m, t + 1]),  
      c and (Subscript[σ, u]^2),  
      we can compute this and make the draw. For example, with {(Subscript[m, t - 1]) = 5, (Subscript[m, t + 1]) = 5.1`, (Subscript[p, t]) = 5.2`, 
        c = 0.2, (Subscript[σ, u]) = 0.4`}, the probability of a buy is 0.679. Intuitively, we can rationalize this value in the following way.  Given that (Subscript[m, t - 1]) = 5 and (Subscript[m, t + 1]) = 5.1, E (Subscript[m, t]) = 5.05. That the transaction price lies above this makes it more likely that the trade was a "buy".

%  /.  {(Subscript[m, t - 1]) -> 5, (Subscript[m, t + 1]) -> 5.1, 
        (Subscript[p, t]) -> 5.20, c -> 0.2, (Subscript[σ, u]) -> 0.4}

We now consider the endpoint draws, (t = 1 and t = T), which are slightly different.

t = 1

At t = 1, the relevant conditional density is f((Subscript[m, 1]) | (Subscript[m, 2])), which is proportional to f((Subscript[m, 2]) | (Subscript[m, 1]))=ϕ(0, (Subscript[σ, u]), (Subscript[m, 2]) - (Subscript[m, 1])). Substituting in for (Subscript[m, 1]) gives ϕ(0, (Subscript[σ, u]), (Subscript[m, 2]) - (Subscript[p, 1]) + c (Subscript[q, 1])). The unnormalized probabilities for a buy and sell are given by evaluating this at (Subscript[q, 1]) = +1 and (Subscript[q, 1]) = -1. The normalized probability of a buy is:

Clear[u, σ, m, c, p, q];
PQ = ϕ[0, (Subscript[σ, u]), (Subscript[u, 2])] /. (Subscript[u, 2]) -> (Subscript[m, 2]) - (Subscript[m, 1]) /. 
          (Subscript[m, 1]) -> (Subscript[p, 1]) - c (Subscript[q, 1]);
((PQ /. (Subscript[q, 1]) -> +1)/((PQ /. (Subscript[q, 1]) -> +1) + (PQ /. (Subscript[q, 1]) -> -1)))

This simplifies to:

% /. ϕDef // Simplify

t = T

At time T we have f((Subscript[m, T]) | (Subscript[m, T - 1])) = ϕ(0, (Subscript[σ, u]), 
          (Subscript[m, T]) - (Subscript[m, T - 1])). Evaluated at (Subscript[m, T]) = (Subscript[p, T]) - c (Subscript[q, T]), this becomes  ϕ(
        0, (Subscript[σ, u]), -(Subscript[m, T - 1]) + (Subscript[p, T]) - c (Subscript[q, T])). The (unnormalized) probabilities for a buy and sell are given by evaluating this at (Subscript[q, T]) = +1 and (Subscript[q, T]) = -1. The normalized probability of a buy is:

PQ = ϕ[0, (Subscript[σ, u]), (Subscript[u, T])] /. 
            (Subscript[u, T]) -> (Subscript[m, T]) - (Subscript[m, T - 1]) /. 
          (Subscript[m, T]) -> (Subscript[p, T]) - c (Subscript[q, T]);
((PQ /. (Subscript[q, T]) -> +1)/((PQ /. (Subscript[q, T]) -> +1) + (PQ /. (Subscript[q, T]) -> -1)))

This evaluates and simplies to:

% /. ϕDef // Simplify

Contemporaneous trade impacts on the efficient price

Description

This model incorporates trade impacts on the efficient price, which are presumed to reflect the informationcontent of the trades.  The evolution of the efficient price is:

(Subscript[m, t]) = 
      (Subscript[m, t - 1]) + (Subscript[q, t]) (Subscript[V, t]) λ + 
        (Subscript[u, t])

where (Subscript[V, t]) is the volume of the trade, λ is the impact coefficient, and (Subscript[p, t]) is the observed log transaction price. The quantity (Subscript[V, t]) λ can be interpeted as a product of scalars, or a vector product, as in: (Subscript[V, t]) = [1   
            (Subscript[Vol, t])    (Sqrt[(Subscript[Vol, t])])] and λ a 3×1 vector of coefficients. As in the basic model, (Subscript[q, t]) is the trade direction indicator, +1 for a buy and -1 for a sell.  Thus (Subscript[q, t]) (Subscript[V, t]) is the signed volume. The disturbance (Subscript[u, t]) is public information, and (Subscript[u, t])~N(0,(Subscript[σ, u]^2)). The mapping to the observed price is the same as in the Roll model:

(Subscript[p, t]) = (Subscript[m, t]) + c (Subscript[q, t])

Relative to the basic Roll case discussed in the last section, this model is complicated by an additional parameter, λ, and dependence of the (Subscript[m, t]) on (Subscript[q, t]).

The parameter draw is relatively straightforward, as the model implies

\(TraditionalForm\`Δ p\_t = \(Δ m\_t + 
          c Δ q\_t = λ \(q\_t\) V\_t + 
          c Δ q\_t + 
          u\_t\)\)

At the parameter draw stage, (Subscript[q, t]) (Subscript[V, t]) and Δ (Subscript[q, t]) are known. This specification therefore fits in the regression framework, and λ and c may be drawn from the regression coefficient posterior.

The latent data draws are more complicated. Given the structure of the model,

\(TraditionalForm\`Pr[q\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
          p\_t] = Pr[q\_t | m\_\(t - 1\), m\_\(t + 1\), q\_\(t + 1\), 
          p\_t]\).

Analogous to eq. (),

Pr((Subscript[q, t]) | (Subscript[p, t]), (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[q, t + 1]))=((f((Subscript[p, t]) | (Subscript[q, t]), (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
                  (Subscript[q, t + 1])) ×Pr((Subscript[q, t]) | (Subscript[m, t - 1]), 
                  (Subscript[m, t + 1]),  (Subscript[q, t + 1])))/(f((Subscript[p, t]) | (Subscript[m, t - 1]), 
                (Subscript[m, t + 1]), (Subscript[q, t + 1]))))

As in the simple case, when we need to evaluate this, (Subscript[p, t]) is known, and so the denominator can be treated as a proportionality factor. Here, however, and in contrast with the Roll case, f((Subscript[q, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1])) ≠ f((Subscript[q, t]))=1/2. Intuitively, if (Subscript[m, t + 1])is relatively high, this implies that (Subscript[q, t]) is more likely to be +1 (a buy). Therefore, we need to compute both of the factors in the numerator of eq. ().

Pr((Subscript[q, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
      (Subscript[q, t + 1]))

The joint distribution of (Subscript[u, t]) and (Subscript[u, t + 1])is ϕ(0, (Subscript[σ, u]), (Subscript[u, t])) ϕ(
          0, (Subscript[σ, u]), (Subscript[u, t + 1])). Substituting from () gives:

TD = ϕ[0, (Subscript[σ, u]), (Subscript[u, t])] ϕ[0, (Subscript[σ, u]), (Subscript[u, t + 1])] /. 
        (Subscript[u, t])_ -> 
          (Subscript[m, t]) - ((Subscript[m, t - 1]) + (Subscript[q, t]) λ (Subscript[V, t]))

To compute Pr((Subscript[q, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
        (Subscript[q, t + 1])) , the dependence on (Subscript[m, t]) must be eliminated, which we do by integrating over (Subscript[m, t]). That is,

\(TraditionalForm\`Pr(q\_t | m\_\(t - 1\), m\_\(t + 1\), 
          q\_\(t + 1\)) ∝ ∫\_\(-∞\)\%\(+∞\)\(ϕ(
              0, σ\_u, \(-m\_\(t - 1\)\) + 
                m\_t - λ\ q\_t\ V\_t)\)\ \(ϕ(
              0, σ\_u, \(-m\_t\) + 
                m\_\(t + 1\) - λ\ q\_\(t + 1\)\ V\_\(t + 1\))\) dm\_t ≡ Pr(q\_t)\)

Evaluating the integral gives Pr((Subscript[q, t]))≡

fI = 
      Integrate[TD /. ϕDef, {(Subscript[m, t]), -∞, +∞}, 
        Assumptions -> σuAssumptions]

Performing the final normalization:

Pr((Subscript[q, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
          (Subscript[q, t + 1]))  = ((Pr((Subscript[q, t])))/(Pr(+1) + Pr(-1)))

Therefore, Pr((Subscript[q, t]) = 1 | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
          (Subscript[q, t + 1]))=

PrBuy = Pr[1]/(Pr[+1] + Pr[-1]) // Simplify

For example, at the values

TrialValues = {(Subscript[m, t - 1]) -> 5, (Subscript[m, t + 1]) -> 5.2, 
          (Subscript[V, t]) -> 1, (Subscript[q, t + 1]) -> 1, 
          (Subscript[V, t + 1]) -> 2, λ -> 0.01, (Subscript[σ, u]) -> 
            0.05};
TrialValues /. RuleToEquals

the probability of a buy is 0.673. Intuitively, given the increase in the efficient price between (Subscript[m, t - 1]) and (Subscript[m, t + 1]), it is more likely that the trade at time t was a buy.

PrqBuy1 = PrBuy /. TrialValues

f((Subscript[p, t]) | (Subscript[m, t - 1]), (Subscript[q, t]), (Subscript[m, t + 1]), 
      (Subscript[m, t + 1]), (Subscript[q, t + 1]))

As indicated above, the transition density is

ϕ(
          0, (Subscript[σ, u]), -(Subscript[m, t - 1]) + 
            (Subscript[m, t]) - λ (Subscript[q, t]) (Subscript[V, t])) ϕ(
          0, (Subscript[σ, u]), -(Subscript[m, t]) + 
            (Subscript[m, t + 1]) - λ (Subscript[q, t + 1]) (Subscript[V, t + 1])).

Expanding the normal densities and simplifying gives:

TD2 = TD /. ϕDef // Simplify

Therefore, (Subscript[m, t]) is normal:  f((Subscript[m, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[q, t]), 
          (Subscript[q, t + 1])) = ϕ((Subscript[μ, t]), (Subscript[σ, t]), (Subscript[m, t])) with parameters

mParams = 
        GetNormalForm[TD2, 
          (Subscript[m, t]), (Subscript[μ, t]), (Subscript[σ, t])];
mParams /. RuleToEquals // TableForm

Substituting in for (Subscript[m, t]) gives

f((Subscript[p, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[q, t]), 
          (Subscript[q, t + 1])) = ϕ((Subscript[μ, t]), (Subscript[σ, t]), 
          (Subscript[p, t]) - c (Subscript[q, t]))

Summary

The draw is made in the following steps.

1. Compute the normalized probabilities Pr((Subscript[q, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
        (Subscript[q, t + 1])) for (Subscript[q, t]) = -1 and (Subscript[q, t]) = +1.

2. Compute ϕ((Subscript[μ, t]), (Subscript[σ, t]), 
          (Subscript[p, t]) - c (Subscript[q, t])) Pr((Subscript[q, t]) | (Subscript[m, t - 1]), 
          (Subscript[m, t + 1]), (Subscript[q, t + 1])) for (Subscript[q, t]) = -1 and (Subscript[q, t]) = +1.

3. Normalize the probabilities from step 2.

4. Make the draw.

Note that the overall calculation requires two normalizations, at step 1 (done, above, for the trial values) and step 3.

Endpoint modifications

t = 1

At t = 1,

\(TraditionalForm\`Pr(q\_1 | m\_\1, q\_\1, p\_1)
 = 
        Pr(q\_1 | m\_2, q\_2, 
            p\_1)
 ∝ \(f(p\_1 | m\_2, q\_2, 
              q\_1)\)×\(Pr(q\_1 | m\_2, q\_2)\)\).

Here, however, Pr((Subscript[q, 1]) | (Subscript[m, 2]), (Subscript[q, 2]))=Pr((Subscript[q, 1]))=1/2. To compute the first term on the r.h.s., the relevant density is f((Subscript[u, 2])) = ϕ(0, (Subscript[σ, u]), (Subscript[u, 2])). Substituting in for (Subscript[u, 2]) and (Subscript[m, 1])and solving indicates

f((Subscript[m, 1]) | (Subscript[m, 2]), (Subscript[q, 2]), 
          (Subscript[q, 1])) = f((Subscript[m, 1]) | (Subscript[m, 2]), (Subscript[q, 2])) = ϕ((Subscript[μ, 1]), (Subscript[σ, 1]), 
            (Subscript[m, 1]))

where

m1Params = 
        GetNormalForm[ϕ[0, (Subscript[σ, u]), (Subscript[u, 2])] /. 
              (Subscript[u, 2]) -> 
                (Subscript[m, 2]) - ((Subscript[m, 1]) + 
                      (Subscript[q, 2]) λ (Subscript[V, 2])) /. ϕDef, 
          (Subscript[m, 1]), (Subscript[μ, 1]), (Subscript[σ, 1])];
m1Params /. RuleToEquals // TableForm

Thus,

f((Subscript[p, 1]) | (Subscript[m, 2]), (Subscript[q, 2]), 
          (Subscript[q, 1])) = ϕ((Subscript[μ, 1]), (Subscript[σ, 1]), 
          (Subscript[p, 1]) - c (Subscript[q, 1]))

We evaluate this. for (Subscript[q, 1]) = ±1, normalize, and make the draw of (Subscript[q, 1]).

t = T

At t = T,

\(TraditionalForm\`Pr(q\_T | m\_\(\(\\)\(T\)\), q\_\(\(\\)\(T\)\), 
          p\_T)
 = 
        Pr(q\_T | m\_\(T - 1\), q\_\(T - 1\), 
            p\_T)
 ∝ \(f(p\_T | m\_\(T - 1\), 
              q\_\(T - 1\), q\_T)\)×\(Pr(q\_T | m\_\(T - 1\), 
              q\_\(T - 1\))\)\).

Again, Pr((Subscript[q, T]) | (Subscript[m, T - 1]), (Subscript[q, T - 1]))=Pr((Subscript[q, T - 1]))=1/2. To compute the first term on the r.h.s., the relevant density is f((Subscript[u, T])) = ϕ(0, (Subscript[σ, u]), (Subscript[u, T])). Substituting in for (Subscript[u, T]) and (Subscript[m, T]) gives:

f((Subscript[m, T]) | (Subscript[m, T - 1]), (Subscript[q, T - 1]), 
          (Subscript[q, T])) = ϕ((Subscript[μ, T]), (Subscript[σ, T]), (Subscript[m, T]))

where

mTParams = 
        GetNormalForm[ϕ[0, (Subscript[σ, u]), (Subscript[u, T])] /. 
              (Subscript[u, T]) -> 
                (Subscript[m, T]) - ((Subscript[m, T - 1]) + (Subscript[q, T]) λ (Subscript[V, T])) /. ϕDef, (Subscript[m, T]), (Subscript[μ, T]), (Subscript[σ, T])];
mTParams /. RuleToEquals // TableForm

We normalize and make the draw.

Discrete prices

Model Description

This model is a Roll model with price discreteness. The evolution of the (log) efficient price is:

(Subscript[m, t]) = (Subscript[m, t - 1]) + (Subscript[u, t]) where (Subscript[u, t]) is distributed as N(0,(Subscript[σ, u]^2))

The (level) efficient price is therefore (Subscript[M, t]) = (Subscript[(e^m), t]). (The units here are "dollars.") The half-spread in levels is C. The bid and ask quotes are:

(Subscript[B, t]) = Floor((Subscript[M, t]) - C)
	(Subscript[A, t]) = Ceiling((Subscript[M, t]) + C)

Note that the rounding is asymmetric.  The bid is rounded down to the next available increment; the ask is rounded up. It is assumed that the variables are scaled so that the tick size is unity.  The buy/sell indicator is

(Subscript[q, t])={({{+1, a buy, with probability 1/2}, {-1, a sell, with probability 1/2}})
The obseved transaction price is

(Subscript[P, t])={({{(Subscript[A, t]) if (Subscript[q, t]) = +1}, {(Subscript[B, t]) if (Subscript[q, t]) = -1}})

In the model without discreteness, the cost parameter (here, C) can be estimated from the regression specification eq. (). With the rounding transformations in the present case, there is no corresponding regression. We discuss the draw of C below.

The latent data draw is also complicated. Without discreteness, (Subscript[p, t]) = (Subscript[m, t]) + c (Subscript[q, t]), so (given c) any variable in {(Subscript[p, t]), (Subscript[m, t]), (Subscript[q, t])} is determined by the other two. This is not the case here: (Subscript[q, t]) and (Subscript[m, t]) must be drawn separately. The steps are:

1. Draw \(TraditionalForm\`q\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
      P\_t\)

2. Draw \(TraditionalForm\`m\_t | m\_\(\(\\)\(t\)\), q, P\_t\)

Note that the conditioning set at step 2 includes (Subscript[q, t]).

Drawing  \(TraditionalForm\`q\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
      P\_t\)

From the properties of conditional probabilities:

Pr((Subscript[q, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[P, t]))
=((Pr((Subscript[P, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
                      (Subscript[q, t])) ×Pr((Subscript[q, t]), |(Subscript[m, t - 1]), 
                      (Subscript[m, t + 1]))×f((Subscript[m, t - 1]), 
                      (Subscript[m, t + 1])))/(Pr((Subscript[P, t]) | (Subscript[m, t - 1]), 
                      (Subscript[m, t + 1])) f((Subscript[m, t - 1]), (Subscript[m, t + 1]))))
∝Pr((Subscript[P, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
                (Subscript[q, t])) ×Pr((Subscript[q, t]), |(Subscript[m, t - 1]), 
                (Subscript[m, t + 1]))
   =Pr((Subscript[P, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
              (Subscript[q, t])) ×Pr((Subscript[q, t]))

where we have used the fact that the denominator will be a constant of proportionality. The last equality follows from the fact that (Subscript[q, t]) is independent of the evolution of (Subscript[m, t]). Next,

\(TraditionalForm\`Pr(P\_t | m\_\(t - 1\), m\_\(t + 1\), 
        q\_t) = ∫\_\(m\+_\)\%\(m\&_\)\(f(m\_t | m\_\(t - 1\), 
            m\_\(t + 1\))\) dm\_t\)

where \(TraditionalForm\`m\+_\) and \(TraditionalForm\`m\&_\) are the limits established by (Subscript[q, t]) and the Floor and Ceiling rounding functions (see below). f((Subscript[m, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1])) is given in eq. (). Using (), we compute unnormalized probabilities for (Subscript[q, t]) = +1 and (Subscript[q, t]) = -1. We normalize these probabilities and draw (Subscript[q, t]). We then proceed to the (Subscript[m, t]) draw.

The limits of integration in eq. () are computed as follows. From the definition of the Floor and Ceiling functions,

MBidLimits = 
      InequalitySolve[(Subscript[B, t]) < (Subscript[M, t]) - C < (Subscript[B, t]) + 1, (Subscript[M, t])]

and

MAskLimits = 
      InequalitySolve[(Subscript[A, t]) - 1 < (Subscript[M, t]) + C < (Subscript[A, t]), (Subscript[M, t])]

When (Subscript[q, t]) = -1, (Subscript[P, t]) = (Subscript[B, t]) and:

MBidLimits = MBidLimits /. (Subscript[B, t]) -> (Subscript[P, t])

When (Subscript[q, t]) = +1, (Subscript[P, t]) = (Subscript[A, t]) and:

MAskLimits = MAskLimits /. (Subscript[A, t]) -> (Subscript[P, t])

As long as (Subscript[q, t]) ∈ {-1, +1}, the lower and upper limits may be expressed as functions:

\(\(M\+_\)(q\_t)\) "=" ((1/2) (2 (Subscript[P, t]) - 2 C (Subscript[q, t]) - (Subscript[q, t]) - 1)) 
and 
\(\(M\&_\)(q\_t)\) "=" ((Subscript[P, t]) - (1/2) (2 C + 1) (Subscript[q, t]) + (1/2))

The limits on the log efficient price are then \(TraditionalForm\`\(m\+_\)(q\_t) = log[\(M\+_\)(q\_t)]\) and \(TraditionalForm\`\(m\&_\)(q\_t) = log[\(M\&_\)(q\_t)]\).

{MBidLimits[[1]] == a + b (Subscript[q, t]) /. (Subscript[q, t]) -> -1, 
      MAskLimits[[1]] == a + b (Subscript[q, t]) /. 
        (Subscript[q, t]) -> +1}

Flatten[Solve[%, {a, b}] // Simplify]

\(M\+_[q_] := Evaluate[a + b\ q\  /. % // FullSimplify]; 
    HoldForm[M\+_[ q\_t ]] -> M\+_[q\_t] /. 
      RuleToEquals\)

\(M\+_[q\_t] /. q\_t -> {1, \(-1\)} // Simplify\)

{MBidLimits[[5]] == a + b (Subscript[q, t]) /. (Subscript[q, t]) -> -1, 
      MAskLimits[[5]] == a + b (Subscript[q, t]) /. 
        (Subscript[q, t]) -> +1}

Flatten[Solve[%, {a, b}] // Simplify]

\(M\&_[q_] := Evaluate[a + b\ q\  /. % // FullSimplify]; 
    HoldForm[M\&_[ q\_t ]] -> M\&_[q\_t] /. 
      RuleToEquals\)

\(M\&_[q\_t]\)

f((Subscript[m, t]) | (Subscript[m, t - 1]), 
          (Subscript[m, t + 1]))=ϕ[(Subscript[μ, m]), (Subscript[σ, m]), (Subscript[m, t])] with {(Subscript[μ, m]) =  ((Subscript[m, t - 1]) + (Subscript[m, t + 1]))/
            2, (Subscript[σ, m]) = (Subscript[σ, u])/(Sqrt[2])}.

From eq. (), Pr((Subscript[q, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[P, t]))\(TraditionalForm\`\(\(∝\)\(\ \)\(Φ[μ\_m, σ\_m, \(m\+_\)(q\_t), \(m\&_\)(q\_t)]\)\)\) for (Subscript[q, t]) = ±1. Therefore, the normalized probability of a buy is:

\(\(Φ(μ\_m, σ\_m, \(m\+_\)(\(+1\)), \(m\&_\)(\(+1\)))\)\/\(Φ(μ\_m, σ\_m, \(m\+_\)(\(-1\)), \(m\&_\)(\(-1\))) + Φ(μ\_m, σ\_m, \(m\+_\)(\(+1\)), \(m\&_\)(\(+1\)))\)\)

At the values {(Subscript[m, t - 1]) "=" log(100),(Subscript[m, t + 1]) "=" log(104),(Subscript[P, t]) "=" 101,C "=" 0.2`,(Subscript[σ, u]) "=" 0.01`} this becomes 0.092. Intuitively, given the locations of (Subscript[m, t - 1]) and (Subscript[m, t + 1]), E (Subscript[m, t]) ≈ 102. Since (Subscript[P, t]) lies below this, it is more likely that the transaction was a sale, and the buy probability is below one-half.

\(Pr = 
      HoldForm[Φ[μ\_m, σ\_m, m\+_[\(+1\)], m\&_[\(+1\)]]\/\(Φ[μ\_m, σ\_m, m\+_[\(+1\)], m\&_[\(+1\)]] + Φ[μ\_m, σ\_m, m\+_[\(-1\)], m\&_[\(-1\)]]\)]\)

mParameters = {(Subscript[μ, m]) -> 
            (1/2) ((Subscript[m, t - 1]) + 
                  (Subscript[m, t + 1])), (Subscript[σ, m]) -> ((Subscript[σ, u])/(Sqrt[2]))};

TrialValues = {(Subscript[m, t - 1]) -> Log[100], 
          (Subscript[m, t + 1]) -> Log[104], (Subscript[P, t]) -> 101, 
          C ->  .2, (Subscript[σ, u]) ->  .01};
TrialValues /. RuleToEquals

ReleaseHold[Pr] /. mParameters /. 
        TrialValues /. ΦDef

Drawing \(TraditionalForm\`m\_t | m\_\(\(\\)\(t\)\), q, P\_t\)

As noted, f((Subscript[m, t]) | (Subscript[m, t - 1]), 
          (Subscript[m, t + 1])) = ϕ[(Subscript[μ, m]), (Subscript[σ, m]), (Subscript[m, t])] where (Subscript[μ, m]) and (Subscript[σ, m]) are given above. Conditioning on (Subscript[q, t]) and (Subscript[P, t]) merely restricts the range of the distribution. Therefore, the draw is from the normal distribution ϕ[(Subscript[μ, m]), (Subscript[σ, m]), (Subscript[m, t])] truncated to the range \(TraditionalForm\`\((m\+_[q\_t], m\&_[q\_t])\)\).

Drawing C | P, m, q

The upper and lower bounds on C, given everything else, can be computed in a fashion similar to that used above for (Subscript[M, t]). If (Subscript[q, t]) = -1,

CBidLimits = 
      InequalitySolve[(Subscript[B, t]) < (Subscript[M, t]) - C < (Subscript[B, t]) + 1, C] /. 
        (Subscript[B, t]) -> (Subscript[P, t])

If  (Subscript[q, t]) = +1,

CAskLimits = 
      InequalitySolve[(Subscript[A, t]) - 1 < (Subscript[M, t]) + C < (Subscript[A, t]), C] /. 
        (Subscript[A, t]) -> (Subscript[P, t])

Written as a linear function of (Subscript[q, t]), the lower and upper bounds on C are:

"\!\(\(C\_t\)\+_\) =(-\!\(M\_t\)+\!\(P\_t\)-\!\(1\/2\
\)) \!\(q\_t\)-\!\(1\/2\)"
and
	"\!\(\(C\_t\)\&_\) =(-\!\(M\_t\)+\!\(P\_t\)+\!\(1\/2\
\)) \!\(q\_t\)-\!\(1\/2\)"

{CBidLimits[[5]] == a + b (Subscript[q, t]) /. (Subscript[q, t]) -> -1, 
      CAskLimits[[1]] == a + b (Subscript[q, t]) /. 
        (Subscript[q, t]) -> +1}

Flatten[Solve[%, {a, b}] // Simplify]

\(C\+_ = Evaluate[a + b\ q\_t\ ] /. %\)

{CBidLimits[[1]] == a + b (Subscript[q, t]) /. (Subscript[q, t]) -> -1, 
      CAskLimits[[5]] == a + b (Subscript[q, t]) /. 
        (Subscript[q, t]) -> +1}

Flatten[Solve[%, {a, b}] // Simplify]

\(C\&_ = Evaluate[a + b\ q\_t\  /. %]\)

\(TraditionalForm\`Max\+t\ \(C\_t\)\+_ ≤ \(C\^*\) ≤ \(Min\+t\) \(C\_t\)\&_\)

As the maxima and minima are over the full sample, these bounds are likely to be extremely confining. This is likely to prevent the C draws from mixing well.

Alternative approach: A joint draw of  C, m | P, q

The preceding discussion demonstrated the difficulty of drawing C from its full conditional distribution. One way of viewing the problem is to note that if a hypothetical new draw of C were to move more than a very small step away from the present value, it would be likely that for some observation in the sample, the existing value of (Subscript[m, t]) lie outside of the \(TraditionalForm\`\((\(m\_t\)\+_, m\&_\_t)\)\) bounds implied by the newly drawn C, i.e., that the new draw would not be feasible. This suggests that a new draw of C would have greater latitude if new (Subscript[m, t]) were also drawn as well.

This is feasible. An overview of the procedure is as follows. We start with the current values of C and m. Suppose for the moment that we have some new candidate draw \(TraditionalForm\`\(C\^*\)\). We assume only that \(TraditionalForm\`\(C\^*\) > 0\). It might be the case that \(TraditionalForm\`\(C\^*\)\) implies infeasibility for some or all elements of the current m. A simple way of generating new feasible m is via a deterministic shift. Consider the upper and lower bounds for the level efficient price given in eq. (), holding (Subscript[P, t]) and (Subscript[q, t]) fixed. In moving from C to \(TraditionalForm\`\(C\^*\)\), these bounds shift from \(TraditionalForm\`\((\(M\_t\)\+_, \(M\_t\)\&_)\)\) to \(TraditionalForm\`\((\(M\_t\%*\)\+_, \(M\_t\%*\)\&_)\)\). The shifts in bounds are identical: \(TraditionalForm\`\(M\_t\%*\)\+_ - \(M\_t\)\+_ = \(M\_t\%*\)\&_ - \(M\_t\)\&_\). This suggests setting the new value

\(M\_t\%*\)=\(\(M\_t\%*\)\+_\)+\((M\_t - \(M\_t\)\+_)\)

(and setting \(m\_t\%*\)=\(log(\(M\_t\%*\))\)). In doing this, we are keeping the relative position of the efficient price the same within the new set of bounds.

There are two remaining problems. First, how should the \(TraditionalForm\`\(C\^*\)\) be generated? Second, how can this procedure be integrated into the Gibbs sweep in a valid manner?

The first issue is straightforward. In the basic Roll model, the new draws for the cost parameter c arose from the linear regression Δ (Subscript[p, t]) = 
        c Δ (Subscript[q, t]) + (Subscript[u, t]) (where the variables in the model were in logs). This equation doesn't hold in the present case due to the discreteness transformations. It does suggest, however, a way for generating new values of C. We could randomly generated (Subscript[U, t])~N(0, (Subscript[σ, U]^2)), and then set up the regression:

\(TraditionalForm\`\((C Δ q\_t + U\_t)\) = \(C\^*\) Δ q\_t + 
          U\_t\)

That is, we use the current value C to simulate a dependent variable, regress it against the Δ (Subscript[q, t]), and draw \(TraditionalForm\`\(C\^*\)\) from the coefficient posterior. Obviously, this regression loosely corresponds to the one used in the basic model.

This procedure defines what is generally termed a candidate or proposal distribution for generating a new parameter value from an existing one. It defines a conditional distribution \(TraditionalForm\`g(\(C\^*\) | C)\). The convention, however, is to write this as \(g(C, \(C\^*\))\), where g is a transition density in a Markov chain. Since a new value \(TraditionalForm\`\(C\^*\)\) implies new values \(TraditionalForm\`\(m\^*\)\), this candidate/proposal/transition density is more properly written \(TraditionalForm\`g(C, m, \(C\^*\), \(m\^*\))\). (In this case, though, once we've chosen the new value \(TraditionalForm\`\(C\^*\)\), however, the new \(TraditionalForm\`\(m\^*\)\)are automatically determined.)

We now turn to the second question, viz., how to use this candidate density. The Gibbs sampler turns out to be a special case of a more general sampling scheme called the Metropolis-Hastings sampler. The program for this sampler can be described as follows. Suppose that we enter sweep j + 1 with values (C^((j))) and (m^((j))). Then:

1. Draw \(TraditionalForm\`\(C\^*\)\) and \(TraditionalForm\`\(m\^*\)\) from the candidate density \(TraditionalForm\`g(C, m, \(C\^*\), \(m\^*\))\)

2. Compute

α=Min(1,((\(\(f(\(C\^*\), \(m\^*\))\) \(g(\(C\^*\), \(m\^*\), C\^\((j)\), m\^\((j)\))\)\))/(f((C^((j))), (m^((j))))g((C^((j))),(m^((j))),\(C\^*\),\(m\^*\)))))

where \(TraditionalForm\`f(\(C\^*\), \(m\^*\))\) is the true ("target") density evaluated at the proposal draws, f((C^((j))), (m^((j)))) is the true density evaluated at the sweep-j values, g((C^((j))),(m^((j))),\(C\^*\),\(m\^*\)) is the transition probability associated with generating the new values (conditional on the old ones), and \(TraditionalForm\`g(\(C\^*\), \(m\^*\), C\^\((j)\), m\^\((j)\))\) is the reverse transition probability (i.e., the probability of generating the old values if we'd started with the new ones).

3. Generate z a uniform random number between zero and one.

4. If z < α, "accept the proposal". That is, set \(TraditionalForm\`C\^\((j + 1)\) = \(C\^*\)\) and \(TraditionalForm\`m\^\((j + 1)\) = \(m\^*\)\).
If z ≥ α, "reject the proposal". That is, set (C^((j + 1)))=(C^((j)))  and (m^((j + 1))) = (m^((j))).

As with the Gibbs sampler, in the limit as j -> ∞, ((C^((j))), (m^((j)))) are random numbers distributed in accordance with the target density f.

In the present case, the target density is the conditional density f(C, m | (Subscript[σ, u]), q, P), i.e., the full conditional density given the observed data, the latent data and remaining parameter.

f(C, m | (Subscript[σ, u]), q, P)=((Pr(P | m, q, C, (Subscript[σ, u])) f(m | q, 
                  C, (Subscript[σ, u])) Pr(q | C, (Subscript[σ, u])) f(
                  C, (Subscript[σ, u])))/(Pr(P, 
                  q | (Subscript[σ, u])) f((Subscript[σ, u]))))

Since the mapping from m, q,  and C to P is nonstochastic, Pr(P | m, q, C, (Subscript[σ, u])) = 1. From the assumed independence of the prior distributions,

Pr(q | C, (Subscript[σ, u])) f(
          C, (Subscript[σ, u])) = Pr(q) f(
          C) f((Subscript[σ, u]))

Therefore

f(C, m | (Subscript[σ, u]), q, 
          P) ∝ f(m | q, C, (Subscript[σ, u])) f(C) = f(
          m | (Subscript[σ, u])) f(C)

(since C and q are independent of m). These two quantities are simple to evaluate for the existing and proposed draws.

In drawing from the proposal density, it is not really necessary to simulate the (Subscript[U, t]) and actually run the regression given in eq. (). Suppose that the prior for C is \(TraditionalForm\`\(N\^+\)(0, Ω\_C\%Prior)\). Using the classic Bayesian regression results from section ., if we simulated and ran the regression, the posterior would be \(TraditionalForm\`\(N\^+\)(μ\_C\%Posterior, Ω\_C\%Posterior)\) with

(Subscript[μ, C]^Posterior)=(((\(\(∑\+t Δ q\_t\%2\)\/σ\_U\%2\)+\(1\/Ω\_C\%Prior\)))^(-1))(\(\(∑\+t Δ \(\(q\_t\)(
                          C Δ q\_t + U\_t)\)\)\/σ\_U\%2\))

and

(Subscript[Ω, C]^Posterior)=(((\(\(∑\+t Δ q\_t\%2\)\/σ\_U\%2\)+\(1\/Ω\_C\%Prior\)))^(-1))

A sensible expedient is to take

(Subscript[μ, C]^Posterior)=(((\(\(∑\+t Δ q\_t\%2\)\/σ\_U\%2\)+\(1\/Ω\_C\%Prior\)))^(-1))(\(\(C \(∑\+t Δ q\_t\%2\)\)\/σ\_U\%2\))

Since C is a cost parameter in levels (rather than logs), (Subscript[U, t]) is also a level disturbance. A logical choice for (Subscript[σ, U]^2) is \(TraditionalForm\`\(P\&_\) σ\_u\%2\) where (Subscript[σ, u]) is the current draw of this parameter and \(TraditionalForm\`P\&_\) is the average price level over the sample. In taking these shortcuts, we are departing from the full conditional distribution. This is permissible because g( ... ) is only a proposal density.

Although this draw is joint over both C and m, it does not replace the m draw described above. The reason is that this joint draw cannot generate all values of m; it only shifts the values in a rather limited fashion.

Clustered prices

Model description

This is an extension of the simple discreteness model. The evolution of the (log) efficient price is:

(Subscript[m, t]) = (Subscript[m, t - 1]) + (Subscript[u, t]) where (Subscript[u, t]) ~N(0,(Subscript[σ, u]^2))

The (level) efficient price is therefore (Subscript[M, t]) = (Subscript[(e^m), t]). (The units here are "dollars.") The half-spread in levels is C. The bid and ask quotes are:

(Subscript[B, t]) = Floor((Subscript[M, t]) - C, (Subscript[K, t]))
	(Subscript[A, t]) = Ceiling((Subscript[M, t]) + C, (Subscript[K, t]))

The rounding functions here round down or up to the nearest K-multiple of the "official" tick size. It is assumed that the variables are scaled so that the minimum tick size is unity. The (Subscript[K, t]) are then i.i.d. Bernoulli variates:

(Subscript[K, t])={({{1,  with probability (1 - k)}, {\(κ, \ \(\(with\)\(\ \)\(probability\)\(\ \)\(k\)\(\ \ \ \ \ \ \ \ \ \ \ \)\)\)}})

κ is a "natural multiple" of the basic tick size, like 2, 5 or 10. k is the clustering probability. The buy/sell indicator is

(Subscript[q, t])={({{+1, a buy, with probability (1/2)}, {-1, a sell, with probability (1/2)}})
The obseved transaction price is

(Subscript[P, t])={({{(Subscript[A, t]) if (Subscript[q, t]) = +1}, {(Subscript[B, t]) if (Subscript[q, t]) = -1}})]

In the latent data draw, at each time t, we need to draw \(TraditionalForm\`m\_t, q\_t, K\_t | m\_\(\(\\)\(t\)\), 
      q\_\(\(\\)\(t\)\), P\_t\). The draw is made in two steps:

1. Draw (Subscript[q, t]), (Subscript[K, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[P, t]).

2. Draw (Subscript[m, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[q, t]), (Subscript[K, t]), 
      (Subscript[P, t]).

The parameter draw for C proceeds exactly as in discreteness model. (That is, we make a joint draw of C and m. See section .) There is also an additional parameter draw, k | K.

The draw for (Subscript[q, t]), (Subscript[K, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[P, t])

We have:

Pr((Subscript[q, t]), (Subscript[K, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[P, t]))
=((Pr((Subscript[P, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[q, t]), 
                      (Subscript[K, t])) ×Pr((Subscript[q, t]), (Subscript[K, t]) | (Subscript[m, t - 1]), 
                      (Subscript[m, t + 1]))×f((Subscript[m, t - 1]), 
                      (Subscript[m, t + 1])))/(Pr((Subscript[P, t]) | (Subscript[m, t - 1]), 
                      (Subscript[m, t + 1])) f((Subscript[m, t - 1]), (Subscript[m, t + 1]))))
∝Pr((Subscript[P, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
                (Subscript[q, t]), (Subscript[K, t])) ×Pr((Subscript[q, t]), (Subscript[K, t]) | (Subscript[m, t - 1]), 
                (Subscript[m, t + 1]))
   =Pr((Subscript[P, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[q, t]), 
              (Subscript[K, t])) ×Pr((Subscript[q, t])) Pr((Subscript[K, t]))

The last equality follows from the fact that (Subscript[q, t]) and (Subscript[K, t]) are mutually independent and also independent of the evolution of (Subscript[m, t]). Next,

\(TraditionalForm\`Pr(P\_t | m\_\(t - 1\), m\_\(t + 1\), q\_t, 
          K\_t) = ∫\_\(m\+_\)\%\(m\&_\)\(f(m\_t | m\_\(t - 1\), 
              m\_\(t + 1\))\) dm\_t\)

where \(TraditionalForm\`m\+_\) and \(TraditionalForm\`m\&_\) are the limits established by (Subscript[q, t]) and (Subscript[K, t]) (see below). The general plan is as follows. Using (), we compute unnormalized probabilities for the four possible combinations of (Subscript[q, t]) and (Subscript[K, t]). We normalize these probabilities and make the draw of the {(Subscript[q, t]), (Subscript[K, t])} pair. We then proceed to the (Subscript[m, t]) draw. We turn now to the details.

The floor and ceiling functions in the model imply

MBidLimits = 
      InequalitySolve[(Subscript[B, t]) < (Subscript[M, t]) - C < (Subscript[B, t]) + (Subscript[K, t]), (Subscript[M, t])]

and

MAskLimits = 
      InequalitySolve[(Subscript[A, t]) - (Subscript[K, t]) < (Subscript[M, t]) + C < (Subscript[A, t]), (Subscript[M, t])]

When (Subscript[q, t]) = -1, (Subscript[B, t]) = (Subscript[P, t]), and

MBidLimits = MBidLimits /. (Subscript[B, t]) -> (Subscript[P, t])

When (Subscript[q, t]) = +1, (Subscript[A, t]) = (Subscript[P, t]), and

MAskLimits = MAskLimits /. (Subscript[A, t]) -> (Subscript[P, t])

The lower and upper limit functions for M are:

\(TraditionalForm\`\(M\+_\)(q\_t, K\_t) = 
        1\/2\ \((\(-q\_t\)\ K\_t - K\_t + 2\ P\_t - 2\ C\ q\_t)\)\) 
and 
	\(TraditionalForm\`\(M\&_\)(q\_t, K\_t) = 
        P\_t + \(\(1\/2\)\(\ \)\((K\_t - \((2\ C + 
                      K\_t)\)\ q\_t)\)\(\ \)\)\)

The limits on the log efficient price are then \(TraditionalForm\`m\+_[q\_t, K\_t] = log[\(M\+_\)(q\_t, K\_t)]\) and \(TraditionalForm\`m\&_[q\_t, K\_t] = log[\(M\&_\)(q\_t, K\_t)]\).

{MBidLimits[[1]] == a + b (Subscript[q, t]) /. 
        (Subscript[q, t]) -> -1, 
MAskLimits[[1]] == 
          a + b (Subscript[q, t]) /. (Subscript[q, t]) -> +1}

Flatten[Solve[%, {a, b}] // Simplify]

\(M\+_[q\_t, K\_t]\)

{MBidLimits[[5]] == a + b (Subscript[q, t]) /. (Subscript[q, t]) -> -1, 
      MAskLimits[[5]] == a + b (Subscript[q, t]) /. 
        (Subscript[q, t]) -> +1}

Flatten[Solve[%, {a, b}] // Simplify]

\(M\&_[q\_t, K\_t]\)

Pr((Subscript[q, t]), (Subscript[K, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
        (Subscript[P, t]))∝Pr((Subscript[P, t]) | (Subscript[m, t - 1]), 
            (Subscript[m, t + 1]), (Subscript[q, t]), (Subscript[K, t])) ×Pr((Subscript[K, t]))

Recall that f((Subscript[m, t]) | (Subscript[m, t - 1]), 
          (Subscript[m, t + 1])) = ϕ((Subscript[μ, m]), (Subscript[σ, m]), (Subscript[m, t])) with (Subscript[μ, m]) = ((Subscript[m, t - 1]) + (Subscript[m, t + 1]))/
              2  and  (Subscript[σ, m]) = (Subscript[σ, u])/(Sqrt[2]). Thus,

\(TraditionalForm\`Pr(q\_t, K\_t | m\_\(t - 1\), m\_\(t + 1\), 
          P\_t) ∝ \ Φ[μ\_m, σ\_m, \(m\+_\)(q\_t, K\_t), \(m\&_\)(q\_t, K\_t)] \(Pr(K\_t)\)\)

for ((Subscript[q, t]), 
          (Subscript[K, t])) ∈ {+1, -1}×{1, κ}. Let i index the four possible combinations of ((Subscript[q, t]), (Subscript[K, t])), and let

\(TraditionalForm\`Z\_i = \ Φ[μ\_m, σ\_m, \(m\+_\)(q\_t, K\_t), \(m\&_\)(q\_t, K\_t)] \(Pr(K\_t)\)\)

evaluated at the the ith values. Then the normalized probability of outcome i is (Subscript[Z, i])/Σ(Subscript[Z, i]).

The draw for (Subscript[m, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[q, t]), (Subscript[K, t]), 
      (Subscript[P, t])

This is simply a draw from f((Subscript[m, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]))truncated to \(TraditionalForm\`\((m\+_, m\&_)\)\).

The parameter draw for k | K

The clustering variables are defined by K = {(Subscript[K, 1]),  ... , (Subscript[K, T])}, where each (Subscript[K, t]) ∈ {1, κ}. Let n be the number of t for which (Subscript[K, t]) = κ. If the probability of (Subscript[K, t]) = κ is k, then n is a binomial random variable. The beta distribution is conjugate to the binomal (Tanner, 1996), so Beta[a, b] is a convenient prior for k. We let (a^Prior) = (b^Prior) = 1/2, for which the Beta density is uniform on the unit interval. The posterior for k is then Beta[(a^Posterior), (b^Posterior)] where (a^Posterior) = (a^Prior) + n and (b^Posterior) = (b^Prior) + T - n.

Lagged trade dependencies

Model description

In this extension of the informative trade model, the evolution of the efficient price is allowed to depend on lagged signed trades (as well as the contemporaneous one).

(Subscript[m, t]) = 
      (Subscript[m, t - 1]) + (Subscript[Λ, t]) + (Subscript[u, t])

where (Subscript[Λ, t]) is the impact term:

\(TraditionalForm\`Λ\_t = ∑\+\(j = 0\)\%\(Min(J, t - 1)\)\(q\_\(t - j\)\) \(λ\_j\) V\_\(t - j\)\)

J is the order of the lagged dependence. The upper limit of the sum indicates that the lags do not extend before the beginning of the sample. The observed price is:

(Subscript[p, t]) = (Subscript[m, t]) + c (Subscript[q, t])

The parameter draw for {(Subscript[λ, 0]),  ... , (Subscript[λ, J]), 
        c, (Subscript[σ, u])} is (mostly) straightforward. Given the observed and latent data,

\(TraditionalForm\`Δ p\_t = \(Δ m\_t + 
          c Δ q\_t = \(Λ\_t + c Δ q\_t + 
            u\_t =  ∑\+\(j = 0\)\%\(Min(J, t - 1)\)\(\(\(λ\)\( \)\)\_j\) \(q\_\(t - j\)\) V\_\(t - j\) + 
            c Δ q\_t + 
            u\_t\)\)\)

This fits into the Bayesian multiple regression framework (with c and the (Subscript[λ, j]) the coefficients).

There is the potential for multicollinearity here, however. Suppose that J = 1 and (Subscript[V, t]) = 1. Then

\(TraditionalForm\`Δ p\_t = \(λ\_0\) q\_t + \(λ\_1\) q\_\(t - 1\) + 
          c Δ q\_t + u\_t\)

In economic terms, the impact of a trade on the efficient price depends only on the direction of the trade, and not its size. Since Δ (Subscript[q, t]) = 
        (Subscript[q, t]) - (Subscript[q, t - 1]), however, the cross-product matrix is singular. Some sort of additional structure is needed. (One possibility is to simply let (Subscript[V, t]) = (Subscript[Vol, t]).)

The latent data draw is of  \(TraditionalForm\`q\_t | m\_\(\(\\)\(t\)\), p\_t, 
      q\_\(\(\\)\(t\)\)\). This follows the design of the draw for the contemporaneous impact model, but the lagged structure extends the (Subscript[q, t]) dependencies. From the structure of the sum, it is clear that (Subscript[q, t]) influences (Subscript[m, t]),  ... , (Subscript[m, t + P]).  Therefore \(TraditionalForm\`Pr(q\_t | m\_\(\(\\)\(t\)\), 
        q\_\(\(\\)\(t\)\))\) depends on (∏_(s = 0)^J) f((Subscript[u, t + s])).  From inspection of these terms,

\(TraditionalForm\`Pr(q\_t | m\_\(\(\\)\(t\)\), p\_t, 
          q\_\(\(\\)\(t\)\)) = 
        Pr(q\_t | m\_\(t - 1\), m\_\(t + 1\), \(\(...\) \(m\_\(t + P\)\)\), 
          p\_t, q\_\(t - P\),  ... , q\_\(t - 1\), q\_\(t + 1\),  ... , 
          q\_\(t + P\))\).

For notational simplicity, however, the conditioning set indicated on the l.h.s. will be used below.

Analogous to eq. (),

\(Pr(q\_t | m\_\(\(\\)\(t\)\), p\_t, q\_\(\(\\)\(t\)\))\)=\(\(\(f(p\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
                  q\_t)\)×\(Pr(q\_t | m\_\(\(\\)\(t\)\), 
                  q\_\(\(\\)\(t\)\))\)\)\/\(f(p\_t | m\_\(\(\\)\(t\)\), 
                q\_\(\(\\)\(t\)\))\)\)

Since \(TraditionalForm\`q = {q\_\(\(\\)\(t\)\), q\_t}\), the first term in the numerator could have been written more concisely (but less clearly) as \(TraditionalForm\`f(p\_t | m\_\(\(\\)\(t\)\), q)\). The denominator can be treated as a proportionality factor. The two terms in the numerator must be evaluated separately.

Evaluation of \(TraditionalForm\`Pr(q\_t | m\_\(\(\\)\(t\)\), \ 
        q\_\(\(\\)\(t\)\))\)

This probability is derived from the joint density of (Subscript[u, t]),  ... , (Subscript[u, Min(t + J, T)]), which is (∏_(s = 0)^(Min(J, T - t)))f(
          (Subscript[u, t + s])). When t < T, it is convenient to write this as:

(∏_(s = 0)^(Min(J, T - t)))f(
          (Subscript[u, t + s])) = ((∏_(s = t + 2)^(J + t))ϕ(
              0, (Subscript[σ, u]), (Subscript[u, s]))) ϕ(0, (Subscript[σ, u]), 
          (Subscript[u, t])) ϕ(0, (Subscript[σ, u]), 
          (Subscript[u, t + 1]))

Here, we've pulled out the two terms that depend on (Subscript[m, t]). Substituting in for (Subscript[u, t]) and (Subscript[u, t + 1]), these terms are:

uDef[t_] := 
        (Subscript[u, t]) -> 
          (Subscript[m, t]) - ((Subscript[m, t - 1]) + (Subscript[Λ, t]));
f1 = ϕ[0, (Subscript[σ, u]), (Subscript[u, t])] ϕ[0, (Subscript[σ, u]), 
              (Subscript[u, t + 1])] /. uDef[t] /. uDef[t + 1]

Integrating out (Subscript[m, t]) gives:

fI = 
      Integrate[f1 /. ϕDef, {(Subscript[m, t]), -∞, ∞}, 
        Assumptions -> σuAssumptions]

Replacing this in the joint density gives \(TraditionalForm\`\(\(Pr(q\_t | m\_\(\(\\)\(t\)\), 
          q\_\(\(\\)\(t\)\))\)\(∝\)\)\)

PrUnnor = 
      fI ((∏_(s = t + 2)^(Min[t + J, T]))ϕ[
              0, (Subscript[σ, u]), (Subscript[u, s])])

We evaluate this for (Subscript[q, t]) = ±1, normalize and make the draw.

The following intermediate calculations are used in the C++ code:

Log[fI] // PowerExpand

Log[ϕ[0, (Subscript[σ, u]), (Subscript[u, s])] /. ϕDef] // 
      PowerExpand

-((Subscript[u, t]) + (Subscript[u, t + 1])) /. uDef[t] /. uDef[t + 1]

We evaluate this expression for (Subscript[q, t]) = ±1 (recognizing that the (Subscript[u, s]) for t + 2 ≤ s ≤ 
        t + P also depend on (Subscript[q, t])), and normalize. We now turn to the first component in the numerator of ().

Evaluation of \(TraditionalForm\`\(\(f(p\_t | \ m\_\(\(\\)\(t\)\), \ 
        q)\)\(\ \)\)\)

Consider again from the joint density for (Subscript[u, t]),  ... , (Subscript[u, t + P]) in eq. (). The first two terms are:

f1 = ϕ[0, (Subscript[σ, u]), (Subscript[u, t])] ϕ[0, (Subscript[σ, u]), 
              (Subscript[u, t + 1])] /. uDef[t] /. uDef[t + 1]

Using the definition for the normal density and simplifying gives:

f2 = f1 /. ϕDef // Simplify

This is proportional to ϕ((Subscript[μ, t]), (Subscript[σ, t]), (Subscript[m, t])) where

mParam = 
        GetNormalForm[f2, (Subscript[m, t]), (Subscript[μ, t]), (Subscript[σ, t])] // 
          Simplify;
mParam /. RuleToEquals // TableForm

Thus,

\(TraditionalForm\`\(\(f(m\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
          q\_t)\)\(∝\)\)\)

ϕ[(Subscript[μ, t]), (Subscript[σ, t]), 
        (Subscript[m, t])] ((∏_(s = t + 2)^(P + t))ϕ[0, (Subscript[σ, u]), 
            (Subscript[u, s])])

Substituting in for (Subscript[m, t]) gives \(TraditionalForm\`\(\(f(p\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
          q\_t)\)\(=\)\)\)

% /. (Subscript[m, t]) -> (Subscript[p, t]) - c (Subscript[q, t])

Summary

To draw \(TraditionalForm\`q\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
      p\_t\), the steps are:

1. Compute the normalized \(TraditionalForm\`Pr(q\_t = \(-1\) | m\_\(\(\\)\(t\)\), 
        q\_\(\(\\)\(t\)\))\) and \(TraditionalForm\`Pr(q\_t = \(+1\) | m\_\(\(\\)\(t\)\), 
        q\_\(\(\\)\(t\)\))\)

2. Compute \(TraditionalForm\`f(p\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
        q\_t = \(-1\))\) and \(TraditionalForm\`f(p\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
        q\_t = \(+1\))\)

3. Compute the unnormalized probabilities \(TraditionalForm\`π(\(-1\)) = \(Pr(
            q\_t = \(-1\) | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\))\) \(f(
            p\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
            q\_t = \(-1\))\)\) and \(TraditionalForm\`π(\(+1\)) = \(Pr(
            q\_t = \(+1\) | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\))\) \(f(
            p\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
            q\_t = \(+1\))\)\).

4. The normalized probability of a buy is \(TraditionalForm\`Pr(q\_t = \(+1\) | m\_\(\(\\)\(t\)\), 
          q\_\(\(\\)\(t\)\), 
          p\_t) = \(π(\(+1\))\)\/\(π(\(+1\)) + π(\(-1\))\)\)

5. Use this probability to make the Bernoulli draw.

Endpoint modifications

t = 1

At t = 1, the relevant joint density is ((∏_(s = 3)^J) ϕ(0, (Subscript[σ, u]), 
              (Subscript[u, s]))) ϕ(0, (Subscript[σ, u]), (Subscript[u, 2])). (The product term is dropped when J < 3.) Consider the ϕ(0, (Subscript[σ, u]), (Subscript[u, 2])) term. Substituting in for (Subscript[u, 2]) gives:

f = ϕ[0, (Subscript[σ, u]), (Subscript[u, 2])] /. uDef[2]

Integrating over (Subscript[m, 1])gives 1. Therefore \(TraditionalForm\`Pr(q\_1 | m\_\1, 
          q\_\1) ∝ ∏\+\(s = 3\)\%J ϕ(
            0, σ\_u, u\_s)\). Compute the r.h.s for (Subscript[q, 1]) = ±1and normalize. If J < 3, then Pr((Subscript[q, 1])) = 1/2.

The function above is equivalent to ϕ((Subscript[μ, 1]), (Subscript[σ, 1]), (Subscript[m, 1])) with

GetNormalForm[f /. ϕDef, (Subscript[m, 1]), (Subscript[μ, 1]), (Subscript[σ, 1])] /. 
        RuleToEquals // TableForm

Therefore \(TraditionalForm\`\(\(f(m\_1 | m\_\1, q\_\1, q\_1)\)\(=\)\)\)

ϕ[(Subscript[μ, 1]), (Subscript[σ, 1]), 
        (Subscript[m, 1])] ((∏_(s = 3)^P) ϕ[0, (Subscript[σ, u]), 
            (Subscript[u, s])])

Or, \(TraditionalForm\`\(\(f(p\_1 | m\_\1, q\_\1, q\_1)\)\(=\)\)\)

% /. (Subscript[m, 1]) -> (Subscript[p, 1]) - c (Subscript[q, 1])

Since \(TraditionalForm\`Pr(q\_1 | m\_\1, q\_\1, 
          p\_1) ∝ \(f(p\_1 | m\_\1, q)\) \(Pr(q\_1 | m\_\1, 
            q\_\1)\)\), we may compute the r.h.s., normalize and make the draw.

t = T

For t = T, the relevant joint density is ϕ(0, (Subscript[σ, u]), (Subscript[u, T])). Substituting for (Subscript[u, T]):

f = ϕ[0, (Subscript[σ, u]), (Subscript[u, T])] /. uDef[T]

Integrating out (Subscript[m, T]) gives 1, so \(TraditionalForm\`Pr(q\_T | m\_\(\(\\)\(T\)\), q\_\(\(\\)\(T\)\)) = 
        1/2\). From the above expression, \(TraditionalForm\`f(m\_T | m\_\(\(\\)\(T\)\), q\_\(\(\\)\(T\)\), 
          q\_T) = ϕ(μ\_T, σ\_T, m\_T)\) with

GetNormalForm[f /. ϕDef, (Subscript[m, T]), (Subscript[μ, T]), (Subscript[σ, T])] /. 
        RuleToEquals // TableForm

Therefore \(TraditionalForm\`f(p\_T | m\_\(\(\\)\(T\)\), q\_\(\(\\)\(T\)\), 
          q\_T) = ϕ(μ\_T, σ\_T, 
          p\_T - c q\_T)\).

Using these results, compute \(TraditionalForm\`f(p\_T | m\_\(\(\\)\(T\)\), q\_\(\(\\)\(T\)\), 
        q\_T)\) at (Subscript[q, T]) = ±1 and normalize. (This is the first normalization.) Make the draw for (Subscript[q, T]).

Combined model I: Trade dependencies, discreteness and clustering

Model description

This model combines the features considered separately in earlier sections. The efficient price evolution reflects a contemporaneous trade impact:

(Subscript[m, t]) = 
      (Subscript[m, t - 1]) + (Subscript[q, t]) λ (Subscript[V, t]) + 
        (Subscript[u, t])

The mapping to observed prices follows the discreteness/clustering model. The bid and ask quotes are:

(Subscript[B, t]) = Floor((Subscript[M, t]) - C, (Subscript[K, t]))
	(Subscript[A, t]) = Ceiling((Subscript[M, t]) + C, (Subscript[K, t]))

where (Subscript[M, t]) = (Subscript[(e^m), t]); C is the half-spread; the rounding functions here round down or up to the nearest K-multiple of the "official" tick size. The clustering multiple is (Subscript[K, t]) , an i.i.d. Bernoulli variate:

(Subscript[K, t])={({{1,  with probability (1 - k)}, {\(κ, \ \(\(with\)\(\ \)\(probability\)\(\ \)\(k\)\(\ \ \ \ \ \ \ \ \ \ \ \)\)\)}})

κ is a "natural multiple" of the basic tick size, like 2, 5 or 10. k is the clustering probability.
The buy/sell indicator is

(Subscript[q, t])={({{+1,  a buy,  with probability (1/2)}, {-1,  a sell,  with probability (1/2)}})
The obseved transaction price is

(Subscript[P, t])={({{(Subscript[A, t]) if (Subscript[q, t]) = +1}, {(Subscript[B, t]) if (Subscript[q, t]) = -1}})

The parameter draws are minor modifications of those given above. That is, {λ, (Subscript[σ, u])} are modeled in the regression:

\(TraditionalForm\`Δ m\_t = λ q\_t + u\_t\)

The clustering parameter k is modeled in the beta/binomial framework. C is drawn using the Metropolis-Hastings algorithm described in section .

In the latent data draw, at each time t, we need to draw \(TraditionalForm\`m\_t, q\_t, K\_t | m\_\(\(\\)\(t\)\), 
      q\_\(\(\\)\(t\)\), P\_t\). The draw is made in two steps:

1. Draw \(TraditionalForm\`q\_t, K\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
      P\_t\).

2. Draw \(TraditionalForm\`m\_t | m\_\(\(\\)\(t\)\), q, K\_t, P\_t\).

Given the structure of the model, \(TraditionalForm\`Pr(q\_t, K\_t | m\_\(\(\\)\(t\)\), 
          q\_\(\(\\)\(t\)\), K\_\(\(\\)\(t\)\), P) = 
        Pr(q\_t, K\_t | m\_\(t - 1\), m\_\(t + 1\), q\_\(t + 1\), P\_t)\). Analogous to eq. (),

Pr((Subscript[q, t]), (Subscript[K, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[q, t + 1]), 
          (Subscript[P, t]))

=((Pr((Subscript[P, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[q, t + 1]), 
                    (Subscript[q, t]), (Subscript[K, t])) ×Pr((Subscript[q, t]), (Subscript[K, t]) | (Subscript[m, t - 1]), 
                    (Subscript[m, t + 1]),  (Subscript[q, t + 1])))/(Pr(
                  (Subscript[P, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[q, t + 1]))))

∝Pr((Subscript[P, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
              (Subscript[q, t + 1]), (Subscript[q, t]), (Subscript[K, t])) ×Pr((Subscript[q, t]) | (Subscript[m, t - 1]), 
              (Subscript[m, t + 1]),  (Subscript[q, t + 1]))×Pr((Subscript[K, t]))

The denominator is subsumed into the proportionality constant; (Subscript[K, t]) is independent of the other variables. The first two terms must be evaluated separately.

Pr((Subscript[q, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
      (Subscript[q, t + 1]))

This development is identical to the one given for the asymmetric information model above. The joint distribution of (Subscript[u, t]) and (Subscript[u, t + 1])is ϕ(0, (Subscript[σ, u]), (Subscript[u, t])) ϕ(
          0, (Subscript[σ, u]), (Subscript[u, t + 1])). Substituting from () gives:

TD = ϕ[0, (Subscript[σ, u]), (Subscript[u, t])] ϕ[0, (Subscript[σ, u]), (Subscript[u, t + 1])] /. 
        (Subscript[u, t])_ -> 
          (Subscript[m, t]) - ((Subscript[m, t - 1]) + (Subscript[q, t]) λ (Subscript[V, t]))

Integrating out (Subscript[m, t]) gives:

fI = 
      Integrate[TD /. ϕDef, {(Subscript[m, t]), -∞, +∞}, 
        Assumptions -> σuAssumptions]

Evaluating this at (Subscript[q, t]) = +1 and (Subscript[q, t]) = -1 and normalizing gives Pr((Subscript[q, t]) = +1 | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
          (Subscript[q, t + 1]))=

PrBuy = (((fI /. (Subscript[q, t]) -> +1))/((fI /. (Subscript[q, t]) -> +1) + (fI /. (Subscript[q, t]) -> -1))) // Simplify

We combine this with the fact that Pr((Subscript[K, t]) = κ) = k to obtain the full set of Pr((Subscript[q, t]), (Subscript[K, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
        (Subscript[q, t + 1])) for ((Subscript[q, t]), 
          (Subscript[K, t])) ∈ {-1, +1}×{1, κ}.

Pr((Subscript[P, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), (Subscript[q, t + 1]), 
      (Subscript[q, t]), (Subscript[K, t]))

This is obtained by integrating f((Subscript[m, t]) | (Subscript[q, t]), (Subscript[K, t]), (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
        (Subscript[q, t + 1])) over the range implied by (Subscript[q, t]) and (Subscript[K, t]):

\(TraditionalForm\`Pr(P\_t | m\_\(t - 1\), m\_\(t + 1\), q\_\(t + 1\), 
        q\_t, K\_t) = \ ∫\_\(m\+_\)\%\(m\&_\)\(f(m\_t | q\_t, K\_t, 
            m\_\(t - 1\), m\_\(t + 1\), 
            q\_\(t + 1\))\) dm\_t\)

where \(TraditionalForm\`m\+_ = \(m\+_\)(q\_t, K\_t)\) and \(TraditionalForm\`m\&_ = \(m\&_\)(q\_t, K\_t)\) are the bounding functions derived for the clustering model. The integrand is:

TD

This can be reworked as the normal density ϕ((Subscript[μ, m]), (Subscript[σ, m]), (Subscript[m, t])) where the parameters are:

GetNormalForm[TD /. ϕDef, (Subscript[m, t]), (Subscript[μ, m]), (Subscript[σ, m])] /. 
        RuleToEquals // TableForm

We now use the result from eq. () that

Pr((Subscript[q, t]), (Subscript[K, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
        (Subscript[q, t + 1]), 
        (Subscript[P, t])) ∝ Pr((Subscript[P, t]) | (Subscript[m, t - 1]), (Subscript[m, t + 1]), 
          (Subscript[q, t + 1]), (Subscript[q, t]), (Subscript[K, t])) ×Pr((Subscript[q, t]) | (Subscript[m, t - 1]), 
          (Subscript[m, t + 1]),  (Subscript[q, t + 1]))×Pr(
          (Subscript[K, t]))

We compute the r.h.s. for all values of {(Subscript[q, t]), (Subscript[K, t])}, normalize and make the draw.

Combined model II: Lagged trade dependencies, discreteness and clustering

This is the richest model estimated in the paper, involving all of the features considered to this point. The model is closest to the one considered in the last section. In this version, the efficient price evolution reflects lagged trade impacts:

(Subscript[m, t]) = 
      (Subscript[m, t - 1]) + (Subscript[Λ, t]) + (Subscript[u, t])

where (Subscript[Λ, t]) is the impact term:

\(TraditionalForm\`Λ\_t = ∑\+\(j = 0\)\%\(Min(J, t - 1)\)\(q\_\(t - j\)\) \(λ\_j\) V\_\(t - j\)\)

J is the order of the lagged dependence. The mapping to observed prices is the same as in the previous section.

The draw strategies are minor modifications of those encountered earlier.

For the parameter draws, {(Subscript[λ, j]), (Subscript[σ, u])} are modeled in the regression:

\(TraditionalForm\`Δ m\_t = ∑\+\(j = 0\)\%\(Min(J, t - 1)\)\(\(\(λ\)\( \)\)\_j\) \(q\_\(t - 
                  j\)\) V\_\(t - j\) + u\_t\)

In discussing the corresponding regression for the lagged trade impact model without discreteness or clustering (cf. Section ), the potential for multicollinearity was noted. This arose from the presence (in eq. ()) of a c Δ (Subscript[q, t]) term. This term is absent in eq. (). This alleviates the problem of multicollinearity in the regression. The problem persists in the broader model, however, if the tick size is small relative to the price changes.

The clustering parameter k is modeled in the beta/binomial framework. C is drawn using the Metropolis-Hastings algorithm.

In the latent data draw, at each time t, we need to draw \(TraditionalForm\`m\_t, q\_t, K\_t | m\_\(\(\\)\(t\)\), 
      q\_\(\(\\)\(t\)\), P\_t\). The draw is made in two steps:

1. Draw \(TraditionalForm\`q\_t, K\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
      P\_t\).

2. Draw \(TraditionalForm\`m\_t | m\_\(\(\\)\(t\)\), q, K\_t, P\_t\).

To derive the probabilities for the first draw, note:

\(Pr(q\_t, K\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
          P\_t)\)

=\(\(\(Pr(P\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
                    q\_t, K\_t)\)\ ×\(Pr(q\_t, 
                    K\_t | m\_\(\(\\)\(t\)\), \ 
                    q\_\(\(\\)\(t\)\))\)\)\/\(Pr(P\_t | m\_\(\(\\)\(t\)\), 
                  q\_\(\(\\)\(t\)\))\)\)

∝\(\(Pr(P\_t | m\_\(\(\\)\(t\)\), 
              q\_\(\(\\)\(t\)\), q\_t, K\_t)\)\ ×\(Pr(
              q\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\))\)×\(Pr(
              K\_t)\)\)

\(TraditionalForm\`Pr(q\_t | m\_\(\(\\)\(t\)\), 
        q\_\(\(\\)\(t\)\))\) is the same as in the lagged trade impact model (see section ), since the results of this analysis do not involve the clustering or discreteness effects.

\(TraditionalForm\`\(\(Pr(P\_t | m\_\(\(\\)\(t\)\), 
        q\_\(\(\\)\(t\)\), q\_t, K\_t)\)\(\ \)\)\)is computed as:

\(TraditionalForm\`Pr(P\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
          q\_t, K\_t) = ∫\_\(m\+_\)\%\(m\&_\)\(f(
              m\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
              q\_t)\) dm\_t\)

where the limits of the integral are the clustering limits discussed in section . The integrand is the (Subscript[m, t]) density for the lagged trade impact model.

To summarize, compute the r.h.s. of eq. () for the four possible values of {(Subscript[q, t]), (Subscript[K, t])}. Normalize and make the draw. Finally, draw (Subscript[m, t]) from \(TraditionalForm\`f(m\_t | m\_\(\(\\)\(t\)\), q\_\(\(\\)\(t\)\), 
        q\_t)\) restricted to the range \(TraditionalForm\`\((m\+_, m\&_)\)\) implied by the (just-drawn) {(Subscript[q, t]), (Subscript[K, t])}.

References

Carlin, B.P., and T.A. Louis, 1996. Bayes and Empirical Bayes Methods for Data Analysis.  (London: Chapman and Hall).
Casella, G., George, E. I., 1992. Explaining the Gibbs sampler. The American Statistician 46, 167-190.
Chib, S., Greenberg, E., 1995. Understanding the Metropolis-Hastings algorithm. The American Statistician 49, 327-335.
Chib, S., Greenberg, E., 1996. Markov chain Monte Carlo simulation methods in econometrics. Econometric Theory 12, 409-431.
Gamerman, D., 1997. Markov Chain Monte Carlo. Chapman and Hall, New York.
Kim, C.-J., Nelson, C. R., 2000. State-space models with regime switching. MIT Press, Cambridge, Massachusetts.
Tanner, M.A., 1996. Tools for Statistical Inference.  Third ed., (New York: Springer-Verlag).