Financial markets are complex systems where millions of people buy and sell and millions of dollars change hands each microsecond. When you think about markets in this way, there’s no question as to why they are so incredibly hard to understand, predict and beat.
In order to unravel this huge puzzle of financial markets, we can try to explain how prices are generated in an order book market, and how trading works in these markets.
Market prices
Everybody’s heard analysts on Bloomberg, CNBC, etc., talking about what’s driving the price of crude oil, gold, the Euro or Apple. But, in fact, there’s only one reason why prices go up or down: offer and demand.
So when we try to analyze the reasons for prices going up or down, what we’re actually doing is looking for reasons why there’s been a change in the willingness of people to buy or sell a given asset.
So how does this offer and demand balance translate into a price movement?
There are two main kinds of market participants: market makers and market takers. Market makers place limit orders in what is called an order book and, this way, they create liquidity.
- Market makers place buy limit orders, indicating the amount of shares they are willing to buy at a certain price level, below the current price. This is called the bid.
- Market makers place sell limit orders, indicating the amount of shares they are willing to sell at a certain price level, above the current price. This is called the ask.
The difference between the best bid to buy and the best ask to sell is the current spread, and the price that we actually observe and call ‘price’ is actually the mid-price (the average between best bid and best ask).
On the contrary, a market taker simply tries to buy or sell a certain amount of stocks at market, i.e. for whatever available prices are the best in the order book. Consequently:
- When you try to buy at market, your market orders will impact the ask side of the order book, above the current mid price.
- Whereas if you sell at market, your market orders will impact the bid side of the order book, below the current mid price.
Please bear in mind that this means that a market maker always trades at a better price than the current mid price and a market taker always trades at a worse price than the current market price.
Let’s see it in a very simple example of how people (with direct market access) trade:
In the above image, we can see the cumulative volume across prices of both bid and ask; this is known as a depth chart of the order book, and has been generated from the limit orders placed by market makers. In this moment, the mid price is in between the best bid and the best ask prices, at a level of $54.96.
What happens next?
Market takers send market orders to the exchange, thus removing this liquidity.
For example, imagine there are two market orders arriving to our previous order book: a market order to sell and a market order to buy with volumes of 50 and 2 shares respectively. Common sense indicates that, in this case, price should decrease after executing the market orders because there’s more volume to be sold than volume to be bought.
After executing the market orders, everything else being equal, the new order book looks like this:
As we can see now, the bid is far less liquid now and the spread has broadened. As the sell volume was significantly larger, the spread has broadened downwards in price, which makes mid price change down to $54.92 from the previous $54.96.
Now imagine that the market orders were the same, but with the 50 shares for the buy order and the 2 shares to sell. The impact on the price changes a whole lot!
As we can see, the spread would broaden much more here, and the price increase is far larger than the previous price decrease. With the same volume being executed, the price increases now from $54.96 to $55.14, four times as much as before.
So the price movement of an asset doesn’t depend just on the arrival of market orders, but also in the structure of the order book i.e. on how liquidity is distributed across bid and ask prices. In this case, to achieve the same amount of volume executed (at market) you needed to trade at worse prices when buying than when selling, because market makers were willing to buy at prices closer to the mid price, but they were willing to sell at prices further away.
Of course, modern markets are not that simple and there are several types of orders and different, complex rules as to how orders are executed. Also, these rules change across exchanges and this mechanism works only when you’re trading through direct market access.
From the modelling point of view, the market is incredibly complex, as this operation is repeated thousands of times per second and market makers dynamically react to the arrival of market orders, trying to minimize their inventory risk (the directional risk of holding a net position in the asset) while trying to maximize their profits.
If you are interested in the way market makers dynamically change the orders they place, you might find this paper interesting, as an introduction to modern market making strategies.
An artificial market
Once we’ve explained market basics, let’s see if we can implement a simple artificial market that replicates the previous mechanism.
For this purpose, we implement two basic kinds of traders:
- Random market makers that place limit orders with an average spread (this is far from realistic but, hey, this is just a model).
- Random market takers that place random market orders.
With these two simple agents in the market, we retrieve what looks like a rather convincing price time series:
And returns look pretty decent too:
The volatility of our asset is 1.7% for an average market maker spread of 0.3 price units.
As we said before, price movements depend both in the order book structure, and market orders volumes and arrival times. Accordingly, an increase in market orders average volume, for the same level of liquidity, should increase volatility. Equivalently, with the same characteristics for market orders, decreasing the amount of liquidity provided by market makers will likely yield a more volatile price process.
To test this effect let’s increase the average spread of our market makers to 2 price units and check if we do see an increase in volatility levels.
As we can see in the previous graphs, volatility has indeed increased to a much higher 7%, and again, price and returns look convincing.
How convincing is enough?
But how convincing are they? Do they adapt to the basic market features of low autocorrelation and volatility clustering?
In order to test whether our artificial returns have these features or not, we can use an autocorrelation function. This statistic measures the independency of current values in the series with its past values.
In a real stock price, returns are serially independent (or very close), but the magnitude of those returns has a positive serial correlation, which is what we are going to check next:
Well, returns are fairly independent, but the ACF of the square of returns shouldn’t look like this. Rather, it should have a positive and decreasingly strong autocorrelation, indicating volatility clustering. (For an example of how it should look, check out this post).
We can conclude, then, that we cannot replicate one of the most well-known market features with just these two simple market participants. This isn’t surprising if we think that our artificial agents trade independently from what’s happening in the market.
For volatility clustering to be replicated, some kind of feedback should make market participants change the way they trade depending on what price or other processes (like news) are doing. We might include something like that for the next time… stay tuned!