Conditional Generators for Limit Order Book Environments: Explainability, Challenges, and Robustness

Limit order books are a fundamental and widespread market mechanism. This paper investigates the use of conditional generative models for order book simulation. For developing a trading agent, this approach has drawn recent attention as an alternative to traditional backtesting due to its ability to react to the presence of the trading agent. Using a state-of-the-art CGAN (from Coletta et al. (2022)), we explore its dependence upon input features, which highlights both strengths and weaknesses. To do this, we use"adversarial attacks"on the model's features and its mechanism. We then show how these insights can be used to improve the CGAN, both in terms of its realism and robustness. We finish by laying out a roadmap for future work.


Introduction
This paper deals with the construction of robust and realistic limit order book (LOB) environments for the training and evaluation of trading strategies.LOBs [22] are a fundamental market mechanism, which are used across a significant proportion of financial markets, including all major stock and derivatives exchanges.The benefits of having robust and realistic simulators for these markets are numerous.For example, they would allow the study of markets under different assumptions, and the investigation of AI techniques for training trading strategies.In a LOB market, matched orders result in trades and unmatched orders are stored in the two parts of the LOB, a collection of buy orders called bids (the bid book), and a collection of sell orders called asks (the ask book).Typically, each side of the LOB will contains hundreds of individual orders, and a real market would be updated at micro-second time resolution, driven by a wide range of market participants and facilitated by "high-frequency" market makers [45].
The development of AI-based automated trading strategies for LOB markets has been a growth area in recent years, both within academia and industry, spurred on in part by developments in deep learning and reinforcement learning.Two typical LOB trading problems that have been investigated are market making, where the goal is to provide liquidity to the market by being continually willing to buy and sell an asset (see, e.g., Spooner et al. [50], Jerome et al. [28], Gasperov and Kostanjcar [19]), and optimal execution where the goal is to execute a pre-determined amount in the most cost efficient manner possible (see, e.g.Nevmyvaka et al. [34], Ning et al. [36]).
The ultimate test of the efficacy of a trading strategy -be it a hand-crafted one or one developed using AI -is to trade it live in a real market [38].However, this testing approach is rarely feasible for academic researchers, and even for industry practitioners it is potentially very costly to evaluate strategies this way.Thus effective simulation-based evaluation frameworks are highly desirable both to drive academic and commercial research.In Section 3.2, we discuss in detail desiderata that a simulation-based strategy evaluation framework should have.
By far the most prevalent choice is market replay, but simulators based on this approach have no reactivity [7].Thus, one implicitly makes the assumption that the financial market does not react to the presence of the trading agent which is being tested.Needless to say, this is an unrealistic assumption.Conditional generative models provide a solution to the issue of reactivity, and for this reason -and others that we discuss in Section 3 -they have recently attracted a lot of attention in the AI community (see, e.g., Li et al. [31], Kuo et al. [29], Coletta et al. [14,15], Shi and Cartlidge [46]).With a deep conditional generative model, a deep neural network is used to generate the next state of the world, conditioned upon the current state of the world.The two most popular such models are Conditional Generative Adversarial Networks (CGANs) [33] and Conditional Variational Autoencoders (CVAEs) [48].All of the main experiments in this paper use a specific class of CGANs introduced in the paper by Coletta et al. [2022].We refer to this CGAN as LOBGAN.
Training of the LOBGAN model works as follows.The generator neural network takes as its conditioning input a set of features that describe both the recent state of the order book and recent trade action, as well as -as in a non-conditional GAN -a random noise vector to add variability.It then outputs a vector that represents the predicted next order to arrive in the book.Then a discriminator neural network takes the synthetic order vector as well as the true order vector (from the historical training data) and aims to distinguish (conditional upon the input to the generator) which is real.For more details on training conditional GANs see, e.g., Goodfellow et al. [20], Mirza and Osindero [33], Gulrajani et al. [23].

Our contributions
In this paper, we motivate and study the problem of developing realistic and robust conditional generative models for simulating LOBs.Throughout the paper we use LOBGAN along with high-fidelity historical order data from LOBSTER [27].While our exploration uses this specific model family, our novel contributions to the methodology of evaluating and interpreting generative order flow models applies more generally.We next summarise our contributions: • We go beyond prior work in demonstrating the benefits of LOBGAN by doing a price impact analysis for market and limit orders separately.This approach newly reveals a strength, and separately a weakness of LOBGAN.
• We provide a new technique for analysing the conditioning of generative LOB models.This technique helps both with explainability and the design of better models.
• We develop and test trading strategies to study and stress the robustness of LOBGAN.These adversarial strategies include both hand-crafted and reinforcement-learning-based strategies.
• Using our insights, we develop new LOBGAN models, which we demonstrate are better in terms of both realism and robustness.
• We provide recommendations for how to use LOBGAN (or similar conditional generative models) in practice.
• We provide a detailed roadmap for future work.
Remark: our adversarial attacks are not "market manipulation".Our goal in this paper is to understand and develop the methodology for designing realistic and robust conditional generators.As such, we design adversarial attacks to exploit and show weaknesses of such models by manipulating the features and mechanism of the models.The term "market manipulation" has a specific meaning and refers to behaviour such as spoofing and quote stuffing, whereby orders are placed, with no intention of them being executed, and with the goal of deceiving and manipulating other market participants.Such market manipulation is typically illegal and markets are carefully monitored for these types of behaviours by exchanges.In the interests of clarity, none of the strategies we present in this paper would be considered as market manipulation, but we rather focus on adversarial attacks on the deep neural network model [53,8,35].Furthermore, whenever we place orders as part of an adversarial attack, there is always a reasonable chance that order will be executed.And, we never cancel an order purely to avoid that order being executed, but instead because that order is in some sense "stale".

Outline of the paper
In Section 2, we provide a discussion of key concepts needed in this paper.We start by explaining how a LOB market works; we then discuss how to measure the realism of a simulator of such a market, where we stress a distinction between two types of realism: realism in isolation and interactive realism; then we discuss a particular type of interactive realism namely the price impact of orders.
In Section 3, we demonstrate the benefit of using a generative CGAN-based order flow model as an alternative to market replay (which is also known as "backtesting").A key benefit of generative models is that they can react to incoming order flow, and therefore generate realistic price impact.In the literature, the price impact of market orders has been heavily studied; the price impact of limit orders has been studied much less so.In this section we further analyse the price impact of LOBGAN, separately for market orders and limit orders.While we find that LOBGAN can generate realistic price impact paths, we also find that the paths show a greater impact of limit orders over market orders, which is unexpected, and was not studied in the earlier papers on LOBGAN.We investigate the possible reasons in the paper.
In Section 4, we review realism metrics for trajectories generated sequentially by CGAN-based order flow models.These metrics have been the primary way that models have been selected and evaluated to date, where a human in the loop chooses among a set of candidate CGAN models one that does well across a range of these realism metrics [15,31]).
In Section 5, we introduce a new analysis technique for CGAN-based order flow models that explores the dependence of the model's output dynamics in terms of the individual input features that are used for conditioning.This technique both helps to explain the causal mechanisms in the model, and improves the robustness of model selection by identifying redundant features that can be removed, which reduces overfitting and further improves explainability.
The realism metrics in Section 4 focus on realism in isolation, whereas Section 3 provides a very simple example of interactive realism (which is similar in spirit to previous work [15,46]).In Section 6, we explore interactive realism in depth -for the first time.We analyse LOBGAN's outputs when it interacts with a range of trading agents.Some of these agents emulate standard market participants such as market makers, where an example of unrealistic behaviour of the CGAN that we discover is a market maker can make consistently large profits, albeit with an extremely unsophisticated strategy.A second type of trading agent that we introduce explicitly tests how exploitable the causal mechanisms of the model are by placing orders to "exploit" features for the purpose of making unrealistic profits.This is problematic because if one were to use AI methods such as reinforcement learning for developing trading strategies, such approaches would likely try and exploit the features of the model to make profits, whilst being potentially unprofitable in real markets.
In Section 7, we develop a variety of solutions to the "vulnerabilities" of the original LOBGAN model that we identify.This leads to new variants of LOBGAN that are better both in terms of their realism and robustness.In Section 7.3 we provide recommendations for how best to use LOBGAN or similar models in practice, based on the insights from this paper.
In Section 8, we provide an extensive discussion of related work.In Section 9, we finish with a discussion of future work and next steps in this promising research direction, where many challenges remain in relation to the CGAN design and model selection, We lay out a programme for future research, including, for example, a proposed generative model training loop that incorporates the use of trading strategies to ensure that the CGAN is not unrealistically exploitable.

