360
Views
0
CrossRef citations to date
0
Altmetric
Research Papers

Online learning of order flow and market impact with Bayesian change-point detection methods

, &
Received 21 Aug 2023, Accepted 16 Mar 2024, Published online: 05 May 2024

Abstract

Financial order flow exhibits a remarkable level of persistence, wherein buy (sell) trades are often followed by subsequent buy (sell) trades over extended periods. This persistence can be attributed to the division and gradual execution of large orders. Consequently, distinct order flow regimes might emerge, which can be identified through suitable time series models applied to market data. In this paper, we propose the use of Bayesian online change-point detection (BOCPD) methods to identify regime shifts in real-time and enable online predictions of order flow and market impact. To enhance the effectiveness of our approach, we have developed a novel BOCPD method using a score-driven approach. This method accommodates temporal correlations and time-varying parameters within each regime. Through empirical application to NASDAQ data, we have found that: (i) Our newly proposed model demonstrates superior out-of-sample predictive performance compared to existing models that assume i.i.d. behavior within each regime; (ii) When examining the residuals, our model demonstrates good specification in terms of both distributional assumptions and temporal correlations; (iii) Within a given regime, the price dynamics exhibit a concave relationship with respect to time and volume, mirroring the characteristics of actual large orders; (iv) By incorporating regime information, our model produces more accurate online predictions of order flow and market impact compared to models that do not consider regimes.

1. Introduction

The study and modeling of order flow and market impact in financial markets hold paramount importance for understanding the incorporation of private information into prices and designing effective trading algorithms that consider transaction costs. A substantial body of literature (see for example Bouchaud et al. (Citation2009) and Lillo (Citation2023) and references therein) has revealed that the joint modeling of impact and order flow is more intricate than initially presumed.

The persistence and autocorrelation of signed trade order flowFootnote1 have been extensively documented since the works of Lillo and Farmer (Citation2004) and Bouchaud et al. (Citation2004). This persistence aligns with a long memory process, suggesting that a realistic market impact model should combine statistically efficient prices with correlated order flow. The introduction of transient impact models, also known as propagator models (Bouchaud et al. Citation2004), successfully accomplishes this goal. Additionally, empirical evidence has attributed the temporal persistence of order flow primarily to order splitting, as discussed in Tóth et al. (Citation2015). Order splitting refers to the common practice of large investors incrementally executing their orders, termed ‘metaorders,’ through several smaller trades known as ‘child orders.’ The model proposed by Lillo et al. (Citation2005) quantitatively establishes a relationship between the autocorrelation of order flow and the distribution of metaorder sizes. In essence, this model postulates that the strong serial dependence arises from the optimal execution strategies employed by institutional investors, which leads to persistent order flow.

From an econometric perspective, this notion might be connected to the well-known fact (see Granger and Hyung Citation1999, Mikosch and Starica Citation1999, Diebold and Inoue Citation2001) that long memory time series can be (approximately) generated by regime-shift models, where each regime exhibits short memory and heterogeneous lengths. Regime shift models gained popularity around two decades ago when they were proposed to explain the long-range memory of volatility, as seen in Diebold and Inoue (Citation2001).

This paper proposes to use regime shift models to describe order flow time series, with the objectives of: (i) econometrically explaining the long memory of order flow; (ii) enhancing the prediction of order flow and price dynamics through detected regimes; and (iii) suggesting a connection between regimes and the execution of metaorders. Unlike many conventional regime shift approaches that require a predetermined number of regimes (e.g. Hidden Markov Models), we focus on a model that allows online detection of change-points (CPs) to identify the occurrence of new regimes. Existing algorithms typically operate offline, recursively segmenting the time series ex-post into increasingly smaller regimes.

In this paper, we specifically concentrate on online CP detection, employing Bayesian approaches. The Bayesian framework is well-suited for quantifying our uncertainty regarding CPs using the posterior distribution, as illustrated in Ghahramani (Citation2015). We primarily consider the class of algorithms known as Bayesian Change-Point Detection Methods (BOCPD), pioneered by Adams and MacKay (Citation2007) as an improvement on the ideas developed by Fearnhead and Liu (Citation2007). Since 2007, BOCPD and its extensions have found applications in various financial settings. Most applications have focused on stock returns, as demonstrated in Fan and Mackey (Citation2017), Lleo et al. (Citation2020) and Zhao et al. (Citation2022), and more recently, Lleo et al. (Citation2022Citation2023) utilized BOCPD as an exit-entry model for long-short prediction in the stock market. The work by Fan and Mackey (Citation2017) extended the BOCPD approach to the multi-sequence setting to analyze changes in 401 U.S. stocks within the S&P 500 index. BOCPD utilizes a message-passing algorithm to recursively compute the posterior distribution of the time since the last CP, termed the ‘run length’. This elapsed time is continuously updated upon receiving new data points. To perform online inference, the underlying predictive model (UPM) is computed, representing the distribution of data given the current run length. For instance, the UPM may assume a Gaussian model with different means across regimes.

In the BOCPD model, the data is assumed to be independently and identically distributed (i.i.d.) within each regime. However, this assumption is unrealistic for most financial time series. In this work, we extend BOCPD to accommodate Markovian data within each regime. While Xuan and Murphy (Citation2007) consider the correlation structure of multivariate time series, their CP detection algorithm is offline. To the best of our knowledge, this is the first work that combines an online learning algorithm for CPs with a Markovian data structure. Furthermore, we propose a second extension of the BOCPD algorithm that relaxes the assumption of constant parameters within a regime, allowing for time-varying autocorrelation. To achieve this, we employ the class of Score Driven models introduced by Creal et al. (Citation2013) and Harvey (Citation2013), which provide an observation-driven framework for real-time learning of time-varying parameters. Thus, our newly proposed method combines the online CP detection approach of BOCPD with the online learning of time-varying autocorrelation parameters within each regime.

We present an empirical application of the proposed methods using order flow samples from stocks traded on NASDAQ. In an out-of-sample forecasting exercise, we find that the Score-Driven-based method outperforms other models, including autocorrelated time series models without regimes. Our analysis demonstrates that the model is correctly specified, and the residuals within each regime exhibit no correlation. By investigating the price dynamics during identified regimes, we discover that they follow concave functions of time, with the total price change in a regime also exhibiting a concave relationship with volume. These findings resemble those observed for real metaorders, consistent with the square root impact law. Finally, we demonstrate that knowledge of order flow regimes can be effectively utilized to improve predictions of order flow and price dynamics. We accomplish this by exploiting the well-known correlation between order flow and simultaneous/future price changes through market impact.

The paper is organized as follows: In section 2, we present the dataset, the variable of interest, and provide the motivation for applying a regime shift model to order flow time series. Section 3 covers the methodological aspects of the paper, outlining the main properties of BOCPD and introducing the two proposed extensions. In section 4, we describe the estimation results of the models on NASDAQ data and analyze the obtained findings. We examine the average price dynamics during an order flow regime and quantify the relationship between the total price change and the net order flow exchanged within a regime. Moreover, it is presented the forecasting analysis of order flow and the correlation with price dynamics through market impact. Finally, in section 5, we draw conclusions and offer suggestions for further research.

2. Data set and motivation

