{'fraction_non_alphanumeric': 0.03133109539794777, 'fraction_numerical': 0.01523700688046092, 'mean_word_length': 4.440932642487047, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 0, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Efficiency of the Moscow Stock Exchange before 2022

This paper investigates the degree of efficiency for the Moscow Stock Exchange. A market is called efficient if prices of its assets fully reflect all available information. We show that the degree of market efficiency is significantly low for most of the months from 2012 to 2021. We calculate the degree of market efficiency by (i) filtering out regularities in financial data and (ii) computing the Shannon entropy of the filtered return time series. We developed a simple method for estimating volatility and price staleness in empirical data in order to filter out such regularity patterns from return time series. The resulting financial time series of stock returns are then clustered into different groups according to some entropy measures. In particular, we use the Kullback–Leibler distance and a novel entropy metric capturing the co-movements between pairs of stocks. By using Monte Carlo simulations, we are then able to identify the time periods of market inefficiency for a group of 18 stocks. The inefficiency of the Moscow Stock Exchange that we have detected is a signal of the possibility of devising profitable strategies, net of transaction costs. The deviation from the efficient behavior for a stock strongly depends on the industrial sector that it belongs to.


Introduction
When prices reflect all available information, the market is called efficient [1]. One way to claim the efficiency of a market is by testing the Efficient Market Hypothesis (EMH). In its weak form, the EMH considers that the last price incorporates all the past information about market prices [2]. If the weak form of EMH is rejected, previous prices help to predict future prices. For traders, market efficiency means that analyzing the history of previous prices does not help to design a strategy that produces abnormal profits. For a company issuing shares, market efficiency means that the cost of its share already reflects all information about the valuation and decisions of the company. The EMH is of great interest also in research. Mathematical models of an asset price are usually based on the assumption that the price follows a martingale: the expected value of a future price is the current value of the price. If the EMH is rejected, there should be an estimation of the future price that is better than its current value. In such a case, new models should be created.
A review of studies confirming the EMH was presented by Fama in 1970 [2] and then in 1991 [3]. The martingale hypothesis was also tested later. It was shown that the efficiency of a market depends on the development of the country [4]. Moreover, the martingale hypothesis was confirmed on short time intervals, but it may be violated on longer intervals [5]. In addition, there is a range of strategies designed to increase an expected profit. High-frequency and algorithmic trading strategies are discussed in [6]. Statistical and machine learning methods for high frequency trading are reviewed in [7]. The existence of such profitable strategies contradicts the Efficient Market Hypothesis. According to Grossman and Stiglitz [8], the degree of market inefficiency determines the effort investors are willing to expend to gather and trade on information.
The goal of this paper is to investigate the degree of stock market efficiency of the Moscow stock Exchange using the Shannon entropy. We quantify the degree of market inefficiency and the degree of price randomness. We aim to distinguish between price predictability due to stylized facts of financial time series [9] and due to market inefficiency. In particular, we consider volatility clustering and price staleness as data regularities needed to be filtered out. Based on the behavior of stock prices, we group them into clusters using several measures. Combining stocks into one cluster means a common price behavior that moves prices away from complete randomness.
A range of methods is used to measure a degree of market efficiency. In particular, Cajueiro and Tabak used the Hurst exponent and R/S statistics to rank efficiency of markets [10,11]. The Hurst exponent was measured on Bitcoin data to compare it with mature markets [12]. A generalized version of the use of the Hurst exponent, multifractal detrended fluctuation analysis, was applied to investigate the efficiency of stock and credit markets [13]. The algorithmic complexity of return time series was applied to measure the efficiency of financial markets [14] and to check the Efficient Market Hypothesis [15]. Finally, the Shannon entropy as a measure of randomness is used in a range of articles; see [16][17][18]. The general idea of these methods is to compare the characteristic of the time series with the value corresponding to a completely random process. In our study, we use Monte Carlo simulations to determine which deviations from a completely random process are statistically significant.
Before estimating the degree of market efficiency, we need to dispose of regularities that make prices more predictable but that do not imply any profitable strategies. A method for filtering regularities was introduced in [19]. However, such a process of filtering has not usually been applied in other research studies. In fact, deviations of price behavior from perfect randomness may be the result of some known regularity pattern, such as volatility clustering or daily seasonality, but not a signal of market inefficiency. One of the innovations of this article is a new method for filtering data regularities, allowing the estimation of volatility and a degree of price staleness minute by minute.
We process data by filtering regularities of financial time series including volatility clustering and price staleness. Price staleness is defined as a lack of price adjustments yielding 0-returns. Traders may trade less because of high transaction costs and so the price does not update. See [20] for more details. Price staleness produces an extra amount of 0-returns called excess 0-returns . The other source of 0-returns in the time series is price rounding. Estimations of volatility and degree of price staleness are mutually connected: Excess 0-returns appear due to price staleness tend to underestimate volatility. At the same time, volatility estimation is needed to calculate the expected amount of 0-returns due to rounding.
One method for estimating volatility in the presence of excess 0-returns was presented in [21]. It uses expectation-maximization algorithm [22] to estimate returns in the places of all 0-returns and uses the GARCH(1,1) model to estimate volatility [23]. The maximization of the likelihood function appearing at each step of the considered algorithm requires several parameters for numerical optimization. If the estimation of volatility is sensitive to these parameters, which are user-defined, then they may affect the entropy of returns standardized by volatility and the amount of 0-returns in the time series. In this article, we suggest a modification of moving average volatility estimations that require an adjustment of the only parameter that can be defined using out-of-sample testing. The idea is to adopt a simple method for volatility estimation such that price staleness is taken into consideration. Moreover, while estimating volatility, we filter out excess 0-returns.
The degree of market efficiency has been measured for many countries. Stock indices for 20 countries were considered in [24]. The efficiency of 11 emerging markets and the US and Japan markets was measured in [10]. US stock markets were considered in a recent paper [25]. A review of articles about Baltic countries was presented in [26]. A degree of uncertainty of Chinese [27], Tunisian [28], Mexican [29], and Portuguese [30] stock markets was also considered by using entropy measures. However, the efficiency of the Russian stock market has not yet been analyzed. In this paper, we present an analysis of market efficiency based on the estimation of Shannon entropy for a group of 18 stocks of Russian companies from five industries.
Our paper introduces four original contributions in the field. First, we construct a method for filtering out heteroskedasticity and price staleness. This filtering process helps identify a true degree of market inefficiency. Second, we calculate the degree of market inefficiency for the previous decade using monthly intervals. We conclude that the degree of market inefficiency for the Moscow Stock Exchange was greater than 80%. Third, we determine which pair of stocks exhibits the largest amount of inefficiency, as measured by estimating Shannon's entropy on their high-frequency price time series. We show that months where the predictability of stock prices attains its maximum cluster together. We find out the form of behavior that is repeated most often with respect to stocks for inefficient time periods. Finally, we estimate the closeness of price movements using two measures of entropy. Based on these results, we cluster together groups of stocks for which the efficient market hypothesis is rejected, thus pointing out how market inefficiency displays some dependence on the financial sector they belong.
The article is organized as follows. Section 2 describes the dataset and the method for filtering data regularities and calculating the Shannon entropy. Section 3 presents the results on simulated and real data. Section 4 concludes the paper.

Materials and Methods
Our main goal is to measure a degree of efficiency of the Moscow Stock Exchange. The data taken for the study are reviewed in the next section. All data processing and computing can be divided into three stages. First, we filter data regularities from financial time series. Then, we calculate the degree of efficiency of the market using the Shannon entropy. Finally, we use the resulting time series to cluster stocks using Kullback-Leibler distance discussed in Section 2.4.

Dataset
We study the Moscow Stock Exchange. We consider close prices aggregated at oneminute time scale. In particular, we select only minutes of the main trading session from 10:00 to 18:40. The time interval covers ten years from 2012 to 2021. The time period is divided into monthly time intervals. We take 18 companies, 16 of them are from five sectors: oil industry, metallurgy, banks, telecommunications, and electricity. All stocks are listed in Table 1 (there are 2520 trading days. Assuming that there are 520 min in each trading day, there are 1310400 trading minutes in total. We use the Brownlees and Gallo's algorithm of an outlier detection [31]. See details in Appendix A.1). All data are provided by Finam Holdings (https://www.finam.ru/, accessed on 17 August 2022). For each company, we specify the ticker of stock, its sector, the size of data, and the amount of outliers removed. The size is given in the amount of minutes with trading activity.

Apparent Inefficiencies
To estimate a degree of market efficiency, we first should eliminate the known patterns of predictability, such as a daily seasonality. Financial agents operating in the market tend to trade less in the middle of a day. It is reflected in prices, but again, this pattern in trading volume should be filtered out to detect genuine patterns of inefficiency. Other known regularities include volatility clustering, price staleness, and microstructure noise. See Appendix A for a guide on filtering out apparent inefficiencies. The contribution of this article is that it devises a simple method for filtering volatility clustering and price staleness. One of the methods used to estimate volatility is the exponentially weighted moving average (EWMA). It is described in the next section.

EWMA
We define price returns as r t = ln P t P t−1 , where P t is the last price available at time t, and ln() is the natural logarithm. In order to estimate volatility σ n , we apply the exponentially weighted moving average [32] of values µ −1 This form of exponential moving average was used in [19]. Here, E[|r n |] = µ 1 σ n is used assuming that returns are normally distributed, r n ∼ N(0, σ n ). More weights are provided for the more recent data. An alternative formula based on expectation E[r 2 n ] = σ 2 n is described as follows.
A large value of return increases the value of volatility. The current value of volatility reflects all available values of returns and changes slowly if the value of α is small.
We follow the approach suggested by [33] (p. 97) to find optimal values of α in Equations (1) and (2). The value of α is selected so that it minimizes error Er σ (α) = ∑ i (σ 2 i − r 2 i ) 2 . In order to minimize Er σ (α) as a function of the only parameter 0 < α < 1, we apply Brent's algorithm [34] (the method is available in Python by using the function scipy.optimize.minimize_scalar. Alternatively, we could use the golden-section search [35] that requires the boundary of the search and the only parameter for the stopping criteria).
We modify the exponential moving average method in Section 2.2.3 so that it removes a bias due to the effect of price staleness discussed in the next section.

Estimation of Price Staleness
Let us define an efficient price, P e , as a continuous process following a Geometric Brownian Motion. P e t = P e 0 + t 0 σ s P e s dW s An observed price moves along a discrete grid. Possible price values are multiples of the tick size, d.
If the efficient price changes insignificantly, the return of the rounded price will be equal to 0. Analogically, if the return of rounded price is 0, the return of efficient price has a value close to 0. We use Equation (3) to estimate the probability that a return of rounded price has zero value: where and er f (x) are Gaussian error functions; d is a tick size (we estimate the tick size using a two-step procedure for each month. First, we find the amount of significant digits in price. Then, we determine the most frequent increment in ordered prices); ∆ is a time step (the time step between the end and start of the main trading session is set as 1 min. Moreover, we consider any time gap without trading more than 2 h as the closure of the market. We set the time step to be equal to 1 min for these gaps);P is a rounded price;σ is an estimation of volatility [36]. It is obtained by considering the probability that a price following a Geometric Brownian Motion moves less than one tick size, assuming that price increments are normally distributed.
There is another source for obtaining 0-returns, namely price staleness. Price staleness represents a regularity pattern of the dynamics; namely, the fundamental (efficient) price of an asset is not updated because of a number of reasons, such as no transactions because of high cost, which makes trading unprofitable for agents. See [20] for more details. This results in a persistence pattern of ("excess") 0-returns. Such a pattern, for example, tends to reduce any estimation of the volatility. Therefore, we need to filter out 0-returns due to price staleness while retaining 0-returns due to rounding for a genuine estimation of volatility.
We save 0-returns in the amount of the sum of past values of the probability in Equation (3) [36]. We set other 0-returns as missing values. We adopt this method to estimate the degree of price staleness together with volatility in the next section.

Modification of EWMA
In this Section, we present a modification of the EWMA that takes into consideration the effect of price staleness. Our modification of the EWMA is based on the suggestion for estimating volatility σ n asσ n−1 (i.e., by setting α = 0), if the value of r n−1 is missing because of price staleness. That is, there is no new information from returns to update the value of volatility.
Initially, the expected amount of 0-returns due to rounding is N save = 0. Thus, each appearance of 0-returns does not affect the value of volatility. A 0-return is defined as a value due to rounding and is saved in the sequence if the sum of all p i (Equation (3)) moves to a new integer value. Other details and the algorithm of volatility estimation can be found in Appendix B.
We update the estimation of volatility and price staleness minute-by-minute. This method has the clear advantage of making the online inference possible by processing data in real time.

The Shannon Entropy
A degree of randomness of price returns is assessed by Shannon entropy. The entropy of a source is an average measure of the randomness of its outputs [37]. Definition 1. Let X = {X 1 , X 2 , . . . . } be a stationary random process with a finite alphabet A and a measure µ. An n-th order entropy of X is with the convention 0 log 0 = 0. The process entropy (entropy rate) of X is

Discretization
The Shannon entropy is computed over a finite alphabet. To measure Shannon's entropy, we need to keep the length of blocks of symbols, k, sufficiently large. The predictable behavior of returns can be seen on blocks of greater length and may not be noticeable on blocks of smaller length. For this reason, we consider 3-symbol and 4-symbol discretizations using empirical quantiles: where θ 1 and θ 2 are tertiles and Q 1 , Q 2 , and Q 3 are quartiles. The tertiles divide data into three equal parts. The quartiles divide data into four equal parts. Q 2 is also the median of the empirical distribution of returns. For the later analysis, we will need a discretization describing the behavior of a pair of stocks: where r (1) t and r (2) t are two time series of price returns, and m 1 and m 2 are their medians.

The Estimation Of Entropy
Let x n 1 ∈ A n be the sequence of length n generated by an ergodic source µ from the finite alphabet A, where x i+k−1 i = x i . . . x i+k−1 . There are possible missing values in the sequence generated independently from x n 1 . We consider all blocks of length k that do not contain missing values. We take the following: where n b (k) is the number of blocks of length k. The restriction on a value of k allows having enough blocks to estimate probabilities appearing in k-th order entropy [38]. The base of the logarithm is the size of alphabet A (3 or 4). For each a k 1 ∈ A k , empirical frequencies are defined as follows.
Empirical frequencies are the actual amount of each block from A k in the data. By considering an empirical k-block distribution aŝ an empirical k-entropy is defined by the following.
The estimation of the process entropy is described as follows.
See [38] for the proof of the consistency of this estimator and [36] for the case of missing values. Since the sequence is finite, the estimation of entropy is underestimated. To remove this bias, we use the correction for the entropy estimation introduced in [39,40]: where the sequence G(i) is defined recursively as with the Euler's constant γ = 0.577215 . . . .

Detection of Inefficiency
We need to perform three steps to determine if the time interval is efficient or not. First, we filter out apparent inefficiencies (see Appendix A). Then, we estimate the entropy of the filtered return time series using Equation (7). Finally, we determine if the value of entropy is significantly lower relative to the case of perfect randomness. We detect inefficiency in the time interval using Monte Carlo simulations. We regard a Brownian motion as absolutely unpredictable. First, we define the length of sequences as l = n b (k) + k − 1. Then, we simulate 10 4 realizations of Brownian motions with Gaussian increments and the length l. For each realization, we calculate entropy using 3-and 4-symbol discretizations. Then, we find the first percentile of the obtained entropies for each discretization. These percentiles are the bounds of 99% of the Confidence Interval (CI) for testing market efficiency. Finally, we define an efficiency rate as the ratio of the entropy of the time interval and the bound of CI. If the efficiency rate is less than 1 for at least one type of discretization; we define the time interval as inefficient. We provide testing for inefficiency twice using different discretizations because the unique testing may not be robust. See an example in Appendix C.

Kullback-Leibler Distance
In addition to estimating the entropy of one time series, we can also consider the difference between two time series. Kullback-Leibler divergence [41] is used to measure similarity between two distributions for two discrete probability distributions P and Q.
We use p i and q i as empirical probabilities obtained in Equation (6). Since the Kullback-Leibler divergence is asymmetric, we consider the distance between two time series proposed in [42].
The greater the distance of D(P, Q), the more probability distributions P and Q differ.

Simulations
The aim of this section is to assess the accuracy of the estimation of volatility and the degree of price staleness. We will choose the method that produces the least amounts of error with respect to the estimation for further analysis on real data. We take the following model of an observed priceP t and t = 1 . . . 2N: where W 1 and W 2 are two independent Brownian motions with a length of 2N, N = 10 5 ; a price of P 0 = 100; and ν = 10 −4 . B = 1 stands for the case when price is not updated due to price staleness (see [20,43]). Prices are rounded to two digits; thus, the tick size is d = 0.01. We consider four choices for q t and σ t listed below.
For price staleness, we consider four cases: the absence of price staleness; two stochastic probabilities with different constant means; a periodic mean. For all four cases of volatility, the unconditional expected value of σ t is 5 × 10 −4 . The first choice of volatility is a constant. Then, we consider the ARCH model [44] with two lagged values, where 0.2 and 0.1 correspond to the first and the second lags, respectively. Volatility values directly depend only on the previous returns values. The dependency on the previous return should be reflected in the value of smoothing parameter. The third and fourth choices are GARCH(1,1) models [23], where the last parameter (0.85 or 0.8) stands for the coefficients for lagged variances. We consider two sets of parameters for a GARCH model, giving less persistence to the fourth model.
We divide the data into two equal parts with the size N. The first part is a training set for finding optimal values of α from Equations (1) and (2). The second part is a testing set for calculating errors represented in Tables 2 and 3. We compare two methods that use Sig 1 and Sig 2 for volatility estimation. For each method, we find the optimal value of α. In addition, we set a fixed value of alpha, α = 0.05, as a benchmark for the comparison. We also apply non-modified EMWA estimation from Section 2.2.1 with selected optimal value of α to show the contribution of 0-filtering to the accuracy of volatility estimation. We simulate 10 3 prices for each model. Table 2 represents a mean absolute percentage error (MAPE) that is 1 N ∑ i |σ i −σ i σ i | for six different approaches. These approaches differ in the choice of a function for volatility, the value of α, and the presence of missing values. Table 3 represents three values for each of the two methods using Sig 1 and Sig 2 for volatility estimation. The first value is the optimal value of α. The second is where N A is the amount of remaining non-missing returns, N round is the amount 0-returns that would appear due to rounding (before adding the effect of staleness in the simulated data), N A is the amount of non-missing returns, and N 0 is the amount of 0-returns. Er N represents the absolute error of the proportion of 0-returns that remain in the data and are defined as 0-returns due to rounding. The third value is the proportion of data set as missing values (that is, 1 − N A N ).  The first column indicated a model. Columns 2 and 3 represent results for two methods described in Section 2.2.3. Columns 4 and 5 are for the same methods but with the fixed value of α. Columns 6 and 7 shows the error of the standard EMWA approach with the optimal selected value of α. Values highlighted in bold are the smallest errors in each row. The 95% CI is presented below each averaged statistic. v 1 stands for using Sig 1 ; v 2 stands for using Sig 2 . Table 3. Results upon filtering out 0-returns. Values of α, errors of the number of 0-returns due to rounding, and fraction of data set as missing values. The first column indicated a model. 95% CI is presented below each averaged statistic. v 1 stands for using Sig 1 ; v 2 stands for using Sig 2 .
It can be seen from Table 2 that the method that more often produces the lowest value of MAPE is with fixed α = 0.05 and Sig 1 used for volatility estimation. Moreover, for almost all cases, 0-filtering makes the volatility estimate more accurate. The error of the amount of 0-returns due to rounding is smaller for the function Sig 1 than for the function Sig 2 for all 16 cases.
After the comparison of the two functions of volatility estimation, we decide to use Sig 1 , which uses absolute values of returns, in the next sections. For the rest of the paper, we fix the value of α as 0.05 for the simplicity of further analysis.

Moscow Stock Exchange
We calculate 18 · 120 = 2160 efficiency rates for each type of discretization, where 18 is the amount of stocks and 120 is the amount of months in 10 years. We define a degree of inefficiency as the fraction of 2160 months that are defined as inefficient according to Section 2.3.4. The degree of inefficiency for the chosen group of stocks traded at Moscow Exchange is 0.823. In our previous study, ref. [36] we found that the degree of inefficiency for the U.S. ETF market is about 0.11 for monthly time intervals and the 3-symbol discretization only. This difference in the degrees of inefficiency can be explained by the hypothesis that developed markets have a high level of efficiency. W. A. Risso reached this conclusion in the article [24]. The degree of inefficiency for each stock and discretization is presented in Table 4. We notice that 4-symbol discretizations contribute to a larger amount of inefficient months compared to the 3-symbol discretization. That is, the 4-symbol discretization appears to have a more predictable structure than 3-symbol discretizations.  There are two most notable deviations from one for MLTR stocks (Mechel, mining and metals company) and RSTI (Rosseti, power company). We investigate them in the next section. For the other 16 stocks, the minimum value of efficiency rate is attained for the AFLT stock, and it is equal to 0.933 (0.964) for three (four) symbols.

Analysis of MLTR and RSTI
We plot the values of efficiency rates for monthly intervals for the MLTR and RSTI stocks. See Figures 2 and 3 Table 5. Note that block 1111 for the 4-symbol discretization appears as the most frequent for 6 months out of 8 for MLTR. The block denotes a slight decrease in price for 4 min in a row. The meaning of the last two columns is discussed later.
For RSTI, there are two sharp decreases in 2014 and 2015. There are 11 months that have the lowest efficiency rates that are in common for both discretizations. These months are April-September of 2014 and June-October of 2015. Note that these inefficient months cluster together and are not distributed uniformly among the entire time period of 10 years. This is the signal of a market condition that affects the inefficiency of the stocks for more than one month. The first column represents months with the lowest efficiency rates. Columns 2 and 3 are the most frequent blocks in 3-and 4-symbol discretizations. Columns 4 and 5 include the probability of success when applying the simple trading strategy for filtered and original price returns.
We construct a simple trading strategy on discretized returns to test the predictability of future returns. We consider blocks of length 4 obtained by the 4-symbol discretization. For each month, we divide blocks into two halves. The discretization is made using only the first half of a month. We consider the sequences of the first three symbols of each block. If the empirical probability of obtaining 0 or 1 after the sequence of three symbols in the first half is greater than 0.5 , this sequence is from group D (decreasing). If the empirical probability of obtaining 2 or 3 after the sequence of three symbols is greater than 0.5, this sequence is from group I (increasing). Then, for the second half of the month, we determine a success if symbols 0 or 1 follow a sequence from group D or if symbols 2 or 3 follow a sequence from group I. Then, we calculate the fraction of successes. Thus, it is the probability of making a profit: sell after group D or buy after group I. In the case of market efficiency, this probability is equal to 0.5. For example, we expect that after 111, the next symbol would be 1 according to Table 5. That is, after this block, a trader can sell a stock. The fourth column of the Table 5 shows the results for a filtered return time series. The fifth column stands for the original return time series.
For all cases, the probability is greater than 0.5. Obviously, the probabilities for the original return time series are greater than those for the filtered return time series. The reason is that predictability for the original return time series follows from the sources of apparent inefficiencies.
The same analysis is performed for the RSTI stock. Eleven months with the lowest efficiency rates are presented in Table 6. For the RSTI stock, the simple trading strategy provides the fraction of successes (of predicting increases and decreases in price) greater than 0.5 for all 11 months. The frequent behavior of the price of RSTI during the chosen months is a slight increase in price for several minutes in a row denoted by symbol 2. Table 6. The most frequent blocks appearing for the RSTI stock and probabilities of success. The simple trading strategy is an illustrative example of market inefficiency. In fact, such a strategy could result in no profit when used in practice because it does not take into account the costs of transaction and other trading frictions. Moreover, the filtering of daily seasonality pattern is made by using the entire period of analysis. That is, this method cannot be applied in real time. Finally, we consider blocks containing only observed returns by neglecting the missing values from the analysis. Thus, the application of such a strategy in practice should be integrated with the case when a missing value follows a sequence of three symbols.

Stock Market Clustering
Most of the month-long time intervals are identified as inefficient. However, is there some dependence between two stocks that are inefficient at the same time?

Kullback-Leibler Distance
We measure the similarity of discretized filtered returns by using the Kullback-Leibler (KL) distance (Equation (8)). We use k, the length of blocks, as the maximum value suitable for both sequences according to Equation (5). The 4-symbol discretization is used. The Kullback-Leibler divergence DL(P|Q) is calculated using empirical frequencies.
The entropy rates are calculated using Equation (7). Using the Kullback-Leibler distance for all pairs of stocks, we cluster them in three groups using hierarchical clustering with the UPGMA algorithm [45]. This algorithm is implemented by using the Python function cluster.hierarchy.dendrogram with the argument distance=average. The result is in Figure 4. Combining companies into one cluster means that their stocks have a common behavior that is not related to the value of volatility, the degree of price staleness, and the structure of microstructure noise.  It can be seen that banks and oil companies are clustered together (right). There is a group of four stocks (RTKM, HYDR, AFLT, and MGNT) that have nothing in common at first glance. The remaining group (left) mainly consists of metallurgy companies. However, there is no visible distinction between the stocks of banks and oil companies. According to the clustering tree, two telecommunications companies differ significantly, as well as electricity companies.
Finally, two stocks with the lowest efficiency rates, RSTI and MLTR, are the furthest (in the sense of KL distance) from any other stock. That is, there are no stocks that behave similarly to these two stocks.

Entropy of Co-Movement
Now, we consider another measure of difference between two stocks: the entropy of co-movement. We calculate the Shannon entropy of the discretization describing the movement of a pair of prices presented in Equation (4). We consider only minutes that are in common for both stocks. For these minutes, we consider values of residuals obtained after ARMA fitting. The result is in Figure 5. Two companies related to telecommunications are a separate cluster. Three metallurgy companies (MAGN, CHMF, and NLMK) also cluster together. Stocks relating to oil and bank companies form the other cluster. The same cluster, with the exception of the TATN (oil industry), was also formed in the previous section. The "closeness" of stocks GAZP and SBER is detected either in this and in the previous section. The three stocks on the left that join other stock clusters last are the stocks with the lowest efficiency rates.
Some clusters may form on the basis that companies belong to the same industry. The division of companies into industries is noticeable from the dendrogram in Figure 5. However, this criterion does not explain all clusters. For instance, GMKN from metallurgy is in the cluster of oil companies and banks.

Discussion and Conclusions
We have investigated the predictability of the Moscow Stock Exchange. We are interested in a measure of market inefficiency that is not related to known sources of regularity in financial time series. Usually, these sources are not filtered out, and accordingly, their impact is taken into account in the degree of price predictability (see, e.g., [16][17][18]).
We have focused on two sources of regularity, namely volatility clustering and price staleness [20]. The process of filtering volatility clustering was performed in [19] by estimating volatility using the exponentially weighted moving average. We have developed a modification of the volatility estimation by taking into consideration the effect of price staleness. Price staleness produces excess 0-returns that affect the estimation of volatility. Another approach of estimating volatility in the case of presence 0-returns was proposed in [21] where all 0-returns are reevaluated during an expectation-maximization algorithm. In our approach, we separate 0-returns that may have resulted from rounding and from price staleness. Thus, we also filter out apparent inefficiency due to price staleness. Our approach combining the estimates of volatility and the degree of staleness can be used for a real-time causal analysis, since only past observations are used.
One of the clear advantage of the proposed approach relies in its simplicity: There is only one smoothing parameter in the method that can be optimized using historical data. We fix the value of smoothing parameter equaled 0.05. In the literature, the smoothing parameter α is usually taken close to 0. Using the principle of the best one-step forecasting, the smoothing parameter is set to 0.06 for the daily data and to 0.03 for the monthly data [33]. The value of the parameter α is set to be equal 0.12 for in-sample testing and 0.22 for out-of-sample testing in [46]. Hunter [32] suggests using α = 0.2 ± 0.1.
We used the Shannon entropy as a measure of randomness to infer the degree of (in)efficiency of the Moscow Stock Exchange. We used two types of the discretization of return time series to test efficiency more reliably for each month. The 4-symbol discretization helps find more price movements that lead to market inefficiency than compared to the 3-symbol discretization. Eighty percent of months over the period from 2012 to 2021 are defined as inefficient. According to Risso [24], a higher level of efficiency corresponds to more developed markets. Deviation from efficiency is a frequent phenomenon in various markets. For example, the authors of work [14] conclude that the Colombo Stock Exchange is only 10.5% efficient while the Pakistan Stock Exchange is 23.7% efficient. Cajueiro and Tabak [10] have shown that Asian markets are less efficient than Latin American markets. The authors of [28] estimates the efficiency of the Tunisian stock market as 97%. There are periods of inefficiency for some stocks traded at the Tel-Aviv stock exchange as stated in [15]. Short periods of inefficiency were also detected for US stock markets in [25].
By investigating the discretized values of filtered price returns, we came to the following conclusions: • Even after filtering out all known sources of regularity, most months contain signals of market inefficiency. • The most inefficient months are grouped together for two stocks exhibiting the lowest efficiency rates. • For such months, discretized price returns before and after filtering out apparent inefficiencies are predictable. • We introduced the entropy of co-movement. Stock prices display common patterns that have an interpretation in terms of the sector that the stock belong to. • The stocks of banks and oil companies cluster together in terms of co-inefficiency for the case of the Moscow stock exchange.
One possible improvement to stock clustering is to modify the entropy of co-movement such that it is possible to define a proper distance function. This is left for future research. The proposed method for measuring market efficiency using the Shannon entropy can be applied in other markets of different countries. In this study, we used monthly time intervals for entropy calculation. Our future work will be related to the optimization of the length of return time series. One problem is to find a significant decrease in entropy without using Monte Carlo simulations. We also plan to switch to a higher frequency (less than one minute) to analyze the predictability of financial time series. Funding: This research was supported by the research project "Dynamics and Information Research Institute-Quantum Information, Quantum Technologies" within the agreement between UniCredit Bank and Scuola Normale Superiore. We are grateful to UniCredit Bank R&D group for financial support through the "Dynamics and Information Theory Research Institute" at the Scuola Normale Superiore.
Institutional Review Board Statement: Not applicable.

Informed Consent Statement: Not applicable.
Data Availability Statement: The Python codes (v. 3.9.5) used in this study are available in Supplementary materials. The dataset analyzed in this study can be found here: https://www.finam.ru/ profile/moex-akcii/gazprom/export/ (accessed on 17 August 2022).

Conflicts of Interest:
The authors declare no conflict of interest.

Appendix B. Algorithm
The aim of the algorithm is to estimate volatility and filter out excess 0-returns due to price staleness. Some 0-returns appear due to price rounding. These 0-returns will be saved in the data. First, we set the number of 0-returns "to save" N save = 0 and the first value of a cumulative function Z 1 = 0. The cumulative function is updated Z t = Z t−1 + p t , if r t−1 is not defined as missing due to staleness. Each time when Z(t) − Z(t − 1) = 1, N save is increased by 1.
We notice that the first non-zero return after a row of 0-returns due to staleness is the sum of all missing returns generated by a hidden efficient price. This return is also set as missing. However, the value of return used for estimating volatility is calculated as its expected value:r n−1 = r n−1 √ N 0 +1 , where N 0 is the amount of missing values strictly before the non-zero return r n−1 . The same is also referred to initially missing values, e.g., due to no-trading or errors in collecting the data.
Another assumption is that a 0-return appears due to staleness if the previous return had the 0-value and was defined to appear due to staleness. We include this rule, since we assume that it is more likely that two consecutive 0-returns appear due to high transaction costs than due to rounding (that is, simply speaking, two outcomes of generating Gaussian random variables are less than a tick size).
Generally, for the estimation of volatility at time t we should consider three cases: P t−1 was missing (or minute t − 1 is non-trading), r t−1 = 0, r t−1 = 0. Thus, the algorithm is the following. We provide the algorithm for the case of Sig 1 , which is used in the application for real data. We remove all 0-returns that start the sequence.
If N real ≤ ∑ i p i + 1.96 √ Var, we leave the time series without placing any missing values, where N real is the initial amount of 0-returns. The value of α can be selected using a training set. The optimal value of α minimizes the mean of (σ 2 t − r 2 t ) 2 .

Appendix C. A Predictable Time Series with Entropy at Maximum
The goal of this section is to construct a price model where entropy is high because of discretization. This model shows that a high entropy value may be caused by discretization, but not because of the randomness of a return time series.
There are equal probabilities of having symbols 0, 1, and 2. Symbol 1 corresponds to log-returns, r, equal to −0.4, and 2 corresponds to log-returns equal to 0.4. The structure of symbol 0 is more complicated. It covers three other symbols: 3, 4, and 5. They correspond to log-returns −0.3, 0.1, and 0.2, respectively. One of the symbols 3, 4, or 5 appears with probabilities depending on the previous value of these symbols. The probabilities are presented in the Table A1. Having a symbol presented in a column, there are probabilities of obtaining a symbol presented in a row. Table A1. Transition probabilities.