Generative Adversarial Networks (GANs)
In recent years, Generative Adversarial Networks (GANs) have been successfully applied to a wide range of applications, ranging from images to time-series data.GANs generate samples with high quality and diversity by implicitly learning to generate data without the need for an explicit density function [20].
In particular, GANs employ two neural networks and an adversarial training procedure: a generator G and a discriminator D are trained simultaneously to play the following min-max game: Given a vector z from a prior distribution p z (i.e., typically a multi-dimensional Gaussian distribution), the generator network G(z) creates a new realistic sample x that the discriminator examines to estimate whether x is real (i.e., x belongs to the ground truth training set) or fake (i.e., x has been generated by G).Both networks aim at maximizing their own utility function.As the training advances, the discriminator network D learns to reject unrealistic synthetic samples generated by G, while the generator G learns to generate more realistic data to fool the discriminator.Finally, in deployment, the generator G is used to generate new (hopefully realistic) data samples.
Conditional Generative Adversarial Networks (CGANs) Conditional GANs [33] condition the generative process by using some extra information, which is captured in a feature vector y.This extra information can represent, for example, the class of the images to generate [23], or the market state to generate appropriate orders [15].
CGANs feed both the generator and discriminator networks with this extra information y, resulting into the following game: LOBGAN uses a particular CGAN architecture namely a Wasserstein CGAN, combined with a gradient penalty [23].The Wasserstein (also called Earth-Mover's) distance has been found to to improve the stability of the CGAN training process (compared to the Jensen-Shannon divergence, which was used in the original GAN), as it is continuous everywhere, and differentiable almost everywhere, under the assumption that the discriminator lies within the space of 1-Lipschitz functions.The Lipschitz constraint is enforced on the discriminator via the gradient penalty, which penalises the norm of the gradient with respect to its input.Importantly, Wasserstein CGANs have demonstrated strong results in modelling discrete data [23], which is the form of the order flow features like order type, volume, and depth that are used by conditional models for limit order books including LOBGAN.
For the Wasserstein CGAN with a gradient penalty the min-max game is defined as follows: In the leftmost subfigure, we see the bid limit orders in blue and ask limit order in red.The best bid (ask) price is $98 ($100).At a given price level, orders of different market participants are delimited by vertical lines, with orders nearer the front of the queue for that price level being nearer the bottom.In the middle subfigure a buy market order with volume 40 has arrived.It totally takes out the old best ask and a further volume of 20 from the next best ask (price $101).After this execution the spread has widened from $2 (i.e., 100-98) to $3 (i.e., 101-98). max where, for LOBGAN, the weight λ for the gradient penalty is set to 10 as in [23].
LOBGAN's generator synthesises subsequent order flow according the recent state of the market, i.e., the features used for conditioning summarise the current market state and recent market action.The features used by LOBGAN for conditioning are explained in detail in Section 5.1.

An illustrative example of limit order book dynamics
The example given in Figure 1 illustrates both the execution mechanism of a limit order book and highlights the lack of reactivity in market replay that we demonstrate further in Section 2.4 below.The left-hand panel of the figure shows a collection of unmatched bid and ask limit orders -forming the order book, with the bid book (at lower price levels) on the left, and the ask book (at higher price levels) on the right.In the middle panel, a buy market order1 arrives and is executed against the ask limit orders.It does so according to price-time priority -first matching against the lowest price and then matching orders at the best price according to time priority (i.e., transacting first against limit orders that arrived earlier).The right-hand panel shows the state of the order book after the execution of this market order; the spread has widened and the mid-price has gone up.
In a real market, the key question would be what happens next?For a market replay environment, the answer is simply whatever happened in the historical data.This is entirely the correct answer when simply replaying historical order data, but ultimately the purpose of a backtest is to evaluate an exogenously defined trading agent (or perhaps to explicitly train a learning agent).Making an assumption that a trading agent can place orders without affecting subsequent order flow is unrealistic: The historical orders that are placed after the "external" order of the trading agent, are being added to an order book that does not look like the order book in which they were placed historically; if the external order had actually been placed historically then the market would have been made aware of the presence of the exogenous agent and its orders and would have reacted accordingly.In particular, the traders responsible for subsequent historical order flow may have no longer chosen to place the same orders that were historically observed.Furthermore, the more that an external agent interacts with the order book, the more the observed order book differs from the historical order book and the more unrealistic the assumptions underlying market replay are.
On the other hand, in a CGAN-based environment, subsequent order flow depends on the current state of the world, so that when an exogenous agent interacts with the book and changes it, the CGAN generates orders that are realistic conditioned on the updated order book as well as any trades that ocurred.This reactivity is a primary advantage of a CGAN-based approach, but it is not the only one.In Section 3 we discuss some of the many other benefits.

Realism in isolation and interactive realism
The example and discussion in Section 2.2 explain how reactivity in response to incoming orders is a strength of the CGAN approach.However, so far evaluation of CGAN models has focused primarily on the realism of the CGAN outputs when the only inputs come from model itself.In this paper, we extend the focus to include realism of outputs when at least one additional trading agent is also in the system.It is thus useful to introduce terminology to distinguish between these two types of realism: Realism in isolation.This type of realism is where no agents are added to the simulation, and the desideratum is that the simulation outputs should look realistic in terms of their statistical properties.This is discussed in detail for limit order books in Vyetrenko et al. [54].In this case of realism in isolation, market replay will -by definition -look completely realistic.This type of realism has been the primary driver of model selection and evaluation for existing CGAN LOB models such as LOBGAN [15] and Stock-GAN [31].
Interactive realism (i.e., realistic reactivity).In addition to realism in isolation, we would like a simulator to also react realistically when an external agent places orders.Again, we would like that the outputs of the model should look realistic given the behaviour of the interacting trading agent(s).By definition, market replay cannot do this.However, a CGAN model can, by conditioning on recent market action, which includes the actions of external agents.

Price Impact
In financial markets, price impact is the effect that an agent has on the midprice due to its trading activity.In particular buy (sell) orders tend to push the price of the asset up (down).There is debate as to whether market impact comes from trades revealing private information about the fundamental value of the asset or whether it emerges naturally from the limit order book mechanism, but there is agreement that it is a fundamental aspect of markets to consider when placing large orders [10,Chapter 11.1].Therefore, a realistic simulator has to show price impact phenomena to properly capture market response to an experimental strategy.
When one only has historical market data one is limited in the type of analysis of price impact that one can carry out.In particular, one is not able to do the type of "A/B" testing that one can do when one has a simulator, as we do.In this case, with a simulator, one can study the market's price evolution in two situations that only differ according to whether a certain set of orders was placed or not.Later in the paper, we do this for the CGAN models that we explore, and compare the results with earlier findings from the literature.
In more detail, to consider price impact we define the (reaction) impact path [10, (11.1),(12.2)]as the average price dislocation between the beginning and the end of a metaorder execution (a collection of smaller orders in one direction): In particular, we measure the price difference between a simulation with and without the metaorder in our simulated environments, and then we compare the resulting impact paths against the form of these paths that have been found in the empirical literature on price impact (Figure 4).As mentioned above, we note that this approach cannot be implemented in market replay or in a real financial system as the two situations (i.e., the metaorder arriving or not) are mutually exclusive.We distinguish between three types of price impact: temporary, permanent, and transient [1,26,11].We define temporary price impact as the impact occurred during the execution of the metaorderand we further define the peak price impact to be the impact when the whole order has been executed.After the metaorder has been executed we have: the transient price impact which is the component of the metaorder's price impact that decays to zero; and the permanent price impact that persists in the market, formally defined as lim l→∞ I react.
t+l (exec t | F t ).

Benefits of LOBGAN over backtesting
Simulated environments are increasingly used by academic researchers, trading firms, and investment banks to evaluate and train trading strategies and study market response to order placement.In this section, we discuss the benefits of conditional generators over traditional market replay simulators.

Price impact of LOBGAN
Going beyond what one typically finds in the literature, we investigate the price impact of market and limit orders on LOBGAN separately.This allows us to better evaluate and understand LOBGAN.

Impact path of market orders
We first evaluate the LOBGAN and market-replay environments by considering a Time-Weighted Average Price (TWAP) agent that uses market orders.TWAP is a widespread benchmark execution strategy which splits a larger order into small parts equally over time (in this case, over a period of 5 minutes).Figure 2 shows the average impact path when the TWAP agent is included in the simulation environment.It may seem counterintuitive that a market-replay environment exhibits price impact at allsince the subsequent order flow does not react to the orders of the the TWAP agent.Nonetheless, under market replay the limit order book mechanism will lead to changes in the midprice for sufficiently large incoming market orders: when an arbitrarily large buy market order comes in, this order could take out a large number of ask price levels and create an arbitrarily large increase in the midprice; if this is an isolated order, then this increase will just be an instantaneous spike, with the midprice reverting to its old level as soon as the next historical asks arrive; however, if, as with our TWAP agent, there are persistent incoming market orders over time, then it is possible that these incoming agent market orders outweigh the incoming historical asks and so one sees temporally-extended, albeit temporary, price impact, as we see in Figure 2. We see this price impact because market replay is using a limit order book mechanism, so the midprice naturally increases as price levels are taken out by the agent.Since these price levels that are taken out are not restored as frequently with market replay as in the LOBGAN (since LOBGAN reacts to the incoming market orders), 2 which has reactive order flow, the temporary price impact is larger.As soon as the TWAP agent stops interacting with the financial market, the incoming limit orders (that were placed in the historical financial market where the midprice hadn't moved upwards) quickly move the midprice back down to its historical level.
It is worth noting that this analysis is similar to that performed in Coletta et al. [15].However, in Coletta et al. [15], the authors look at the price impact of a TWAP agent that, every minute: first, places a limit order on the touch; then, if the order doesn't get filled, places a market order to hit their target for that period.Market impact (%) The price impact of market orders market replay Figure 2: The average price impact path of a TWAP market metaorder in the CGAN environment and in the market replay environment.This TWAP execution consitutes an average of 70% of the traded Percent of Volume (POV) over its 5 minute execution window (shaded in grey).Error bars represent the 5th-95th% confidence interval.The start time of the trajectory is given by 30 equally-spaced times for two days for a total of 60 trajectories.

Impact path of limit orders
Whilst the impact of market orders has been much studied, the impact of limit orders has received less attention.An in-depth study of the price impact of limit orders is conducted in Hautsch and Huang [24].The authors find that relatively large limit orders do have a significant market impact, pushing the price up for large bids and down for large asks.
In Figure 3, we illustrate the price impact of limit orders in LOBGAN and market replay environments.The market-replay simulation produces minimal market impact, since non-aggressive limit orders (limit orders that do not enter the spread) only affect the price by being filled instead of limit orders deeper in the book that would have been filled had they not been there.In particular, the future evolution of order flow is not affected by their presence leading to a tiny market impact.In contrast, these incoming limit orders can impact subsequent order flow in LOBGAN, and this impact, as shown in Figure 3, has same characteristic shape in response to a meta-order as found in the literature and shown in Figure 4.It is worth mentioning that LOBGAN exhibits a greater price impact with limit orders than with market orders (see Figure 2).This phenomenon is partially related to the BookImbalance 1 feature (see Section 5.1) which is generally a strong predictor of the sign of future price changes [10].LOBGAN is overreliant on this feature and large limit buy orders alter the BookImbalance 1 and drive the price up.We further investigate this effect in Section 5.2.1.

Comparison with impact paths from the literature
The LOBGAN price impact path closely resembles the shape of the price impact path from the empirical and theoretical literature given in Figure 4 or Bouchaud et al. [10,Figure 12.1].In particular, temporary price impact is increasing in the volume that is executed and concave (Bouchaud et al. [10] states that it should be approximately square root in volume and Bacry et al. [5] find it to be power law with exponent 0.6).Then, there is also clearly a permanent price impact component, as the midprice mean reverts back to a proportion of its peak impact.Furthermore, the permanent price impact is even approximately equal to 2/3 of the peak price impact (a finding from Zarinelli et al. [57]).market as a whole is learnt -which includes the order flow from market makers.Market impact (%) The price impact of limit orders market replay Figure 3: The price impact of a an agent placing and maintaining a relatively large limit buy order (of volume 750) at the touch over a 5 minute window (shaded in grey).The executions from this order constitute approximately 60% of the traded volume.Error bars represent the 5th-95th% confidence interval.The start time of the trajectory is given by 30 equally-spaced times for two days for a total of 60 trajectories.Here, the TWAP execution period is shaded in grey.
Apart from the issues relating to the excessive impact of limit orders when compared with market orders, the market impact produced by LOBGAN is much more realistic than that produced by market replay.The impact of a buy metaorder.This form of the impact function represents the temporary price impact (until time T), the permanent price impact (the long-run limit level) and the transient price impact (the difference between the price impact at the peak and the long-run limit level).This shape can be seen empirically in Figure 13 of Zarinelli et al. [57] or Figure 8 of Bacry et al. [5]).

Further benefits
We now describe two important further benefits of the CGAN approach which motivate the challenge of designing robust and realistic models.
The first further benefit is data shareability: Generative models offer a way for commercial entities to share realistic data with academia, whereas sharing historical data is constrained by licensing and cost issues.
The second further benefit is variability of the market scenarios that a generative model can generate.A weakness of backtesting is that there is only one market history, so backtesting is prone to "time-period bias", i.e., in essence, overfitting to the particular history that was encountered.An attractive feature of CGANs is that they can create many possible histories depending on the randomness that is used every time the CGAN outputs new orders.While there is only one true market  history, with a generative model, you can in principle generate as much data as you want.With an effective generative model, this then allows the use of potentially sample inefficient machine learning approaches such as Reinforcement Learning, while avoiding the problems of both "time-period bias" and "data-snooping bias" [51] (where good results are obtained by luck just because the same data is used again and again).

Realism metrics
In Section 2.3, we introduced the concept of realism in isolation as the ability of the CGAN to generate realistic limit orderbook markets when trajectories are rolled out at test time with no other agents in the system.In general, a single metric to measure the realism of a synthetic market does not exist, and we rather evaluate how well a range of statistical properties align with those of real markets.These properties are typically highly non-trivial and sometimes counter-intuitive, which makes it very difficult, if not impossible, to define a single unified metric [10].
In this section we briefly review the main statistical properties that have been used in the literature to evaluate synthetic LOB markets, and we refer to these properties as stylized facts [54].We use such stylized facts to evaluate the synthetic price series, volumes and order flow.We consider: autocorrelations, the heaviness of tails of the respective distributions, long-range (temporal) dependence, the order volume distribution, the time to first fill, and the depth and market spread distributions. 3hese stylized facts are used to answer two fundamental questions during the CGAN training process: • At which training epoch has the model stabilised?
• Given two trained CGAN models, which one is more realistic?
Due to the adversarial training procedure, the CGAN loss is by no means a perfect indicator of the generator quality [21].Instead, it is common to include humans in the loop (HITL) to evaluate the realism of generated samples during the training, especially in computer vision and image generation tasks, where human judgement can reliably reject unrealistic images [9].In our case, at the end of each epoch we unroll the CGAN in closed-loop simulation to generate multiple days of synthetic market data.We then compute the stylized facts and compare them against those of the real market.As mentioned, we do not have a unified metric but we rather adopt the HITL approach to distinguish between the properties of synthetic data streams, using the stylised facts as a basis.In particular, considering the HITL approach we restrict the analysis to price series, volume at best bid and ask, and spread as shown in Figure 5.
We consider them as a prerequisite of a realistic market.Importantly, it is the case that humans can easily distinguish between real stock price series and synthetic price series generated by simple popular stock price models (members of the Brownian-motion-based midprice processes) [32,Chapter 2].Also, since mode collapse is common during training of generative adversarial networks, one needs to ensure that the generated price and volume trajectories exhibit significant diversity.
Finally, the best trained model can be tested against all the stylized facts.We refer to Coletta et al. [15] for the complete evaluation of LOBGAN realism, and in Figure 5 we report the restricted set of statistical properties computed in isolation (unrolled in closed-loop) against real data.The Figure also confirms the realism and the ability of LOBGAN to cope with previously generated synthetic orders and possible compounding errors during the unrolling of those orders [52].
In the original paper Coletta et al. show also that the CGAN produces realistic dynamics in presence of a certain class of experimental order-execution agents [15].In particular, the authors introduce an impact experiment in which an experimental agent buys (sells) a given amount of volume showing how the simulation reacts and eventually mean-reverts.They show that, in these cases, the simulator manages to simulate realistic price impact paths and stylized facts.In Section 5.2 we answer a different question: can an experimental agent discover weaknesses of LOBGAN and drive the market into a desired state?

The conditioning of LOBGAN
This section explores the conditioning mechanism of LOBGAN.In Section 5.1, we define and explain a range of relevant features, which are based upon the dynamics of the order book.These features include all of those that are used by LOBGAN, as well as some further features that are useful for our analysis and development of LOBGAN.In Section 5.1.1 we specify the features that are used by LOBGAN.Then, in Section 5.2, we present an analysis of the feature dependence, highlighting the difficulties in analysing sequentially generated data.Finally, in Section 5.3 we perform an ablation study, where we train models with and without certain candidate features to understand their importance.

Feature definitions
Since extracting features from the raw data is difficult and computationally expensive [47], LOBGAN uses hand-crafted features that have been successfully used in other parts of the market microstructure literature [10].

Order book features
Denote the i th best price on the bid and sell sides of the order book by P b i (t) and P a i (t) respectively.Corresponding to these price levels, let V b i (t) and V a i (t) denote the volume of limit orders at same i th level of the bid and ask sides of the book respectively.We then define the following order book features: • The total volume at the top n levels of the order book at time t, • The order book imbalance of the top n levels of the book at time t, • The spread at time t, Spread(t) = P a 1 (t) − P b 1 (t).
• The percentage return for a time window [t − ∆, t] is given by • Suppose that the order book events occur at times t i for i ∈ N.Then, the midprice at time t is equal to the midprice at time t j * (t) for j * (t) = sup{j ∈ N : t j ≤ t}.After the n th order book event, we may then also define the n-event percentage return at time t by EventPctReturn n (t) = We further define the touch to consist of the best bid and the best ask price levels.When we refer to quoting at a distance from the touch, this means that we post a limit order at that distance away from the best price on the corresponding side of the order book.This is quoted in ticks -the minimum price difference between two price levels in a LOB.

Trade features
We now introduce a family of trade features.Suppose that trades occur at times s i for i ∈ N and let V trade s i be the signed volume of the trade; if the trade is seller-initiated then it takes a positive sign, if it is buyer-initiated, it takes a negative sign. 4 Then, for t ≥ ∆ one can define the trade volume imbalance of window size ∆ at time t by

LOBGAN features
The features which LOBGAN conditions upon are: • the order book imbalance for n = 1 and n = 5 levels; • the total volume at the first level and at the top five levels of the book; • the spread; • the n-event midprice percentage return for n = 1 and n = 50 order book events; • the trade volume imbalance over the last minute and over the last five minutes.
To better capture the market evolution over time, LOBGAN concatenates the feature values over the last 30 seconds.

LOBGAN features dependence
The conditional nature of LOBGAN is crucial for two main reasons: firstly, it makes it easier for the CGAN to learn to produce stable (and therefore more realistic) trajectories; secondly, it ensures reactivity when an exogenous agent interacts with the order book.In this section, we investigate how the order book dynamics depend upon the input feature vectors and which features produce the largest changes in the trajectories of the trained CGAN.
Notice that, analysing the effect of individual features is extremely difficult for a number of reasons: firstly, there are cross-correlations between all of the input features (see Figure 6); second, we do not only want to investigate the distributional properties of a single output of the CGAN -realistic order flow data must be maintained when the orders generated by the CGAN are processed and the features are fed back into it which compounds any errors in the order flow; finally, there is also a "mechanism effect" that comes directly from the order book mechanism -this should ideally be separated from the effect of the features.
In this section, we introduce a pragmatic approach to investigate the long-run dependence of the CGAN output upon certain features.This approach requires that the correlations between the input features not be too large.We see in the correlation matrix in Figure 6 that this is indeed a reasonable assumption.To investigate the effect of various features we first roll out 60 trajectories each lasting 20 minutes, starting on a lattice of evenly spaced points across two trading days in January 2021.These act as baseline trajectories.We then repeat the process twice for each input feature of the CGAN, fixing its values to be equal to the 5 th and 95 th percentiles of the empirical training distribution; we give these percentiles in Appendix A.1.We allow all of the other features to update as the order book updates.Finally, we investigate the properties of the time-series data for each of these trajectories with the goal of measuring the effect of fixing these features on certain key properties of the time-series data that are described in Vyetrenko et al. [54].In particular, if the trajectory statistics for these rollouts with extreme values for the conditioning appear much the same as the baseline trajectories, then these features are candidates for ablation, and if there is a clear dependence of any of the output "stylised facts" on the feature being perturbed, then this knowledge provides a partial explainability of the CGAN.It can also be used to construct "adversarial" strategies for the CGAN.
Discussion of approach.Our approach allows us to investigate how altering a single input feature of the financial market effects the output of LOBGAN and, as a consequence, the rolled out trajectories.It is worth noting here that we do not actually change the past orderbook or trades that occur, but rather LOBGAN's perception of them.This in turn may of course change the future output of LOBGAN, which is the whole point.This type of A/B testing is simply not possible using historical data, as it relies on counterfactually altering one component of the financial market and seeing how the subsequent order flow evolves.There are not enough historical time intervals in which the value for one of the input features remains unaltered, and so the macro effects of such a change cannot be studied easily.It is only possible to look at the order-level distributions and then attempt to infer how the changes in distribution affect the dynamics of the order book throughout time.Thus, under the assumption that LOBGAN has successfully learnt the conditional distribution of orders from historical data, this presents a completely novel approach to investigating LOBs with much more insight into the causal mechanism.In the rest of this subsection, we employ our approach for the different LOBGAN features in turn.We note that, in this approach the input to the CGAN after having been altered could correspond to an unrealistic orderbook and historical trade combination.However, as we see in results below, the dependence of the CGAN output on the input modified in this manner is actually relatively well-behaved (stable).

BookImbalance 1
When the book imbalance at the touch is larger -due to a larger volume of buy limit orders than sell limit orders -the trajectories generated by LOBGAN noticeably trend upwards more on average (see Figure 7).This effect has also been frequently observed in analyses of historical data, where book imbalance is often a predictor of the next midprice move (see, for example, Bouchaud et al. [10], Zheng et al. [59]).This effect could have a variety of causes: there could be an imbalance between the market buy orders and the market sell orders; on the ask side of the book there could be an imbalance between limit orders and cancellations; or, on the bid side, there could be an imbalance between limit orders and cancellations.By investigating the properties of the individual orders outputted by the CGAN during these trajectories, we can answer the question of how this trend appears.
In Figure 8, it is clearly shown that one of the causes of the upwards price trend is the effect on the direction of outputted market orders.Specifically, when the imbalance is lower, LOBGAN outputs a larger proportion of sell market orders and vice-versa.This is one of the causes of the downward price pressure.Furthermore, if the input of BookImbalance 1 to the CGAN is lower, there is an increase in the quantity (cancellation volume − limit volume) on the sell side when compared with the baseline trajectory.This means that there are relatively much more cancellations than limit orders.Similarly, when BookImbalance 1 takes a large value, there is a decrease on the sell side of the quantity cancellation volume − limit volume.Interestingly, in both cases the difference on the bid side of the book is unaltered.It seems likely that this is simply due to bias in the training data, and that the price dynamics w.r.t.BookImbalance 1 have become overly reliant on the sell side of the book.

TradeImbalance
Both TradeImbalance 1 and TradeImbalance 5 have a large effect on the dynamics of the midprice, with TradeImbalance 1 playing a particularly big role.A plot of the effect can be seen in Figure 22 in the appendix.In particular, the midprice is increasing in the value of TradeImbalance.It is also worth noting that TradeImbalance is increasing in its own value (which produces a self-exciting effect).Similarly to BookImbalance 1 , the main causes of the upward (downward) price are the larger proportion of buy (sell) market orders shown in Figure 23, and the difference of (cancellation volume -limit volume) on both sides of the book shown in Figure 24.Compared to BookImbalance 1 , the quantity (cancellation volume -limit volume) is more symmetric, being consistent across both sides of the book.Relative midprice (%) The dependence of on

Volume and PctReturn
Upon observing the rollouts when individually fixing TotalVolume 1 , TotalVolume 5 , PctReturn 1min and PctReturn 5min in turn, it is clear that none of them has a meaningful effect.Therefore, they are candidates for ablation (Section 5.3).

Spread
The spread plays a key role in the dynamics of the trajectories generated by LOBGAN.In particular, it is highly mean-reverting.This is essential for the stability of the outputted market dynamics.This can be seen in Figure 10 -when LOBGAN perceives the spread to be small, it outputs orders that increase the spread; when the spread is large, LOBGAN tries to close it.It does this primarily via the distribution of order types (see Figure 11).When the spread is large (i.e., 95 th percentile), LOBGAN places more limit orders so that more liquidity is provided to the market and the spread tightens.When the spread is small (i.e., 5 th percentile), the order type distribution shifts in favour of deletions and the spread increases massively.

Ablation studies for candidate features
To further investigate the LOBGAN's features as candidates for inclusion or not in a potentially improved model, we perform an ablation study in which we train the model without the features that do not show an observable effect in the rollouts from Section 5.2 (i.e., TotalVolume 1 , TotalVolume 5 , PctReturn 1min , and PctReturn 5min ).
In the ablation study we remove features and investigate how time to model convergence and model realism (see Section 4) are affected.Without TotalVolume 1 and TotalVolume 5 the model achieves comparable realism, meaning that it is able to unconditionally learn the average volume of the orders.In fact, we recall that CGAN is trained against a discriminator that rejects unrealistic volumes.Without PctReturn 1min and PctReturn 5min we observe substantially more training time, i.e., more unrealistic markets in the early phases, yet comparable performance at the end of the training procedure.As the returns are used also by the discriminator, we can conclude that they help more with rejecting unrealistic markets during training than with conditioning the generation.

LOBGAN adversarial attacks
In this section, we show that certain simple trading strategies are able to exploit the LOBGAN model, completing round trip meta-orders and turning a profit.This means that the agent begins and ends the trajectory with a "risk-neutral" inventory of zero and such trades constitute a form of arbitrage.Some of these trading strategies, such as market making, are commonly studied in the literature -however, these strategies can be implemented so as to realise unrealistic outsized profits for the adversarial agent.Other adversarial attacks have been inspired by Section 5.2 to take advantage of feature dependence in the CGAN model.Finally, we introduce trading strategies that "exploit" the order creation mechanism5 of the LOBGAN-based simulator.
All of these strategies start with zero inventory and liquidate any terminal inventory and sowhilst the profit and loss curves are marked to market (MtM) -the terminal profit corresponds purely to an increase in the cash holdings of the agent from the start to the end of the episode.

Market-making
Market makers (i.e., liquidity providers) are a ubiquitous and crucial type of participant in highfrequency financial markets.In orderbook-driven financial markets, they post limit orders on both sides of the book always offering to buy or sell with the aim of earn the difference between the bid and the ask whenever they complete a round trip trade of one order.Their main source of risk is inventory risk -the possibility that they will accumulate a large (positive or negative) inventory by getting filled unevenly on each side of the book before the price moves against that inventory; the other source of risk is adverse selection where they are more likely to get filled by informed traders than uninformed traders.
In this section, we introduce a naive symmetric market-making strategy that posts a symmetric volume around the midprice of the asset.These strategies update every 5 seconds -maintaining a fixed volume on each side the book at a fixed depth.They do so by cancelling existing orders that after an orderbook update are no longer at the desired depth, replacing them with orders at the desired depth.This simple liquidity provision strategy ends up being consistently profitable in the trained LOBGAN-based simulator (see left hand panel of Figure 12), and is robust across a range of depths.While market making is a highly profitable activity in real markets, it is not realistic for such a simplistic strategy, which uses a fixed distance from the touch on both sides at all times (i.e., it never skews its spread), to be so consistently profitable.
It is worth noting that this strategy is not profitable if it posts exactly at the touch, as the frequency at which the agent gets filled can cause the agent to accumulate a overly large signed inventory that needs to be liquidated at the terminal time (at a cost, through market impact) to satisfy the condition of being a round-trip meta-order.It seems highly likely that a more adaptive market-making strategy (see Jerome et al. [28] for example) could avoid this problem by managing inventory risk better.
In the right hand panel of Figure 12, the mean inventory accumulated by such a market-making strategy is plotted.The inventory mean-reverts, causing the inventory risk of the strategy to be maintained within reasonable bounds.

Accumulating a positive inventory using limit orders and then liquidating
As shown in Section 5.2, LOBGAN is quite sensitive to the order book imbalance.In this section, we show that a trading strategy can target this feature by continually placing a large volume of limit orders on one side of the book.The strategy also places a small volume of orders on the other side of the book.It accumulates inventory from the larger orders, and after liquidation at the end of the episode makes a profit from the overall round-trip meta-order.A specific example is an agent that maintains a limit order of size 200 at one tick away from the touch on the bid side of the book and an order 10% of the magnitude one tick away from the touch on the ask 6 .As described in Section 5.2, by making BookImbalance 1 larger, this strategy pushes the price up whilst accumulating inventory as the price goes up.The strategy is then able to liquidate at the terminal time for a cost that is less than the value it gained by pushing the price up, completing a profitable round-trip meta-order.Figure 13 shows the profit and loss of this strategy, along with the effect that this strategy has on the midprice dynamics as well as the strategy's accumulated inventory.We recall that this is an adversarial attack, like all of our strategies, created to highlight the LOBGAN model weaknesses.Moreover, our strategy is not a form of (illegal) market manipulation, like spoofing, since every limit order we place has a good chance to be, and often is, executed.
It is worth briefly commenting on a similar strategy -which pushes the price up using buy market orders.This strategy causes price impact, but also importantly increases the values for TradeImbalance.Whilst this strategy did manage to have an outsize effect on the midprice of the market, it was not a profitable round-trip trade as the cost of liquidating the large accumulated inventory at the terminal time offset its gains.Figure 13: The left-hand side shows the profit and loss for a simple strategy that places buy limit orders over a 10 minute period and then liquidates its position with a market order.The right-hand side shows the midprice of the order book and the inventory for this strategy.

The weakness of the LOBGAN placing mechanism
The trained CGAN outputs orders with relative prices called depths.For example, if the CGAN outputs a bid limit order with depth 1, then it is placed one tick away from the current touch on the bid side of the book.This ensures that the order price distribution is stationary, improving the performance and convergence of the CGAN compared to training the CGAN using absolute prices.However, as we will show in this section, this rule for assigning prices to orders can be a exploited by an interacting agent.
A limit order that is placed at a better price than the touch (i.e. the current best price in the order book) is called an aggressive limit order.The arrival of aggressive limit orders, the cancellation of orders at the touch, and the execution of orders at the touch are the ways in which the midprice in a LOB changes.In particular, restricting to the bid side of the book for clarity, the midprice decreases when sell market orders arrive and are executed, or when the bid touch is fully cancelled; the midprice increases when aggressive bid limit orders are placed.These same events cause the spread to increase and decrease.
The adversarial strategy in this section is the following: maintain a single limit order at the touch on the side of the book that the agent wishes to move inwards.For example, we describe the strategy for a case in which the agent wishes to move the price to move down.This strategy is shown in Figure 14, where the bottom and top rows show the market evolution with and without the strategy, respectively.In this market, the best ask price is 101$ (top left chart), thus the agent can place a new ask limit order at 99$ being at the touch of the side he wishes to move inwards (bottom left chart).This means that the prices of all new incoming sell limit orders from LOBGAN (which are priced relative to the best ask) are now relatively lower (bottom right chart) than they would have been had the aggressive order of the agent not been added to the order book (top right chart).In short, the agent's aggressive ask order means that the best ask is lower than it would have been without and this modifies subsequent order placement by LOBGAN.Then, the agent places an order of a larger size (we chose 300) at a fixed depth away from the ask touch (to get a better sale price) to accumulate a negative inventory and profit as the price price goes down further.
We recall that also in this case, our adversarial strategy is demonstrating a weakness of the LOBGAN placing mechanism, which is not representative of a real market.Moreover, we never cancel Here, the agent places a small aggressive sell order near the original midprice (the agent's sell order then becomes the best ask) which puts downwards pressure on the midprice.This is because all of the ask orders generated by LOBGAN -which are assigned a price relative to the best ask -have a lower price assigned to them than if the agent's order was not present.
placed orders to make them less likely to be filled.The resulting strategy is consistently profitable across a variety of depths for the larger fixed-depth order (see Figure 15).Profit and loss for mechanism agent large order at level 3 large order at level 4 large order at level 5 Figure 15: The profit and loss for adversarial strategy on the market mechanism (Section 6.3) for a variety of depths and for a fixed (main) volume of 300.

Learning liquidity provision with reinforcement learning
As well as the three hand-crafted strategies in the previous sections, we trained a simple marketmaking reinforcement learning agent to act in the LOBGAN environment.The state of the agent was simply the agent's inventory and the spread of the environment, 7 and the action space was that considered in Spooner et al. [50] with one minor alteration and several extra actions.In Spooner et al. [50], the agent is allowed to quote symmetrically around the midprice with a half-spread in {1, 2, 3, 4, 5}; it also has two options in to skews their orders relative to midprice -quoting at 1 tick away from the midprice on one side of the book and 3 ticks away on the opposite side or 2 ticks away from the midprice on one side of the book and 5 ticks away on the opposite side.
The first change that we make is to have our market maker agent price relative to the touch (the best price on the relevant side of the book) instead of the midprice.The second change is to augment these 9 available actions with 6 more: the ability to post at 1, 2, or 3 ticks away from the touch on one side of the book and not quote on the opposite side of the book.
After training the reinforcement learning agent, we find that it learns a policy that is a combination of the strategies found in Sections 6.1 and 6.2.On the right hand side of the plot -where the spread is large -the agent learns a version of the market making strategy from Section 6.1.In the lower left corner of Figure 16, when the agent has a negative inventory, the agent takes action 14, corresponding to placing a large order 3 ticks away from the touch on the ask side of book to push the price down.In the top left hand corner, when the agent has a large positive inventory, the agent learns to place a large buy order 2 ticks away from the touch and a sell order 5 ticks away from the touch, i.e., it has learnt to emulate the strategy from Section 6.2.Thus, the weaknesses of the LOBGAN shown in previous sections enable this adversarial strategy, which exploiting the CGAN model, rather than learning a real profitable policy.We recall that, this is an adversarial strategy exploiting the CGAN deep learning model, rather than market manipulation.

Insights from the CGAN weaknesses
From the strategy tested againsts the LOBGAN in the previous section, several conclusions emerge, which we discuss next.
Conservativeness.The market making strategies are problematic because an unsophisticated strategy earns large, consistent profits.It is important to note that market-making is profitable in real markets, the main issue is that it should not be so easy to design a profitable trading strategy, and such as strategy should not be as simplistic as those in Section 6.Actually, it is preferable that a simulator be too hard rather than to too easy; that is, we prefer to be conservative when evaluating a trading strategy, and indeed this is the typical approach taken in practice.For example, when backtesting a strategy one would typically assume that trades incur slippage that hurts profits even if occasionally slippage might help.In a similar vein, we would in general like a simulator to provide an environment in which it is too hard to make profits rather than too easy [38]: It is common wisdom that strategies practically never outperform their backtests when traded in reality, and it is desirable to have a "harder" simulator that gives a more accurate picture of expected performance in real markets.Thus, our first conclusion is that it is possible to use strategies like ours to provide a check on how easy it is to produce profit and thereby conclude whether or not the generative model simulator is suitably "hard".
Relative vulnerabiltiy of features.The easiest LOBGAN features to exploit were BookImbalance and Spread.TotalVolume didn't have as large of an effect on the dynamics of LOBGAN as the other features, as described in Section 5.2.Among the other LOBGAN features, TradeImbalance could be exploited in a similar fashion, altering the perception of LOBGAN model and generating the desired market regime.However, creating an adversarial attack on the TradeImbalance requires, firstly, crossing the spread with market orders, which is costly, and, secondly, a costly liquidation at the terminal time.
The placing mechanism weakness.This section showed that as well as exploiting the model features, the CGAN is also sensible to the relative placing price, which enable an aggressive limit order to change the best price on one side of the book (which the CGAN then posts orders in relation to).
We discuss an approach to address the weakness of the placing mechanism in Section 9.

Improved LOBGAN models
This section presents various solutions aimed at improving the robustness of LOBGAN and the simulators that are built upon it.Based on the the previous section strategies, we can identify four possible limitations of the current LOBGAN-based simulator: 1. Representativeness -by using a restricted set of hand-crafted features the simulator has a limited view of the financial market which could lead to unrealistic behaviour when it conditions on certain market regimes.In particular, any predictive feature of the financial market that is uncorrelated to the input features of LOBGAN will be invisible to it.

2.
Overimportance of certain features -by limiting the number of features to a handful of human-interpretable market features, new developed strategies could be "biased", i.e., overfitted, on these LOBGAN features, and not being profitable in a real market but just on the LOBGAN environment.In fact, by only including a limited number of features there is a much higher risk of the model becoming over-reliant upon them, thereby facilitating the bias in developed strategies.
3. Interactiveness -independently from the chosen features, LOBGAN is training in a closed-loop: during the training the model learns to generate orders from ground truth past states and novel states induced by its previous orders.While this training alleviates compounding errors (i.e., it reduces the possibility that previous suboptimal decisions induce unseen states and failures), the inclusion of an interactive agent (i.e., trading agent) during training will almost certainly be able to create novel or adversarial states that are not seen in the current training of LOBGAN.In short, lack of interaction with training agents during training is arguably a limitation of LOBGAN.
4. LOBGAN order placement -by placing orders relative to dynamic market features (i.e., best bid/ask) LOBGAN enables a trading agent to manipulate the next placed LOBGAN orders by altering these features, as seen in Section 6.3.Thus, using the touch for relative order placement is a limitation of LOBGAN.
Therefore, although hand-crafted features are useful for development and explainability, they are the first limitations we should address to improve simulations.We now propose three improved LOBGAN models by addressing the representativeness and overimportance of features limitations discussed in the previous section.We discuss a solution to interactiveness and order structure in Section 9 in the form of a new training procedure and placing mechanism, respectively.

Representativeness
The LOBGAN model uses a set of hand-crafted features introduced in Section 5.1.1 to create its own representation of the financial market.However, this representation can be limited and cause misleading behaviour under certain market regimes.Learning the market dynamics from raw orderbook observations would be ideal, but it is difficult and computationally expensive in general [55], and this is possibly further aggravated by the adversarial training of GANs; we discuss this further as a future research direction in Section 9. Instead, here we show how to improve the Representativeness by introducing a new LOBGAN model that augments the features detailed in Section 5.1.1 with the following new features.This allows the CGAN to have a more detailed view of the current market state.The features that are added to this new version of LOBGAN, which we refer to as LOBGAN v1 (with the original LOBGAN being denoted by LOBGAN v0), are: • the order book imbalance for n = 10 (i.e., for the top 10 levels of the book); • the total volume at the top 10 levels of the book; • the midprice percentage return over the last ∆ ∈ {1, 5} minutes; • the trade volume imbalance over the last 10 minutes; • the total execution volume over the last ∆ ∈ {1, 5, 10} minutes; where the total execution volume of window size ∆ minutes at time t is defined by , where s i is the time at which the trade occurs, and V trade s i is the signed volume of the trade.We also remove the two n-event midprice percentage return features to reduce the overlap/correlation of features (given that we now include time-based midprice returns).
Realism of LOBGAN v1.In the first row of Figure 18 we evaluate the realism of the new proposed model by comparing its stylized facts against those of real market and LOBGAN v0 in Figure 5.We note that LOBGAN v1 achieves similar realism for the volume and spread time-series, with a clear resemblance between the simulated and real time series.Interestingly, the new model has slightly better price series: they exhibit significant diversity and better symmetry.We believe the new features, and especially the time-based midprice percentage return, are responsible for the increased realism (in isolation) of the price series.
Robustness of LOBGAN v1.As well as improving realism in isolation, it is also the case that LOBGAN v1 is more robust to the main adversarial strategies we introduced in Section 6.In Fig- ures 19 and 20, we can see that LOBGAN v1 makes improvements in terms of robustness to both the BookImbalance 1 strategy and the market making strategy.While these strategies can still be employed, they will be more expensive and less profitable: the first strategy just about breaks even on average, and the second one loses money.

Feature overimportance
The introduction of new hand-crafted features in the last section partially solved the overly reliance on some features that was outlined in Section 5.2.In particular, LOBGAN v1 largely neutralised the imbalance overreliance shown in Section 6.2.(see Figure 19).However, in general it is by no  means guaranteed that adding new features will preclude the model overly relying on just few of them.In this section we further investigate strategies to mitigate over-reliance on certain features.For simplicity, we continue to focus on BookImbalance 1 and the related adversarial strategy.Starting from LOBGAN LOBGAN v1, we investigate two approaches to further mitigate potential over-reliance on BookImbalance 1 .

Removing BookImbalance 1
We first investigate the effect of simply removing BookImbalance 1 from the feature set for LOBGAN v1.
Realism of LOBGAN v2.In the middle row of Figure 18, we evaluate the realism of our second proposed model.We recall this model is a first naïve attempt to show the advantages and disadvantages of just removing relevant features.The figure shows less realism on both volume and spread with respect to the real data: volume accumulates over time while spread has higher variance.Most importantly, the proposed model shows price series with strong trends, moving more than 20% compared to the market open.BookImbalance 1 is a strong indicator of market direction [10], and when it is included as a feature, the CGAN uses it to generate more realistic time-series than it does without it.
Robustness of LOBGAN v2.The goal of LOBGAN v2 was primarily to improve the robustness of the CGAN to the adversarial attacks on BookImbalance 1 .As we can see in Figure 19, this goal was clearly achieved.In particular, the adversarial strategy losses its control over the midprice dynamics.Furthermore, as illustrated in Figure 20, LOBGAN v2 is also robust to market-making strategies.They make a slight loss and have a high variance, both undesirable from a risk and reward perspective.

Randomising levels used for the imbalance feature
We now introduce a more sophisticated attempt to reduce the model dependency on order book imbalance at level 1 by using a randomised version of this feature.We remove the order book imbalance at levels 1, 5, and 10, and we add the χ-level order book imbalance for a random variable χ.Here, we simply take χ to be uniformly distributed on the set S = {1, 2, 3, 4, 5} so that at each time period, the agent randomly samples one of these values to use for that feature.Before training, we pre-sample from this distribution so that the χ-level order book imbalance does not change when it is reused as a data point.
Realism of LOBGAN v3.The bottom row of Figure 18 shows the stylized facts of our third model and second attempt to feature overimportance.The figure clearly shows an improvement on realism for both volume and spread with respect to the previous attempt (the middle row in Figure 18).The stylized facts resemble more those of real data even though the generated price series still have stronger trends, moving around 10% compared to the market open.19 and 20, we can see that LOBGAN v3 improves upon all of the previous versions of LOBGAN in terms of robustness to both the BookImbalance 1 adversarial strategy and the market-making strategy.Both of these naïve trading strategies lose a substantial amount of money on average and have high variance.When considered alongside the improvements in realism over LOBGAN v2, this makes it a clear improvement.Profit and loss ($)

Robustness of LOBGAN v3. As shown in Figures
Profit and loss for limit up market down strategy

Recommendations for using LOBGAN or similar models in practice
In Section 9, we provide a roadmap for future research and development of conditional generative models for LOB environments.In this subsection, we discuss practical recommendations for how  best to use LOBGAN or similar models, given the current state of the art, and in particular the insights of this paper.We highlight three main recommendations: • Training LOBGAN with diverse feature sets.Our work and prior work has demonstrated that LOBGAN models can be generated with a variety of different features sets, which can result in models that have realism and robustness properties.We recommend to both explore further predictive features that are not highly correlated with the features already used in versions v0-v3 of LOBGAN and to train a variety of models using different subsets of features.The overarching goal is to choose as many uncorrelated and predictive features as possible.This will improve realism, as LOBGAN is able to form a more nuanced view of the financial market, and robustness, as LOBGAN should then be reliant on each of the features it uses, rather than overreliant on one or two features, which could then be easily exploited.It is further useful to have a wider pool of models to select from (the models trained with different feature spaces) and, as we discuss next, it can make good sense to use multiple models.The features used for LOBGAN were handcrafted; we discuss in Section 9 the, already mentioned, challenging but promising direction of using raw market data, rather than hand-crafted features, to allow the deep conditional generative model to learn its own features.
• Using multiple models.By using multiple models, one can improve the robustness of trading strategy evaluation.A natural way to use multiple models is to run a strategy independently in a simulator using each of these models, and then use the distribution of performance across the models to evaluate the strategy.The evaluation could use a variety of statistics of this distribution; for example, a worst-case approach would use the worst performance across models.
• Use existing trading agents for calibration/model selection.If the user has access to historical true trade data from a variety of agents, such as execution and market making agents, then this data could be used to calibrate LOBGAN to make sure that it gives similar profit as that achieved by these test agents in historical live trading.While this will almost never by feasible for an academic project, it would be very natural for a commercial trading entity.

Related work
Conditional generative models.Conditional generative adversarial networks (CGANs) were introduced in Mirza and Osindero [33], where they were demonstrated and evaluated using the MNIST dataset of images of handwritten digits.In general, GANs and CGANs have mainly and most prominently been used the context of image generation tasks, but they have also been explored for generating a wide variety of other types of data, including tabular data [56] and time series data [18].Important early works on GANs include Arjovsky et al. [2] (who introduced the Wasserstein GAN used by Stock-GAN [31] and LOBGAN [15]) and Gulrajani et al. [23], who made fundamental contributions to improving Wasserstain-GAN training such as gradient penalties (used in the training of LOBGAN).While conditional generators for LOBs have so far used CGANs, other important types of generative model exist.We briefly mention Conditional Variational Autoencoders (CVAEs), which have been used to for generating lower-frequency financial data (such as hourly or daily data as opposed to LOB data), e.g., Bühler et al. [12].Other generative model approaches that have been applied to time series include normalizing flows [43] and denoising diffusion models [25,42].It is an interesting direction to explore what these other approaches can offer for LOB simulation, although the feature exploitation demonstrated in this paper would likely apply to any conditional model if explicit care to avoid it is not taken.We discuss denoising diffusion models further in Section 9.
• Adversarial Reinforcement Learning.In "Robust Adversarial Reinforcement Learning" (RARL), during the training of an agent in an RL environment, a second adversarial agent is introduced into the environment system with opposite rewards, and this adversary is given (limited) control over (e.g., the transitions of) the environment [39,49].This is closely related to what we propose in Section 9, namely introducing trading agents during CGAN training.
• Learning to simulate.There are existing works that use RL in order to learn a simulator, such as Ruiz et al. [44].However, these works tend to look at settings where there is a downstream task that the simulator will be used for, such as image classification, where accuracy in that task can be used as a reward function.In our setting, part of the challenge is that our desiderata for our simulator are complex and multi-faceted, and to apply RL a key challenge would be design of the reward function, and dealing with the fact that it would be a multi-objective problem.
Agent-based models.For a long time, agent-based models (ABMs) have offered the promise of reactive financial and economic market simulation.However, due to a combination of the lack of agent-level historical data, and the intrinsic difficulty of calibrating ABMs, they are not currently a viable option for realistic strategy evaluation.ABMs in principle offer reactivity, similar to conditional generative models, and in contrast to backtesting (market replay).In real markets the number of agents is huge, and their individual historical actions are not explicit in the historical data, which is anonymous.Thus, modelling and calibrating agent-based models (not just in finance, but actually in general) is a serious challenge (see, e.g., Bai et al. [6], Platt [41], Lamperti et al. [30], Platt and Gebbie [40], Coletta et al. [16]).While ABMs have been shown to be useful for investigating structural properties of financial markets [37], they are difficult to use in practice for testing trading strategies where a high precision of calibration is required.We do note that a combination of approaches is possible, for example, where a conditional generative model is combined with distinct agents -in this paper we investigate the case of various single trading agents operating within a CGAN environment, but one could include more agents in such an environment simultaneously.

Future work
In this section, we highlight some promising directions for future work.
Using raw market features.Existing conditional generative models for LOBs, including LOBGAN, use hand-crafted features.It is an open challenge to effectively train a conditional model using raw market features.Given the success of deep learning in learning representations from raw pixels of images, this does seem like a challenge worth pursuing at this point in time.One piece of work in this direction is Zhang et al. [58] which uses convolutional layers to extract features and create a representation of the ongoing market using raw order book snapshots.However, we found in some preliminary experiments that the training approach used by LOBGAN does not work immediately with raw features, perhaps because the representation learning that is needed is too challenging in the adversarial training setup.We suspect that new innovations may be needed in terms of a sophisticated training procedure, or an improved conditional generator architecture, if we are to effectively use raw orderbook features in a conditional generative LOB model.For instance, (denoising) diffusion models [25,42] could be a good candidate for a different type of generative model that may be good at processing raw orderbook data, thanks to their more stable training process and their remarkable results in computer vision handling high-resolution data.However, to simulate LOBs we require to generate tens of thousands of orders which may be computationally expensive for diffusion models (because each sample is generated through a high number of iterations/steps [17]).
An automated training approach that includes RL-based adversarial attacks.We demonstrated how interactive realism and corresponding adversarial attacks on the features and mechanism of LOBGAN could be used to build better generative models.It is appealing to try and systematize this process, for example, by using reinforcement learning (as we did post-training) to create adversarial agents during the CGAN training process.A challenge here is to effectively balance the CGAN's training objective between minimising the rewards of adversarial agents, and maximising realism in isolation.
Metrics for model selection.While a fully automated model selection procedure is desirable, it is arguably some way off.Firstly, human input into determining realism as in Section 4 currently brings an important sanity check to the process, and, secondly, there are so many aspects to realism that the required step of aggregating these aspects into single realism scores requires much more research.Still, this is certainly an important direction and worthy of further research as it will open up many possibilities.For example, with a realism in isolation metric and a metric for interactive realism one can explore whether there is a trade-off between these type of realism.With a metric for model quality, which would presumably combine metrics for realism in isolation and interactive realism, one could include an automated model selection step within the training process.A concrete example of this would be to use this metric as a fitness function within a population-based evolutionary method for constructing models.
Order placement mechanism.We demonstrated that a fairly simply, yet effective, adversarial strategy can exploit the order creation mechanism of the LOBGAN-based simulator: orders are placed relative to the best ask/bid.We envision the use of a more robust notion of price to solve this problem: new orders will instead be placed according to a more sophisticated notion of current price that the model could compute.This notion should be more resilient to temporary and exogenous trading orders, than the touch, or even midprice.Finding such a notion of price is an interesting research direction.We note, however, that adding sophistication here will increase the complexity of the training process.+ Wider applicability of our work beyond LOBs.The use of conditional generative models for simulation has widespread applicability, and is by no means only relevant for finance.As three examples, CGANs have been applied for simulation of flows in aerodynamical systems [13], fuel sprays in combustion engines [4], and sensors in autonomous vehicles [3].While some of our work is undoubtedly specific to LOBs, and other parts to economic/financial systems more generally, significant parts such as the distinction between realism in isolation and interactive realism, and our techniques for exploring the conditioning of a generative model, apply in general.In particular, we note that it will often be the case that when a conditional generative model is built as a simulator, the initial development will naturally tend to focus on realism in isolation, but often the end goal will be to allow interaction with the model.Our paper shows that is likely important to incorporate interactive realism into the design process from the start.

Conclusion
In this paper, we have explored the benefits and challenges of building conditional generative models for LOB environments.In doing so, we have stressed the distinction between realism in isolation and interactive realism.We then explored interactive realism in depth with LOBGAN, a specific family of models.We analysed LOBGAN for its dependence on features, and then we explored the weaknesses of its features and mechanism.Using the insights from our analysis and adversarial strategies, we designed new LOBGAN models that are better in terms of both realism and robustness.We finished by outlining numerous directions for further work on generative models for LOBs.All of these directions are at the same time both challenging but also potentially extremely fruitful • Action 12: place nothing on the bid side, large order 1 tick away from touch on the ask side • Action 13: place nothing on the bid side, large order 2 ticks away from touch on the ask side • Action 14: place nothing on the bid side, large order 3 ticks away from touch on the ask side   Relative midprice (%)

A.4 Additional experiments
The dependence of on

3 Figure 1 :
Figure1: In the leftmost subfigure, we see the bid limit orders in blue and ask limit order in red.The best bid (ask) price is $98 ($100).At a given price level, orders of different market participants are delimited by vertical lines, with orders nearer the front of the queue for that price level being nearer the bottom.In the middle subfigure a buy market order with volume 40 has arrived.It totally takes out the old best ask and a further volume of 20 from the next best ask (price $101).After this execution the spread has widened from $2 (i.e., 100-98) to $3 (i.e., 101-98).

Figure 4 :
Figure4: The impact of a buy metaorder.This form of the impact function represents the temporary price impact (until time T), the permanent price impact (the long-run limit level) and the transient price impact (the difference between the price impact at the peak and the long-run limit level).This shape can be seen empirically in Figure13of Zarinelli et al.[57] or Figure8of Bacry et al.[5]).

1 1 = 5 th percentile baseline 1 =Figure 7 :Figure 8 :
Figure 7: The effect of fixing BookImbalance 1 on the midprice dynamics.The midprice change is calculated relative to the "baseline" case in which the feature BookImbalance 1 is unaltered.

Figure 9 :Figure 10 :
Figure9: The effect of fixing BookImbalance 1 on the difference between the volume of cancellation orders and the volume of limit orders.This difference is a key driver of price changes.

Figure 11 :
Figure 11: The effect of spread on the proportion of different order types.

Figure 12 :
Figure 12: The left-hand figure shows the profit and loss for a family of market-making strategies that symmetrically posts a (relatively) large volume at a fixed number of levels (its depth) from a target.The right-hand figure shows the associated inventories.

Figure 14 :
Figure14: An illustration of a market-mechanism weakness.Here, the agent places a small aggressive sell order near the original midprice (the agent's sell order then becomes the best ask) which puts downwards pressure on the midprice.This is because all of the ask orders generated by LOBGAN -which are assigned a price relative to the best ask -have a lower price assigned to them than if the agent's order was not present.

Figure 16 :Figure 17 :
Figure 16: The policy learnt by a simple reinforcement learning agent who posts at the touch.Colours represent the different actions (see Appendix A.3).

Figure 19 :
Figure 19: The profit and loss trajectories for the BookImbalance 1 strategy from Section 6.2 when used on the new models.LOBGAN v0 is the original version of LOBGAN which is studied throughout Sections 2-5, LOBGAN v1 is modified to use the features outlines on Section 7.1, LOBGAN v2 uses the features in Section 7.2.1, and LOBGAN v3 uses the features in Section 7.2.2.

Figure 20 :
Figure20: The profit and loss trajectories for the market making strategy described in Section 6.1 when used on the new models.

Figure 21 :
Figure21: A market maker strategy that places a single unit order at the touch to constrain the spread and then a symmetric larger order of volume 300 at a fixed depth away from the touch.

Figure 22 :
Figure 22: The effect of fixing TradeImbalance 1 on the midprice dynamics.The midprice change is calculated relative to the "baseline" case in which the feature TradeImbalance 1 is unaltered.