In this paper, we consider the order flow of trades and in particular the aggregated signed volume. Let M be the number of trades in a given day and let vi (i=1,,M) the signed volume (positive for buyer initiated and negative for seller initiated trades) of the i-th trade and let us indicate with N the number of trades we aggregate, so that our time series is composed by T=M/N observations. The time series of interest is the aggregated order flow xt on the interval N[N(t1)+1,N(t1)+N] given by (1) xt=j=1NvN(t1)+j,t=1,,T.(1) Our data set consists of executed orders during March 2020 for Microsoft Corp. (MSFT) and of December 2021 for Tesla Inc. (TSLA). In order to investigate the role of aggregation time scale, we choose N = 240 and N = 730 for TSLA and N = 400 and N = 1200 for MSFT, which, in both cases correspond to an average time interval of 1 and 3 minutes, respectively. The length of the two time series is 8686 data points for 1 minute and 2856 data points for 3 minutes of TSLA and 8723 data points for 1 minute and 2908 data points for 3 minutes of MSFT. The choice of 1 and 3 minutes is of course arbitrary. However we decided to choose these interval lengths in order to avoid any microstructure noise but being still at high frequency.

To motivate our analysis, figure  shows the autocorrelation function of the order flow for TSLA and MSFT at the 3 minutes aggregation scale. Consistently with the literature (see, e.g. Lillo and Farmer Citation2004, Bouchaud et al. Citation2018), we observe that the autocorrelation function in all the cases has a slow decay. i.e. a buy (sell) trade is more likely followed by a buy (sell) trade. More quantitatively, it has been documented in many papers (see Bouchaud et al. Citation2004, Lillo and Farmer Citation2004, Bouchaud et al. Citation2006Citation2009, Yamamoto and Lebaron Citation2010, Tóth et al. Citation2015, Taranto et al. Citation2018aCitation2018b) that the autocorrelation function of trade signs ρ(τ) decays asymptotically as a power law with an exponent smaller than one ρ(τ)1τγ where γ<1 which implies that the time series is long memory with a Hurst exponent H=1γ/2>1/2.

Figure 1. Autocorrelation function of the order flow aggregated at the 3 minute time scale corresponding to N = 730 executions for TSLA (a), and N = 1200 executions for MSFT (b).

Figure 1. Autocorrelation function of the order flow aggregated at the 3 minute time scale corresponding to N = 730 executions for TSLA (a), and N = 1200 executions for MSFT (b).

The origin of this large persistence has been investigated both empirically and theoretically. Making use of labeled data allowing to identify the market member initiating each trade, Tóth et al. (Citation2015) empirically showed that the long-range persistence observed at the London Stock Exchange is strongly driven by order splitting, i.e. the same trader sequentially placing trades with the same sign, very likely as part of an optimal execution program. On the contrary, herding, i.e. groups of investors trading in the same direction in the same period, plays a much minor role.

From a theoretical point of view, the connection between order splitting and long memory of order flow has been elucidated by Lillo et al. (Citation2005) (LMF). They proposed a simple model that postulates that market participants who intend to execute large orders split them into smaller orders and trade them incrementally. The large orders are called metaorders and the small trades in which they are split and sequentially traded are termed child orders. Under the assumption that metaorders are randomly sampled from a size distribution pL (LN), the LMF model predicts the form of the autocorrelation function of trade signs. In particular, when the distribution pL is a power law (2) pL=αL1+α(2) then the autocorrelation function of trade signs decays asymptotically as (3) ρ(τ)1τα1(3) i.e. the model predicts that γ=1α. Interestingly, very recently Sato and Kanazawa (Citation2023) theoretically showed that predictions of the LMF model remain valid also when there is heterogeneity in trading frequency and size distribution across market participants.

The empirical validation of the LMF model poses some challenges because of the need for complete information on metaorders traded in the market. Lillo et al. (Citation2005) used off-market trades as a proxy of metaorders. An alternative to such proxy is suggested by Vaglica et al. (Citation2008), Moro et al. (Citation2009) and Vaglica et al. (Citation2010), who proposed segmentation algorithms and Hidden Markov Models to identify metaorders from brokerage data. Without relying on noisy proxies, Bershova and Rakhlin (Citation2013) and Zarinelli et al. (Citation2015) used private data of real metaorders by financial companies to test the power law hypothesis. In such a case, the results lacks generality since information on metaorders is company-specified. Recently, Sato and Kanazawa (Citation2023) used account-level data of the whole Tokyo Stock Exchange to directly test the LMF model. The predicted relationship between the exponent γ and α has been very accurately verified, both at the market and at the single stock level.

Summarizing, the LMF model proposes that most of the autocorrelation of order flow comes from the execution of metaorders but, due to the anonymous nature of financial markets, their presence cannot be easily and directly inferred from public market data. However, the start of the execution of a new metaorder should lead to a regime change in the order flow time series, which could be detected with suitable statistical methods. Thus the identification of a CP in the order flow might signal the arrival of a new metaorder execution. Moreover, from the market (or econometric) point of view, the identification of a CP modifies the forecasting of future order flow and price dynamics, since only past data after the last CP are useful for predictions. The practical use of such methods for CP detection requires that they work online, i.e. that the identification is done in real time and not ex-post (such as in the segmentation algorithms used, for example, in Vaglica et al. (Citation2008)). Finally, the method should allow to perform one-step ahead prediction in an online mode.

3. Methods: Bayesian online change-point detection algorithms

In the following, we briefly review the BOCPD algorithm, introduced by Adams and MacKay (Citation2007), and present two novel extensions that we propose here, namely the Markovian BOCPD (MBO) and the Markovian BOCPD for Correlated data (MBOC) algorithm. The original BOCPD algorithm relies on the assumption that the data are independent and identically distributed within each regime. To relax such a strong assumption, we propose a new MBO algorithm that considers Markovian dynamics within each regime, thus allowing for serial correlation. At this stage, both BOCPD and MBO assume that parameters (i.e. mean, variance, autocorrelation) are constant within each regime. We further relax this assumption in a generalization of the MBO, named MBOC, that accounts for time-varying correlations. Such a generalization is based on the Score Driven approach introduced by Creal et al. (Citation2013). In a companion paper Tsaknaki et al. (Citation2024), we introduce in full generality the new class of regime-shift score-driven models, where other parameters can change over time within each regime.

3.1. The BOCPD algorithm

The BOCPD algorithm for i.i.d. data has been introduced by Adams and MacKay (Citation2007). Let x1:T={x1,,xT} be a sample time series. The model assumes that data are non-stationary (because of regimes) and satisfy the product partition model (PPM), see Barry and Hartigan (Citation1992), meaning that data can be partitioned into regimes. Moreover, the parameters θR within each regime R are i.i.d. random variables drawn from some given distribution. Such a distribution needs to belong to the exponential family. Throughout the paper, we consider normal distributions. This assumption is tested using a Jarque-Bera (JB) statistic in the empirical application as shown in section 4.1.

Adams and MacKay (Citation2007), assume a time series as the realization of i.i.d. random variables from a normal distribution with unknown mean θR and known variance σ2, (4) xiN(θR,σ2).(4) Regimes and CPs separating them are not directly observable but must be inferred from data. To this end, the goal is to infer the elapsed time since the last CP, a quantity named run length and defined as follows.

Definition 3.1

