Generating Realistic Stock Market Order Streams

We propose an approach to generate realistic and high-fidelity stock market data based on generative adversarial networks . We model the order stream as a stochastic process with finite history dependence , and employ a conditional Wasserstein GAN to capture history dependence of orders in a stock market . We test our approach with actual market and synthetic data on a number of different statistics , and find the generated data to be close to real data . 1 INTRODUCTION . Financial markets are among the most well-studied and closely watched complex multiagent systems in existence . Well-functioning financial markets are critical to the operation of a complex global economy , and small changes in the efficiency or stability of such markets can have enormous ramifications . Accurate modeling of financial markets can support improved design and regulation of these critical institutions . There is a vast literature on financial market modeling , though still a large gap between the state-of-art and the ideal . Analytic approaches provide insight through highly stylized model forms . Agent-based models accommodate greater dynamic complexity , and are often able to reproduce “ stylized facts ” of real-world markets ( LeBaron , 2006 ) . Currently lacking , however , is a simulation capable of producing market data at high fidelity and high realism . Our aim is to develop such a model , to support a range of market design and analysis problems . This work provides a first step , learning a high-fidelity generator from real stock market data streams . Our main contribution is an approach to produce stock market data that is close to real market data , using a Wasserstein generative adversarial network ( WGAN ) ( Arjovsky et al. , 2017 ) . There are many challenges that we overcome as part of this contribution . The first is how to represent a stream of stock market orders as data that can be used in a WGAN . Towards this end , we assume the stock market data stream to arise from a stochastic process with finite ( but long ) memory dependence . The stochastic process view also makes precise the conditional distribution that the generator is learning as well the joint distribution that the critic of the WGAN distinguishes by estimating the earth-mover distance . The second main challenge is the design of the network architecture . We choose a conditional WGAN to capture the history dependence of the stochastic process , with both the generator and critic conditional on history of orders and the time of day . A single LSTM layer is used to summarize the history succinctly . The internal architecture of both the generator and critic uses a standard convolutional structure . The generator outputs the next stock market order as well as how this order changes the active orders in the market . Part of the generator output , which updates the active market orders , is produced using a pre-trained network to approximate the deterministic buy and sell order matching in the stock market . Finally , we experiment with synthetic and real market data . The synthetic data is produced using a stock market simulator that has been used in several agent-based financial studies . The real data was obtained from OneMarketData , a financial data provider and publisher of the OneTick database product . We evaluate the generated data using various statistics such as the distribution of price and quantity of orders , inter-arrival times of orders , and the best bid and best ask evolution over time . We find the generated data matches the corresponding statistics in real data ( simulated or actual stock market ) closely . 2 RELATED WORK AND BACKGROUND . WGAN is a popular and well-known variant of GANs ( Goodfellow et al. , 2014 ) . Most prior work on generation of sequences using GANs has been in the domain of text generation ( Press et al. , 2017 ; Zhang et al. , 2017 ) . However , since the space of word representations is not continuous , the semantics change with nearby word representation , and given a lack of agreement on the metrics for measuring goodness of sentences , producing good quality text using GANs is still an active area of research . Stock market data does not suffer from this representation problem but the history dependence for stock markets can be much longer than for text generation . In a sequence of recent papers , Xiao et al . ( 2017 ; 2018 ) have introduced GAN-based methods for generating point processes . The proposed methods generate the time for when the next event will occur . The authors have also explored the use of these techniques to generate the time for transaction events in stock markets . Our problem is richer as we aim to generate the actual limit orders including time , order type , price , and quantity information . Deep neural networks and machine learning techniques have been used on financial data mostly for prediction of transaction price ( Hiransha et al. , 2018 ; Bao et al. , 2017 ; Qian , 2017 ) and for prediction of actual returns ( Abe & Nakayama , 2018 ) . As stated , our goal is not market prediction per se , but rather market modeling . Whereas the problems of learning to predict and generate may overlap ( e.g. , both aim to capture regularity in the domain ) , the evaluation criteria and end product are quite distinct . The stock market is a venue where equities or stocks of publicly held companies are traded . Nearly all stock markets follow the continuous double auction ( CDA ) mechanism ( Friedman , 1993 ) . Traders submit bids , or limit orders , specifying the maximum price at which they would be willing to buy a specified quantity of a security , or the minimum price at which they would be willing to sell a quantity.1 The order book is a store that maintains the set of active orders : those submitted but not yet transacted or canceled . CDAs are continuous in the sense that when a new order matches an existing ( incumbent ) order in the order book , the market clears immediately and the trade is executed at the price of the incumbent order—which is then removed from the order book . Orders may be submitted at any time , and a buy order matches and transacts with a sell order when the limits of both parties can be mutually satisfied . For example , as shown in Figure 1 if a limit buy order with price $ 10.01 and quantity 100 arrives and the order book has the best offered sell price at $ 10.01 with quantity 100 then the arriving order matches an incumbent exactly . However , the next buy order does not match any sell , and the following sell order partially matches what is then the best buy in the order book . The limit order book maintains the current active orders in the market ( or the state of the market ) , which can be described in terms of the quantity offered to buy or sell across the range of price levels . Each order arrival changes the market state , recorded as an update to the order book . After processing any arrived order every buy price level is higher than all sell price levels , and the best bid 1Hence , the CDA is often referred to as a limit-order market in the finance literature ( Abergel et al. , 2016 ) . refers to the lowest buy price level and the best ask refers to the highest sell price level . See Figure 1 for an illustration . The order book is often approximated by few ( e.g. , ten ) price levels above the best bid and ten price levels below the best ask ; as these prices are typically the ones that dictate the transactions in the market . There are various kinds of traders in a stock market , ranging from individual investors to large investing firms . Thus , there is a wide variation in the nature of orders submitted for a security . We aim to generate orders for a security in aggregate ( not per agent ) that is close to the aggregate orders generated in a real market . We focus on generating orders and do not attempt to generate transactions in the stock market . This is justified as the CDA mechanism is deterministic and transactions can be determined exactly given a stream of orders . 3 STOCK-GAN . 3.1 STOCK MARKET ORDERS AS A STOCHASTIC PROCESS . We model stock market orders as a stochastic process . Recall that a stochastic process is a collection of random variables indexed by a set of numbers . We view the stock market orders for a given chunk of time of day ∆t as a collection of vector valued random variable { xi } i∈N indexed by the limit order sequence number in N = { 1 , . . . , n } . The components of the random vector xi include the time interval di , type of order ti , limit order price pi , limit order quantity qi , and the best bid ai and best ask bi . The time interval di specifies the difference in time between the current order i and previous order i− 1 ( in precision of milliseconds ) ; the range of di is finite . The type of order can be buy , sell , cancel buy , or cancel sell ( represented in two bits ) . The price and quantity are restricted to lie within finite bounds . The price range is discretized in units of US cents and the quantity range is discretized in units of the equity ( non-negative integers ) . The best bid and best ask are limit orders themselves and are specified by price and quantity . Observe that we assume the stochastic process depends on the discrete time of day ∆t , which we will make explicit in the next paragraph . We divide the time in a day into 25 equal intervals and ∆t refers to the index of the interval . A visual representation of xi is shown in Figure 2 ( a ) . Following the terminology prevalent for stochastic processes , the above process is discrete time and discrete space ( note that discrete time in this terminology here refers to the discreteness of the index set N ) . We assume a finite history dependence of the current output xi , that is , P ( xi | xi−1 , . . . , ∆t ) = P ( xi | xi−1 , . . . , xi−m , ∆t ) . Such dependence is justified by the observation that recent orders mostly determine the transactions and transaction price in the market as orders that have been in the market for long either get transacted or canceled . Further , the best bid and best ask serves as an ( approximate ) sufficient statistic for events beyond the history length m. While this process is not a Markov chain , it forms what is known as a higher order Markov chain , which implies that the process given by yi = ( xi , . . . , xi−m+1 ) is a Markov chain for any given time interval ∆t . We assume that this chain formed by yi has a stationary distribution ( i.e. , it is irreducible and positive recurrent ) . A Markov chain is a stationary stochastic process if it starts with its stationary distribution . After some initial mixing time , the Markov chain does reach its stationary distribution , thus , we assume that the process is stationary by throwing away some initial data for the day . Also , for the jumps across two time intervals ∆t , we assume the change in stationary distribution is small and hence the mixing happens very quickly . A stationary process means that P ( xi , . . . , xi−m+1 | ∆t ) has the same distribution for any i . In practice we do not know m. However , we can assume a larger history length k + 1 > m , and then it is straightforward to check that yt = ( xi , . . . , xi−k ) is a Markov chain and the claims above hold with m− 1 replaced by k. We choose k = 20 .

Summary: This paper proposes a Generative Adversarial Network (GAN) methodology to learn the distribution of limit orders that arrive on an equity market. The proposed approach captures the (mostly discrete) structure in the generated orders; modeling is carried out with a conditional Wasserstein-GAN with a recurrent neural networks in both the generator and critic used to capture the time dependency, and convolutional layers to capture other conditioning information. Experiments are provided on both synthetic and real data.