The run length rt is a non-negative discrete variable defined as: (5) rt={0,if\ a\ CP\ occurs\ at\ time trt1+1,else.(5)

In the BOCPD algorithm, the arrival of a CP is modeled as a Bernoulli processFootnote2 with hazard rate 1/h: (6) p(rt|rt1)={1/h,if rt=011/h,if rt=rt1+10,otherwise.(6) The primary quantity of interest is the computation of the run length posterior p(rt|x1:t) which characterizes probabilistically the number of time steps since the last CP given the data observed so far, (7) p(rt|x1:t)=p(rt,x1:t)p(x1:t).(7) The joint distribution over both the run length and the observed data can be written recursively, (8) p(rt,x1:t)=rt1p(rt,rt1,xt,x1:t1)(8) (9) =rt1p(xt|rt1,x1:t1)UPMp(rt|rt1)Hazardp(rt1,x1:t1)Message.(9) An important assumption that simplifies the computation is about the changepoint prior, namely rt is conditionally dependent on rt1 only. The quantity p(x1:t) is named evidence and is computed as (10) p(x1:t)=rtp(rt,x1:t).(10) The Underlying Predictive Model (UPM) is defined as the predictive posterior distribution given the current run length. Because of the assumption on PPM, such a distribution depends only on the last rt1 observations and can be stated in a more compact form as (11) p(xt|rt1,x1:t1)=p(xt|xt1(rt1))(11) where (12) xt1(rt1)=xtrt1:t1andxt:t1=.(12) By using the conjugacy property of the exponential family when data are i.i.d., one obtains closed-form solutions for the UPM term, see Diaconis and Ylvisaker (Citation1979) and Murphy (Citation2007). For normal distributions, the UPM term is (13) p(xt|xt1(rt1))=N(μrt1,σ2+σrt12),(13) with posterior parameters given by (14) μrt1=i=trt1t1xiσ2+μ0σ02rt1σ2+1σ02andσrt12=(rt1σ2+1σ02)1forrt1{1,,t1}.(14) Let us stress that the run length in equation (Equation14) is a latent variable we must infer. As such, the value of the posterior parameters varies depending on rt1, i.e. where we put the last change point, whose probability is in equation (Equation7).

The BOCPD algorithm works as follows. At time t = 0, we initialize the prior values μ0,σ02 and the known variance σ2 (see below for details). At a generic time t>0, a new data point xt becomes available, and the UPM in equation (Equation13) is computed for any possible μrt1 and σrt12, as a function of the run length rt1 that takes value from 0 to t−1. Then, the joint distribution over both the run length and the observed data point, see equation (Equation8), is computed for all the possible values of the run length. Thus we obtain:

  1. the growth probabilities, (15) p(rt=l,x1:t),for l=1,,t;(15)

  2. the CP probability (16) p(rt=0,x1:t).(16)

After computing the evidence in equation (Equation10), the run length posterior is obtained by equation (Equation7). Finally, μrt and σrt2 are updated as in equation (Equation14) in order to be used at the next time t + 1.

3.2. The MBO algorithm

The assumption about the independence of data is clearly restrictive. Here we introduce the MBO algorithm as an extension of the BOCPD algorithm to the case of Markovian dependence. Similarly to before, we consider normally distributed data. As such, within a regime R, a time series is a realization of an AR(1) process with normal innovations, (17) xtN(θR,σ2),(17) (18) xt|xt1N(θR+ρ(xt1θR),σ2(1ρ2)).(18) As in the previous model, in each regime, the unconditional distribution is normal with unknown mean θR and known variance σ2. Moreover the conditional distribution is normal with constant correlation ρ=Cov(xt,xt1)σ2. In the next Section, we introduce a further generalization, allowing ρ to be time-varying within each regimeFootnote3.

The key observation is that the conjugacy property still holds when the data are Markovian since the conditional distribution of any member in the exponential family is still in the family, see Wainwright and Jordan (Citation2008). After some computations, one can obtain a closed form for the UPM term as (19) p(xt+1|xt(rt))=N(μrt+ρ(xtμrt),σ2(1ρ2)+σrt2(1ρ)2),(19) where the posterior parameters are (20) μrt=brt+μ0σ02art+1σ02andσrt2=(art+1σ02)1forrt{1,,t}(20) and (21) art=1σ2+(rt1)(1ρ)2σ2(1ρ2)(21)

(22) brt={xtσ2,forrt=1xt1σ2+(1ρ)(xtρxt1)σ2(1ρ2),forrt=2xt+1rtσ2+(1ρ)2i=t+2rtt1xi+(1ρ)(xtρxt+1rt)σ2(1ρ2),forrt{3,,t}.(22)

Let us notice that we recover the previous case when ρ=0.

3.3. The MBOC algorithm

Both the baseline model and its Markovian generalization assume that the parameters within each regime are constant. This might be unrealistic in many empirical cases. For example, heteroscedasticity, i.e. time-varying variance, is ubiquitous in financial time series. Since our interest here mostly focuses on the correlation of the order flow and its temporal dependencies, we consider a model where temporal correlation (i.e. ρ) is time-varying within the regime. This might capture the variability and temporal persistence of trading volume, which in turn depends on the available liquidity of the market.

Time-varying parameters models display typically some difficulties for estimation. Following Cox (Citation1981), we consider the class of observation-driven models where the parameters are unconditionally random variables, but evolve in time based on some nonlinear deterministic function of past observations.

In particular, we consider the class of Score-Driven models introduced by Creal et al. (Citation2013) and Harvey (Citation2013), which assume that the dynamics of the time-varying parameter(s) is autoregressive with an innovation term depending on the so-called scoreFootnote4. The score is then re-scaled by the inverse of the Fisher matrixFootnote5 , which is used to modulate the importance of the innovation according to the concavity of the log-likelihood. The intuition is simple: the scaled score adjusts the value of the parameter(s) in order to maximize the likelihood of the observed data. It is worth noticing that many standard models in financial econometrics, such as the GARCH, ACD, MEM, etc., are special cases of score-driven models (see www.gasmodel.com for more details).

We extend the MBO model by promoting the correlation coefficient ρ to a time-varying parameter ρt described by the Score-Driven version of the AR(1) process (see Blasques et al. (Citation2014)). We name such an extension as MBOC. We then introduce an online method to estimate both the time-varying parameter ρt and the regime characteristics, namely the mean θR characterizing the regime and the run length rt.

More specifically, within a regime R, the data generating process is assumed to be (23) xt=ρt(xt1θR)+θR+ut,utN(0,σ2),(23) where θR and σ2 are unknown. According to the Score-Driven AR(1) process, the time-varying correlation ρt is described by the recursive relationFootnote6 (24) ρt=ω+αst1+βρt1(24) where st is the scaled score defined as (25) st=It|t1dt,d[0,1](25) (26) t=logpu(ut)ρt(26) (27) It|t1=Et|t1[tTt](27) and ut is the prediction error associated with the observation xt. The parameter d controls the role of the Fisher matrix in modulating the role of the score in the update of the parameters. Standard choices for d are d=0,1/2,1. Each of them lead to different dynamic scale models. The vector of parameters λ=[ω,α,β,σ2] is estimated through a Maximum Likelihood Estimation method. In the analysis below, we set d = 0, i.e. we consider a not re-scaled score. It is (28) st=t=utσ2(xt1θR).(28) Then the UPM term becomes (29) p(xt+1|xt(rt))=N(μrt+ρt(xtμrt),σ2+σrt2),(29) where the posterior parameters are (30) μrt=brt+μ0σ02art+1σ02andσrt2=(art+1σ02)1for rt{1,,t},(30) and (31) art=1σ2+(rt1)(1ρt)2σ2(1ρt2)(31)

(32) brt={xtσ2,for rt=1xt1σ2+(1ρt)(xtρtxt1)σ2(1ρt2),for rt=2xt+1rtσ2+(1ρt)2i=t+2rtt1xi+(1ρt)(xtρtxt+1rt)σ2(1ρt2),for rt{3,,t}.(32)

The vector of parameters λ is estimated at each time-step within the time window associated with the most likely regime after we demean the data with the posterior mean see equation (Equation30). In particular at each time step t>1 we find i=argmaxi{1,,t}p(rt=i|x1:t) and we consider the demeaned data set xt(i)μi={xt+1iμi,,xtμi} in which we infer λ and we filter ρt with the use of the Score-Driven model. In order to robustify the algorithm and accomplish better Mean Squared Error (MSE) (see section 4.1 for more details) we define a threshold value η, then we filter the time-varying correlation and we infer the variance (see algorithm 1 for more details on the inference procedure of the MBOC model) whenever i>η. In that way, the demeaned data set contains at least η data points. The threshold value is a hyperparameter that is tuned in a preliminary phase, see below for the implementation details.

4. Results

4.1. Model estimation and empirical analysis

We estimate the three models, BOCPD, MBO, and MBOC, on the time series of aggregated order flow xt of TSLA and MSFT, both for the 1 and the 3 min aggregation time scale. The application of the models requires a careful choice of several hyperparameters. For both TSLA and MSFT, the prior value of the mean for all models is set to μ0=0 shares due to the symmetry between buy and sell orders. The tuning of the other hyperparameters is obtained by minimizing the MSE in the first day of each month and each stock. For TSLA, for all the models, the prior value of the variance of the mean is set to σ02=107 shares2, while for MSFT σ02=15107 shares2. The hazard rate is set to h=180. For both BOCPD and MBO the known variance is set to σ2=108 shares2 for TSLA while for MSFT σ2=15108 shares2. The same values for TSLA and MSFT are being used for the initial variance σi2 of the MBOC model (see algorithm 1). Moreover, the initial correlation ρ1 is set to 0.2 for TSLA and 0.3 for MSFT while the initial parameters of the Score-Driven dynamics are set to λ=[0.08,0.02,0.05,108] and the η value is set equal to 20 shares for the 1 minute and 10 shares for the 3 minute data set. The hyperparameter η is being tuned in such a way in order to obtain the best MSE. Finally, for the constant correlation coefficient ρ of MBO we have tested different specifications. In the table below we will report the results for three of them, showing that the predictive capacity of the model slightly depend on it.

4.1.1. Model comparison

We present here the results of an online prediction study for order flow data by using BOCPD, MBO, and MBOC models introduced in section 3, and we compare their performances by computing the Mean Squared Error for the predictive mean of each model. The three models are then compared with the ARMA(1,1) model, estimated on the whole time period by assuming the absence of regimes. As such, the ARMA(1,1) model represents a natural benchmark to test whether including regime-switching dynamics does improve the forecasting of order flow.

The predictive mean μˆt at time t as one step ahead forecast is defined by using observations up to time t and to predict out-of-sample the realization at time t + 1. That is (33) μˆt=rtp(xt+1|x1:t,rt,)p(rt|x1:t)=rtμrtp(rt|x1:t)(33) where μrt is defined in equations (Equation14), (Equation20), and (Equation30) for BOCPD, MBO and MBOC model respectively. Then, the MSE can be computed as (34) MSE=1Tt=1T(μˆt1xt)2.(34) Table  shows the MSE of the three aforementioned models along with the ARMA(1,1) for both TSLA and MSFT stocks. As mentioned above, we consider three different values of the correlation coefficient ρ in the MBO model. We observe that the MBOC model outperforms all competitors. In particular, the proposed models (MBO and MBOC) outperform systematically the ARMA(1,1) benchmark, while the baseline BOCPD model displays comparable performances. Finally, notice that the role of the hyperparameter ρ for the MBO model is relatively marginal.

Table 1. Comparison of out of sample one-step-ahead MSE of ARMA(1,1), BOCPD, MBO and MBOC.

In conclusion, the online prediction study with order flow data suggests that regime-switching models accounting for a Markovian correlation structure outperform both the baseline BOCPD model and the benchmark. The MBOC model displays the best forecasting performance and high flexibility in data description. In the following Sections, we exploit such flexibility in modeling regime-switching dynamics in the presence of time-varying correlations to empirically show a clear connection between regimes for aggregated order flows and the market impact of associated trades (likely including metaorders).

4.1.2. Empirical analysis of identified regimes

Here we investigate the statistical properties of the identified regimes for the aggregated order flows. We consider the MBOC model because of the best performances. Let us first introduce the adopted definition of an identified regime.

Definition 4.1

Let x1:T be a time series and t,sN[1,T] times with t<s such that (35) argmaxi{0,1,,t}p(rt=i|x1:t)=argmaxi{0,1,,s}p(rs=i|x1:s)=0(35) and for any uN(t,s), argmaxi{0,1,,u}p(ru=i|x1:u)0. Then the subset xt:s1 of the time series x1:T is defined as a regime.

The top panel of figures  and  shows xt for TSLA (MSFT) aggregated every 730 (1200) executions corresponding to an average time interval of 3 minutes. The vertical red dashed lines indicate the CPs identified by MBOC, according to the definition above. Interestingly, many CPs are observed at the end of a trading day for both stocks. On one side this is expected since overnight is a natural separation between regimes, but on the other side, this is an indication that the proposed method is able to identify regime changes.

Figure 2. Top: Order flow of Tesla at the 3 minutes aggregation time scale during December 2021. The black solid line is the predictive mean and the dashed line, the predictive standard deviation. The red dashed lines indicate the CPs the MBOC finds and as a result the regimes. The tick labels on the x-axis indicate the end of each trading day. Bottom: Run length posterior of the MBOC model. The darkest the color, the highest the probability of the run length. The red line highlights the most likely path, i.e. value of rt with the largest run length posterior p(rt|x1:t) for each t.

Figure 2. Top: Order flow of Tesla at the 3 minutes aggregation time scale during December 2021. The black solid line is the predictive mean and the dashed line, the predictive standard deviation. The red dashed lines indicate the CPs the MBOC finds and as a result the regimes. The tick labels on the x-axis indicate the end of each trading day. Bottom: Run length posterior of the MBOC model. The darkest the color, the highest the probability of the run length. The red line highlights the most likely path, i.e. value of rt with the largest run length posterior p(rt|x1:t) for each t.

Figure 3. Top: Order flow of Microsoft at the 3 minutes aggregation time scale during March 2020. The black solid line is the predictive mean and the dashed line, the predictive standard deviation. The vertical red dashed lines indicate the CPs the MBOC finds and as a result the regimes. The tick labels on the x-axis indicate the end of each trading day. Bottom: Run length posterior of the MBOC model. The darkest the color, the highest the probability of the run length. The red line highlights the most likely path, i.e. value of rt with the largest run length posterior p(rt|x1:t) for each t.

Figure 3. Top: Order flow of Microsoft at the 3 minutes aggregation time scale during March 2020. The black solid line is the predictive mean and the dashed line, the predictive standard deviation. The vertical red dashed lines indicate the CPs the MBOC finds and as a result the regimes. The tick labels on the x-axis indicate the end of each trading day. Bottom: Run length posterior of the MBOC model. The darkest the color, the highest the probability of the run length. The red line highlights the most likely path, i.e. value of rt with the largest run length posterior p(rt|x1:t) for each t.

The bottom panels of figures and show the run length posterior of the MBOC model for the two assets. For each time (on the abscissa) the vertical axis displays in grayscale the probability that the run length has a given value (on the ordinate). Darker gray regions correspond to higher probabilities. The red line highlights the most likely path, i.e. the value of rt with the largest run length posterior p(rt|x1:t) for each t. Finally, we also show the (one step ahead) predictive standard deviation defined as (36) σˆt=rtσrt2p(rt|x1:t),(36) where σrt2 is as in equations (Equation14), (Equation20), and (Equation30) for BOCPD, MBO, and MBOC models, respectively.

Regime length distribution : For the 1 (3) minute(s) data set, we find 911 (546) regimes for TSLA and 1394 (690) regimes for MSFT. Figure  shows the histograms of the length of the detected regimes. Consistently with the constant hazard function, we find that the regime length is approximately exponentially distributed with a mean regime length of 10 for the 1 minute data set and 5 for the 3 minutes data set intervals for TSLA and 7 for the 1 minute data set and 4 intervals for the 3 minutes data set of MSFT corresponding to 10 and 15 trading minutes for TSLA and to 7 and 12 trading minutes for MSFT respectively. The length of the regimes ranges in the interval [1,92] for 1 minute and in [1,30] for 3 minutes for TSLA while for MSFT in [1,65] for 1 minute and in [1,30] for 3 minutes for MSFT.

Figure 4. Histograms of regimes length for Tesla (a) with Δt=1min, (b) with Δt=3min and for Microsoft (c) with Δt=1min, (d) with Δt=3min.

Figure 4. Histograms of regimes length for Tesla (a) with Δt=1min, (b) with Δt=3min and for Microsoft (c) with Δt=1min, (d) with Δt=3min.

Gaussianity inside regimes : The main assumption of both BOCPD and MBO is that the variable xt is Gaussian within each regime, with constant parameters. For MBOC, we expect that xt is only conditionally Gaussian, because of the time-varying autocorrelation, but not unconditionally over the whole period and only approximately within a regime. The Jarque-Bera (JB) test rejects the Gaussianity hypothesis of unconditional aggregated order flow {xt}t=1,,T at a 1% significance level, for both stocks and time scales. We then perform the JB test within each regime detected by the MBOC model. For the 3 minute time scale, we cannot reject the null hypothesis at 5% confidence level for 94% (95%) of the regimes for TSLA (MSFT). When we consider the 1 minute time scale, the frequency of rejection is 86% (87%). These findings support the choice of MBOC to identify regimes with order flows as approximately Gaussian within each regime.

Autocorrelation of residuals inside regimes : As a final model checking we test for the lack of serial correlation in the residuals of our model within each regime. We have seen above that, coherently with the literature, vt is strongly autocorrelated. Following Lillo et al. (Citation2005), our assumption is that this correlation is driven by the presence of regimes, which in turn are likely associated with metaorders. We thus apply the Ljung-Box test to the residuals in each regime. For the 3 minute time scale, we cannot reject the null hypothesis of uncorrelated residuals for 98% (99%) of the regimes of TSLA (MSFT), with 5% confidence level. For the 1 minute time scale, the frequency of rejection is 97% (93%). It is possible to conclude that the MBOC model captures most of the serial correlation of aggregated order flow. Notice that, according to the model, the unconditional slow decay of the autocorrelation of order flow observed in the literature (see also figure ) is due largely to regime-switching dynamics and, only partially, to Markovian temporal dependencies.

4.2. Price impact during order flow regimes

In this Section, we empirically study the average price dynamics inside a detected order flow regime and we measure the relation between the total price change and the net volume exchanged in the same regime.

4.2.1. Price as a function of time inside an order flow regime

As said, we first study the average price dynamics during an order flow regime. This type of analysis mirrors the one performed, for example, by Bacry et al. (Citation2015) and Zarinelli et al. (Citation2015) which studied the average price dynamics during the execution of a metaorder. Using labeled data allowing to identify when an institutional investor executed a metaorder, these papers find that (i) the average price dynamics is correlated with the conditioning metaorder sign, i.e. the price increases (decreases) when a buy (sell) metaorder is executed; (ii) the price dynamics is concave in time, i.e. the price increases faster at the beginning of a buy metaorder and slowly toward the end.

Here we take a step forward by asking what is the average price dynamics during a regime of aggregated order flow detected with the MBOC model. To this end, for each detected regime R (see definition 4.1), characterized by an initial time tR and a final time sR>tR, we denote with ϵR=sign(tRt<sRxt) the sign of the order flow in the regime, being equal to +1 (1) when the regime is dominated by the volume of buyer (seller) initiated trades. Since during a metaorder execution we expect a significant net imbalance of buy or sell volume, we will consider subsets of regimes for which (37) ZR:=|tRt<sRxttRt<sR|xt||>Θ,0Θ<1(37) i.e. when the difference between buy and sell volume divided by their sum is larger than Θ. Notice that when Θ=0 the subset coincides with the entire set of regimes identified by the MBOC. Appendix A.1 reports the number of regimes in the different subsets.

Indicating with pt the log-price of the last transaction in the interval labeled by time t, we compute the log-price change between the beginning of the regime and tR+k, where 0k<sRtR and we take the average (38) IΘ(k)=ER[ϵR(ptR+kptR1)|tR+k<sR,ZR>Θ].(38) With ER[], we denote the sample average over the regimes, i.e. that tR is the first interval of a regime, and the conditioning restricts it to those regimes for which the observation at tR+k is in the same regime as the one at tR as well as to those regimes that satisfy condition in equation (Equation37).

Figure  shows the impact function IΘ(k) as a function of k for the two stocks and the two time scales when Θ=0,0.5, and 0.9. Error bars are standard errors in each bin. We notice that in all cases impact is positive and increasing. This is somewhat expected since we are implicitly conditioning on the sign of order flow in the whole regime, thus the observed behavior is coherent with the known correlation between aggregated order flow and contemporaneous price change, see Bouchaud et al. (Citation2009), Patzelt and Bouchaud (Citation2018). Interestingly the price dynamics is a concave function of time, similarly to what is observed when conditioning on metaorders execution instead of on order flow regimes. Moreover the degree of concavity increases with Θ. Clearly the concavity is not expected by the mere fact that the regime is characterized by a net order flow sign, while it could instead be explained by the Transient Impact Model of Bouchaud et al. (Citation2004) or by the LLOB model of Donier et al. (Citation2015), which predicts a concave average price temporal profile when the order flow has a non-zero average as during a metaorder execution.

Figure 5. Market Impact IΘ(k) defined in equation (Equation38) for Tesla (a) with Δt=1 min, (b) with Δt=3 min and for Microsoft (c) with Δt=1 min, (d) with Δt=3 min. The plotted quantities are in basis points. Error bars are standard errors. The black dashed line indicates the y = 0 axis.

Figure 5. Market Impact IΘ(k) defined in equation (Equation38(38) IΘ(k)=ER[ϵR(ptR+k−ptR−1)|tR+k<sR,ZR>Θ].(38) ) for Tesla (a) with Δt=1 min, (b) with Δt=3 min and for Microsoft (c) with Δt=1 min, (d) with Δt=3 min. The plotted quantities are in basis points. Error bars are standard errors. The black dashed line indicates the y = 0 axis.

4.2.2. Price impact as a function of volume

Finally, we study the relation between the total price change in a regime and the total net volume in the same time span. A large body of empirical literature Torre (Citation1997), Almgren et al. (Citation2005), Moro et al. (Citation2009), Tóth et al. (Citation2011), Bershova and Rakhlin (Citation2013), Zarinelli et al. (Citation2015) and Tóth et al. (Citation2016) have shown that on average the total price impact during a metaorder execution scales with a sublinear power law of metaorder volume, a relation well fit by a power law with an exponent ranging in [0.4,0.7]. This is the celebrated square root impact law. It is therefore natural to investigate empirically the relation between the same two quantities within a regime identified with our method.

To this end, defining ΔpR=psRptR we consider the non-linear regression: (39) ϵRΔpR=A(ϵRtRt<sRxt)γ+noise.(39) Since the measurement of market impact is notoriously very noisy, we have performed the estimation both on the original dataset and on a dataset where potential outliers are removed. In the latter approach, we used the standard procedure of considering outliers datapoints corresponding to regimes whose price change is smaller (larger) than the first (third) quartile minus (plus) 1.5 times the interquartile range (see appendix A.2 for details).

Table  reports the estimated parameters when outliers are removed, while appendix A.2 reports the results for the entire dataset and presents the scatter plots of the data and the fitted curve. Both Tables indicate that the exponent γ is smaller than one and for the data without outliers it is remarkably close to 0.5, as postulated by the square root law.

Table 2. Estimated parameters and their standard errors (SE) of the regression of equation (Equation39).

Clearly these results are preliminary and should be validated on larger panels of stocks, also pooling them together with the usual rescaling by daily volatility and volume. However we find these results very encouraging and suggestive of a relation between the identified regimes and the execution of metaorders.

4.3. Online prediction of order flow and market impact

The possibility of performing an online detection of regimes and regime changes in the order flow opens the question of how to use this information to predict subsequent order flow and price changes. In the PPM, regimes are independent, hence in forecasting future values only data from the current regime are useful, while older data add noise to the prediction. This idea will be used to build online predictions of order flow. Additionally, through market impact, price dynamics is correlated with order flow. Thus a proper modeling of order flow is useful to forecast future price.

Since we have seen in the last Section that order flow sign of a regime correlates with contemporaneous price change, we can ask the question of whether the knowledge that a new regime in order flow has just started allows to predict the future order flow and, more importantly, the future price dynamics. Consistently with the results of section 4.1 showing that the MBOC model outperforms the competitors (BOCPD, MBO, ARMA) in one step ahead prediction of order flow, here we focus our analyses on the regimes identified by MBOC. It is important however to stress that qualitatively similar results are obtained with the other two simpler models, BOCPD and MBO. In other words the relation between price dynamics and aggregated order flow is importantly understood by using regimes, while the choice of the specific regime shift model improves the short-term prediction of aggregated order flow. However, as shown in in the appendix 2, the MBOC method achieves higher predictability wrt the other CP detection methods.

To better understand the role of regimes in prediction, let consider the following argument. If the data generating process of order flow is truly consistent with a product partition model (i.e. independent regimes), the knowledge of the data of the previous regimes is not useful for prediction. Thus in this case, it is better to use only the data in the current regime and its learned statistical properties. However, even if we are relatively sure that a new regime has just started, its parameters could be quite uncertain at the beginning. Thus, in order to form a forecast, it is better to wait for few observations into a new regime. Moreover, if many regimes are very short (e.g. composed by one or two intervals), as observed empirically in figure , it might be better to build predictions after the observation of a few intervals in a regime.

Online order flow prediction : Following the above argument, we adopt the following procedure. Whenever we detect a CP in an online fashion for the time series of order flow, we measure the correlation (40) Iϵ(1)(k)=ER[sign(xtR)sign(xtR+k)]k=1,2,(40) where ER indicates that we are conditioning on the fact that tR is the first observation of a new regime. Notice that (i) the correlation is extended to values of k possibly beyond the end of the detected regime (at time sR); (ii) we do not consider the case k = 0 since in this case the correlation is trivially equal to 1. The superscript (1) in the above expression means that we take the sign of the aggregated order flow in the first interval (see below for an extension).

The continuous yellow line in figure  shows that Iϵ(1)(k) is a poor predictor of order flow. To better quantify this statement, the dashed yellow line in the figure is the unconditional correlation (41) I~ϵ(1)(k)=E[sign(xt)sign(xt+k)]k=1,2,(41) which makes no use of regime detection (and for this reason the expectation does not have the subscript R; the tilde refers to the expectation without considering regimes). Clearly, the unconditional correlation is larger than the conditional one.

As said above, one of the reasons of the comparable performance of Iϵ(1) with respect to I~ϵ(1) is the fact that there are many regimes of length one and also that the sign of the new regime, ϵR, might be poorly measured by the sign of the first interval sign(xtR). A better option is to wait few more intervals within the regime before building the predictor. Thus, defining m=1,2, the number of intervals in a regime we wait before forming the prediction, we introduce the correlation (42) Iϵ(m)(k)=ER[sign(t=tRtR+m1xt)sign(xtR+m1+k)]k=1,2,(42) which is the correlation between the sign of the order flow in the first m intervals of a regime and the sign of the order flow in an interval k steps after these m intervals. Notice that we are not conditioning on the fact that tR+m1+k is in the same regime as tR, so the two observation could belong to different regimes. However, we condition on the fact that tR+m1 is in the same regime as tR. Similarly we use as a benchmark case the predictor (43) I~ϵ(m)(k)=E[sign(s=tt+m1xs)sign(xt+m1+k)]k=1,2,.(43) The orange, red, and dark red continuous lines in figure  show Iϵ(m)(k) for m = 2, 3, 4 respectively, while the corresponding dashed lines refer to I~ϵ(m)(k). We observe that the correlations based on regimes are larger than the corresponding ones without regimes, especially for large m. This empirical evidence indicates that the knowledge of the order flow regimes improves the short-term predictability of order flow.

Figure 6. Online order flow prediction for Tesla (a) with Δt=1min, (b) with Δt=3min and for Microsoft (c) with Δt=1min, (d) with Δt=3min. The plotted quantities are defined in equations (Equation42) and (Equation43) and error bars are standard errors.

Figure 6. Online order flow prediction for Tesla (a) with Δt=1min, (b) with Δt=3min and for Microsoft (c) with Δt=1min, (d) with Δt=3min. The plotted quantities are defined in equations (Equation42(42) Iϵ(m)(k)=ER[sign(∑t=tRtR+m−1xt)⋅sign(xtR+m−1+k)]k=1,2,…(42) ) and (Equation43(43) I~ϵ(m)(k)=E[sign(∑s=tt+m−1xs)⋅sign(xt+m−1+k)]k=1,2,….(43) ) and error bars are standard errors.

Online market impact prediction : We now consider the prediction of price change based on the knowledge of being in a regime of order flow. To this end we introduce the online impact (44) IΔp(m)(k)=ER[sign(t=tRtR+m1xt)(ptR+m1+kptR+m1)]k=1,2,(44) which is the correlation between the sign of the total order flow in the m initial intervals of a regime and the subsequent price change over k intervals. Compared to equation (Equation38), two important differences are worth to be highlighted. First, the sign inside the expectation is taken only on the aggregated order flow of the m intervals used to build the prediction, while in equation (Equation38) ϵR considers the sign of the whole regime and therefore is non-causal. Second, in IΔp(m)(k) we do not condition on sRtR>k as in equation (Equation38) since after having observed m intervals in a regime we do not know when the regime is going to end. In other words, for a given k, we take the average both on cases when tR and tR+k belong to the same regime and when they do not. Finally, as before we use as a benchmark an impact predictor that is based on the sign of the order flow, (45) I~Δp(m)(k)=E[sign(s=tt+m1xs)(pt+m1+kpt+m1)]k=1,2,.(45) When m = 1 the quantity I~Δp(m)(k) becomes the response function widely investigated in the market impact literature, mainly in transaction time, see Bouchaud et al. (Citation2004) and Bouchaud et al. (Citation2009). We choose this more general definition in order to make a fairer comparison between impact predictors using the same number of past order flow observations.

Figure  shows these different quantities for online market impact prediction, considering both stocks and both time intervals. It is evident that as soon as m>1, IΔp(m)(k) (orange to dark red lines) is much larger than the corresponding response function I~Δp(m)(k) (dashed orange to dark red lines) which does not make use of regimes. Moreover, the larger m, the larger the correlation between the order flow sign and the future price change, in all four investigated cases. Thus the (online) knowledge that a regime has started provides a significant additional forecasting power to future price change with respect to the response function, which is an unconditional cross-correlation between current order flow and future price change.

Figure 7. Online market impact prediction for Tesla (a) with Δt=1 min, (b) with Δt=3 min and for Microsoft (c) with Δt=1 min, (d) with Δt=3 min. The plotted quantities (in basis points) are defined in equations (Equation44) and (Equation45) and error bars are standard errors.

Figure 7. Online market impact prediction for Tesla (a) with Δt=1 min, (b) with Δt=3 min and for Microsoft (c) with Δt=1 min, (d) with Δt=3 min. The plotted quantities (in basis points) are defined in equations (Equation44(44) IΔp(m)(k)=ER[sign(∑t=tRtR+m−1xt)⋅(ptR+m−1+k−ptR+m−1)]k=1,2,…(44) ) and (Equation45(45) I~Δp(m)(k)=E[sign(∑s=tt+m−1xs)⋅(pt+m−1+k−pt+m−1)]k=1,2,….(45) ) and error bars are standard errors.

5. Conclusion

In this work, we proposed the use of Bayesian Online Change Point Detection Methods to identify (in a real-time setting) regimes in time series of aggregated order flow of financial assets. Since the existing methods make very strong assumptions on the data generating process, in particular for what concerns the serial correlation of data within each regime, we proposed here two extensions of the regime detection algorithm: the first one assumes a Markovian dynamics inside each regime, while the second one makes use of an observation driven dynamics based on the score-driven mechanism. As shown by the recent econometric literature, the score driven approach is extremely flexible also as a filter of a misspecified dynamics (tantamount to GARCH). The companion paper (Tsaknaki et al. Citation2024) provides more methodological details of this new class of models by discussing different specifications where other parameters (e.g. the variance) are time-varying within each regime. The analysis of two liquid stocks traded in the NASDAQ market shows that the new algorithms presented here, particularly the latter, outperform the baseline model in out-of-sample forecasting. In general, we find that the regime-switching methods outperform standard econometric time series models like ARMA(1,1). Moreover, a careful model checking shows that the algorithm outputs well specified regimes both in terms of Gaussianity of data and of lack of serial correlation of residuals, within each regime.

From the financial point of view, the identification of weakly autocorrelated regimes in the order flow time series suggests that the observed unconditional long memory might be explained by regime switching. This is in line with the mechanism proposed by Lillo et al. (Citation2005) who connected the long memory to order splitting by heterogeneous institutional investors. It is natural at this point to try to identify the detected regimes with time periods when one or a few institutional investors are trading a large order. Of course, we do not have any empirical evidence in support of this idea which, at this point, can be considered as a conjecture to be tested with suitable data (for example those used by Zarinelli et al. (Citation2015) or Sato and Kanazawa (Citation2023)).

The paper shows how the online identification of regimes can be used to significantly improve the forecasting of order flow and of price dynamics. Using the knowledge of the order flow during the current regime provides better predictions when compared with methods using unconditionally the past history of order flow. We foresee that such improvement could be fruitfully used in several financial applications, such as optimal trading, market making, and alpha signal detection. Similarly, if our interpretation above is correct, the online regime detection method could be used to statistically identify the execution of a large institutional execution from anonymous market data.

Disclosure statement

No potential conflict of interest was reported by the author(s).

Data availability statement

The data that support the findings of this study are not publicly available but can be purchased at https://lobsterdata.com.

Additional information

Funding

This paper is funded by the European Union Next Generation EU with grant number PNRR IR0000013 ‘SoBigData.it’.

Notes

1 I.e. the sequence of signed trade volume, positive (negative) when buyer (seller) initiated.

2 Other assumptions on the distribution of regimes can be implemented, for example, those leading to a non-exponential distribution of regime length. This more realistic extension is left for future research.

3 We have also explored a further generalization where the variance inside each regime is time-varying, similarly to a GARCH model. The results for the order flow are qualitatively similar and we do not present them here. The reader interested in this model can consult the companion paper Tsaknaki et al. (Citation2024).

4 We remind that the score is the derivative of the log-likelihood with respect to the parameter(s).

5 The Fisher matrix is defined as It|t1=Et|t1[tTt] where t is defined in equation (Equation26).

6 This specification does not guarantee that |ρt|1, thus sometimes one uses a link function (e.g. an inverse logistic) which maps [1,1] in R, see Blasques et al. (Citation2014). In our empirical analysis, we observe that the filtered |ρt| is larger than 1 in less than one per thousand observations, thus we simply set a threshold |ρt|1.

References

  • Adams, R.P. and MacKay, D.J.. Bayesian online changepoint detection. Preprint arXiv:0710.3742, 2007.
  • Almgren, R., Thum, C., Hauptmann, E. and Li, H., Direct estimation of equity market impact. Risk, 2005, 18, 57–62.
  • Bacry, E., Iuga, A., Lasnier, M. and Lehalle, C.-A., Market impacts and the life cycle of investors orders. Market Microstruct. Liquidity, 2015, 1, 1550009.
  • Barry, D. and Hartigan, J.A., Product partition models for change point models. Ann. Statist., 1992, 20, 260–279.
  • Bershova, N. and Rakhlin, D., The non-linear market impact of large trades: Evidence from buy-side order flow. Quant. Finance, 2013, 13, 1759–1778.
  • Blasques, F., Koopman, S. and Lucas, A., Optimal formulations for nonlinear autoregressive processes. Working Paper 14-103/III, Tinbergen Institute, 2014.
  • Bouchaud, J.-P., Bonart, J., Donier, J. and Gould, M., Trades, Quotes and Prices: Financial Markets under the Microscope, 2018 (Cambridge University Press: North-Holland).
  • Bouchaud, J.-P., Farmer, J.D. and Lillo, F., How markets slowly digest changes in supply and demand. In Handbook of Financial Markets: Dynamics and Evolution, Handbook of Finance, 2009.
  • Bouchaud, J.-P., Gefen, Y., Potters, M. and Wyart, M., Fluctuations and response in financial markets: The subtle nature of ‘random’ price changes. Quant. Finance, 2004, 4, 176–190.
  • Bouchaud, J., Kockelkoren, J. and Potters, M., Random walks, liquidity molasses and critical response in financial markets. Quant. Finance, 2006, 6(02), 115–123.
  • Cox, D., Statistical analysis of time series: Some recent developments. Scand. J. Statist., 1981, 8, 93–115.
  • Creal, D., Koopman, S.J. and Lucas, A., Generalized autoregressive score models with applications. J. Appl. Econom., 2013, 28, 777–795.
  • Diaconis, P. and Ylvisaker, D., Conjugate priors for exponential families. Ann. Statist., 1979, 7, 269–281.
  • Diebold, F.X. and Inoue, A., Long memory and regime switching. J. Econom., 2001, 105, 131–159.
  • Donier, J., Bonart, J., Mastromatteo, I. and Bouchaud, J.P., A fully consistent, minimal model for non-linear market impact. Quant. Finance, 2015, 15, 1109–1121.
  • Fan, Z. and Mackey, L., Empirical Baysian analysis of simultaneous changepoints in multiple data sequences. Ann. Appl. Stat., 2017, 11, 2200–2221.
  • Fearnhead, P. and Liu, Z., On-line inference for multiple changepoint problems. J. Royal Statist. Soc., 2007, 69, 589–605.
  • Ghahramani, Z., Probabilistic machine learning and artificial intelligence. Nature, 2015, 521, 452–459.
  • Granger, C. and Hyung, N., Occasional Structural Breaks and Long Memory, pp. 399–421, 1999 (Department of Economics, University of California: San Diego).
  • Harvey, A., Dynamic Models for Volatility and Heavy Tails: With Applications to Financial and Economic Time Series, 2013 (Cambridge University Press: Cambridge).
  • Lillo, F. and Farmer, J.D., The long memory of efficient market. Stud. Nonlinear Dyn. Econom., 2004, 8, 1.
  • Lillo, F., Mike, S. and Farmer, J., Theory for long memory in supply and demand. Phys. Rev. E., 2005, 71, 066122.
  • Lillo, F., Order Flow and Price Formation, Volume Machine Learning and Data Sciences for Financial Markets: A Guide to Contemporary Practices, 2023 (Cambridge University Press: Cambridge).
  • Lleo, S., Zhitlukhin, M. and Ziemba, W.T., Using a mean-changing stochastic processes exit–entry model for stock market long–short prediction. J. Portfolio Manag., 2022, 49, 172–197.
  • Lleo, S., Ziemba, W.T. and Li, J., Do factor models explain breaks in the distribution of equity returns? J. Portfolio Manag., 2023, 50, 111–131.
  • Lleo, S., Ziemba, W.T. and Li, J., Exploring breaks in the distribution of stock returns: Empirical evidence from apple Inc. SSRN Working Paper 3700419, 2020 (Elsevier).
  • Mikosch, C. and Starica, C., Change of structure in financial time series, long range dependence and the garch model. Technical Report, preprint available at https://www.ine.pt/revstat/pdf/rs040103.pdf, 1999.
  • Moro, E., Vicente, J., Moyano, L.G., Gerig, A., Farmer, J.D., Vaglica, G., Lillo, F. and Mantegna, R.N., Market impact and trading profile of hidden orders in stock markets. Phys. Rev. E., 2009, 80, 452–459.
  • Murphy, K.P., Conjugate Bayesian analysis of the gaussian distribution. Technical report, University of British Columbia, 2007.
  • Patzelt, F. and Bouchaud, J.-P., Universal scaling and nonlinearity of aggregate price impact in financial markets. Phys. Rev. E., January, 2018, 97, 012304.
  • Sato, Y. and Kanazawa, K., Inferring microscopic financial information from the long memory in market-order flow: A quantitative test of the lillo-mike-farmer model. Phys. Rev. Lett., 2023, 131, 197401.
  • Sato, Y. and Kanazawa, K., Exact solution to a generalised lillo-mike-farmer model with heterogeneous order-splitting strategies, arXiv:2306.13378, 2023.
  • Tóth, B., Lempérière, Y., Deremble, C., de Lataillade, J., Kockelkoren, J. and Bouchaud, J.-P., Anomalous price impact and the critical nature of liquidity in financial markets. Phys. Rev. X., October, 2011, 1, 021006.
  • Tóth, B., Palit, I., Lillo, F. and Farmer, J.D., Why is equity order flow so persistent? J. Econ. Dyn. Control, 2015, 51, 218–239.
  • Taranto, D., Bormetti, G., Bouchaud, J., Lillo, F. and Toth, B., Linear models for the impact of order flow on prices. I. History dependent impact models. Quant. Finance, 2018a, 18(6), 903–915.
  • Taranto, D., Bormetti, G., Bouchaud, J., Lillo, F. and Toth, B., Linear models for the impact of order flow on prices. II. The mixture transition distribution model. Quant. Finance, 2018b, 18(6), 917–931.
  • Torre, N., Barra Market Impact Model Handbook, 1997 (BARRA Inc.: Berkeley).
  • Tóth, B., Eisler, Z. and Bouchaud, J.-P., The square-root impact law also holds for option markets. Wilmott, 2016, 2016(85), 70–73.
  • Tsaknaki, I.-Y., Lillo, F. and Mazzarisi, P., A score driven Bayesian online change-point detection model (in preparation), 2024.
  • Vaglica, G., Lillo, F. and Mantegna, R.N., Statistical identification with hidden markov models of large order splitting strategies in an equity market. New. J. Phys., 2010, 12, 075031.
  • Vaglica, G., Lillo, F., Moro, E. and Mantegna, R.N., Scaling laws of strategic behavior and size heterogeneity in agent dynamics. Phys. Rev. E., 2008, 77, 036110.
  • Wainwright, M.J. and Jordan, M.I., Graphical models, exponential families, and variational inference. Found. Trends Machine Learn., 2008, 1, 1–305.
  • Xuan, X. and Murphy, K., Modeling changing dependency structure in multivariate time series. In Proceedings of the International Conference on Machine Learning (ICML-07), Vol. 24, pp. 1055–1062, 2007 (PMLR: Brookline).
  • Yamamoto, R. and Lebaron, B., Order-splitting and long-memory in an order-driven market. Eur. Phys. J. B-Condensed Matter Complex Syst., 2010, 73(1), 51–57.
  • Zarinelli, E., Treccani, M., Farmer, J. and Lillo, F., Beyond the square root: Evidence for logarithmic dependence of market impact on size and participation rate. Market Microstruct. Liquidity, 2015, 1, 1550004.
  • Zhao, Y., Landgrebe, E., Shekhtman, E. and Udell, M., Online missing value imputation and change point detection with the gaussian copula. In Proceedings of the AAAI Conference on Artificial Intelligence (AAAI-22), Vol. 36, pp. 9199–9207, 2022 (AAAI Press: Palo Alto).

Appendices

Appendix 1.

Price dynamics inside an order flow regime

A.1. Concavity of order flow regimes

In table  we report the number of regimes that satisfy the condition: (A1) ZR:=|tRt<sRxttRt<sR|xt||>Θ(A1) for various values of Θ.

Table B1. Number of regimes satisfying the condition in equation (EquationA1) for Θ=0,0.5 and 0.9, for both TSLA and MSFT with Δt=1 min and Δt=3 min.

A.2. Testing the square root impact law

Table  presents the estimation of the parameters of the regression in equation (Equation39) when we consider the entire data sets without removing any outliers. We observe that the exponent γ is a bit larger than 1/2 being typically close to 0.7.

Table B2. Estimated parameters and their standard errors (SE) of the regression of equation (Equation39).

The outlier removal is obtained by the standard interquartile approach. Namely, we compute the first and third quartile Q1 and Q3, respectively, of log-returns. Then the data points outside the range [Q11.5IQR,Q3+1.5IQR], where IQR = Q3−Q1,are considered as outliers.

Figure  illustrates the data and the fits for the two stocks and the two timescales. The red points are those which are identified as outliers.

Figure A1. Data points and best fitting curves according to the regression of equation (Equation39) with Θ=0 for Tesla (a) with Δt=1 min, (b) with Δt=3 min and for Microsoft (c) with Δt=1 min, (d) with Δt=3 min. The plotted quantities are in basis points. The red points are the outliers. The green line is the fitting curve of the entire data set, while the orange line is the fitting curve when the outliers are excluded.

Figure A1. Data points and best fitting curves according to the regression of equation (Equation39(39) ϵRΔpR=A(ϵR∑tR≤t<sRxt)γ+noise.(39) ) with Θ=0 for Tesla (a) with Δt=1 min, (b) with Δt=3 min and for Microsoft (c) with Δt=1 min, (d) with Δt=3 min. The plotted quantities are in basis points. The red points are the outliers. The green line is the fitting curve of the entire data set, while the orange line is the fitting curve when the outliers are excluded.

Appendix 2.

Comparison of order flow and market impact predictions under different regime shift models

Figure  compares the correlation function Iϵ(m)(k) of order flow for the MBOC and the BOCPD model. Figure  compares the predictor of market impact IΔp(m)(k) for the same models.

Figure A2. Online order flow prediction according to MBOC (solid lines) and BOCPD (dotted lines) models with Δt=3 min (a) for Tesla and (b) for Microsoft.

Figure A2. Online order flow prediction according to MBOC (solid lines) and BOCPD (dotted lines) models with Δt=3 min (a) for Tesla and (b) for Microsoft.

Figure A3. Online market impact prediction according to MBOC (solid lines) and BOCPD (dotted lines) models with Δt=3 min (a) for Tesla and (b) for Microsoft.

Figure A3. Online market impact prediction according to MBOC (solid lines) and BOCPD (dotted lines) models with Δt=3 min (a) for Tesla and (b) for Microsoft.

From both figures, it is evident that the MBOC model outperforms the BOCPD when m>1. This justifies why in the main text we present the results obtained with the MBOC model.