1. Introduction
The study of a complex system has always been of great interest because of thier rich properties and behavior, for example, the solar system [
1] or biological systems [
2]. By analyzing such natural systems, people discovered fundamental laws that help them to build other systems, such as computer networks [
3] or power-grid systems [
4]. A financial market can also be considered as a complex system. For tens of years, researchers have been faced with the problem of the analysis and modeling of financial markets [
5,
6,
7]. One of the most important questions is “How can we develop an artificial stock trading system and describe investors’ behaviors in a way that is similar to reality?”. Previous models are based only on a single fully rational representative agent and fail to reproduce all the properties of real markets [
8,
9]. To overcome these problems, a new behavioral approach emerged, referred to as agent-based modeling, characterized by markets populated with bounded rational, heterogeneous agents [
10].
An agent-based model (ABM) in the financial market is a class of quantitative models to simulate the decisions and interactions of different traders in order to understand their behaviors and their impact on the market [
11]. In recent years, ABM in financial markets is still a prominent topic of interest for researchers [
6,
12]. The behavior of the agents is described in a variety of ways; their interaction and the impact of exogenous factors in the market are also introduced [
13]. Thereby, studies help managers to understand the behavioral characteristics of investors and explain the phenomena occurring in the stock market [
13,
14].
One of the problems of agent-based modeling is how to tune hyperparameters for the traders’ strategies and the market. Many models use large parameter sets and run simulations for long periods of time [
15,
16]. However, even for small models, exploring the stylized facts through all parameter combinations is not possible or is prohibitively costly [
12]. For example, in [
15], the authors generated 400,000 initial points to calibrate their model. To solve the above problems, this model introduces an approach with Bayesian optimization and an error measurement function to tune the hyperparameters of the environment.
In this work, we combine the main properties of the pioneer works. An agent-based model is introduced to highlight the stylized facts of the stock market. This research offers a novel perspective on how to detect the proportion of each trader in the stock market. The results can be used in selecting effective trading strategies for traders. The model consists of three types of traders: noise traders, technical traders, and fundamental traders, with various behaviors to increase diversity. A noise trader makes decisions based on price changes. They have different emotions and news reactions which play important roles in making decisions. Technical traders are diversified by trading indicators; they make different decisions based on target return and time. Fundamental traders are introduced to balance the market; they are diversified by their confidence level, which measures the convergence of the stock price to its fundamental value. The interaction is a function that combines the sentiment change when getting information from the market and the influence of other investors’ decisions.
The highlight of our model is that Bayesian optimization is introduced to tune the hyperparameters of trading strategies and the environment. The results show that Bayesian optimization can propose an optimal set of parameters and reduce simulation error. This provides stylized facts to compare with the real market, providing a bench-marking method for calibrating parameters of agent-based stock market. We used different methods of comparing the two distributions—Kullback–Leibler (KL) divergence and the Kolmogorov–Smirnov (KS) test—to measure the simulation error. In our model, the KS test showed better results by successfully explaining some important stylized facts in real stock markets, such as the leptokurtosis, the heavy tail of the returns, and the volatility clustering. With extensive simulations, we found that the fundamental traders accounted for 9%–11% of all traders in the stock market. These results are consistent with the real-market research [
17].
The remainder of this paper is organized as follows. The literature on ABM of stock markets is introduced in
Section 2.
Section 3 outlines the construction of the model.
Section 4 presents the description of the data and the calibration of model. Statistical analysis of the model’s results and the stylized facts are given in
Section 5. Finally,
Section 6 concludes and proposes some extensions of our work.
2. Background
In the financial market, there are many types of agents (investors, banks, central banks, etc.). These agents can interact directly through trading, exchanging derivatives. They can also interact indirectly, because any decision or behavior of an agent affects others [
18]. Moreover, the agents have different sensitivities to exogenous factors in the market and thus different news can influence and impact them [
19]. Therefore, financial market modeling needs to understand the characteristics of agents such as behavior and interaction between investors and the impact of exogenous factors such as public news on the market [
13,
20]. The studies in this paper will focus on clarifying these properties.
The first approach addresses the types of agents and how they impact the dynamics of the market. Pioneering works have proposed a number of interesting agent-based financial market models. The concept of zero-intelligence traders or noise traders who decide randomly whether to buy or sell was introduced in a double auction market [
21]. The studies of market participants using technical and fundamental analysis to assess financial markets creates a strong empirical foundation for building financial market models [
22]. Technical traders are considered to be a factor of instability because their trading often adds a positive response to the dynamics of the market [
23]. In contrast, fundamental analysis based on its definition provides a stabilizing impact on market dynamics [
24].
The second approach that should be considered is the diversity of agents. To make every fundamental agent and technical agent unique, they are assigned with different memory lengths or reaction intensities to price and fundamental changes [
13]. Exogenous factors such as news, social media, and insider information [
25] also have different impacts on each agent. In addition, the sentiments of agents such as risk aversion play an important role in the decision-making process [
14,
26].
The third approach is the interaction between agents. Besides the interactions that directly affect market prices, investors’ decisions also have an indirect effect on each other. In [
27,
28], the authors introduced the propagation in the decision of investors with a fixed probability. In another study [
13], the interactions and diversity among fundamental traders and technical traders were introduced. The average utility associated with each type was calculated and agents could rely on profit to come up with an effective investment strategy.
Each of these approaches has been extended in various interesting directions. From that, the stylized facts of financial markets are highlighted, such as heavy tails in stock return distribution and volatility clustering [
10,
28]. Another proposed stylized fact is the positive autocorrelation in volatility and trading volume [
13,
29].
One important issue is how to tune hyperparameters for traders’ strategies and the market. Grid search is a method to list all combinations of hyperparameters, then perform a model test with this list [
30]. Random search only randomly selects a finite number of hyperparameters from the list to conduct a model test [
31]. Theoretically, grid search can find the global value, but as the number of parameters increases, this becomes increasingly impossible due to the time and cost of implementation. Random search does not run as many cases as grid search, so it is significantly faster [
31]. However, depending on its randomness, each run will receive a different optimal value because it does not guarantee the optimum value to be global or local only. Bayesian optimization is an adaptive approach to parameter optimization, trading off between exploring new areas of the parameter space and exploiting historical information to find the parameters that maximize the function quickly [
30]. Thus, Bayesian optimization is introduced to tune hyperparameters for the trading strategies of technical traders and the environment of our model.
3. The Model
This section outlines the construction of a new agent-based model. This model adds the understanding of the reason for the stylized facts and the estimated proportion of traders in the stock market.
3.1. Environment
The agent-based model in this paper focuses on analyzing the behavior of traders and the log return properties which are reflected in the simulation process. The model considers a fixed amount of agents, denoted as
N, trading a single asset. The current time is denoted with
t and the corresponding price is
. At each time step
t, trader
i can choose between three actions: buy/sell one unit of the stock or hold,
, respectively. For liquidity purposes, the model assumes that every trader always has enough wealth and shares—in other words, they are always able to buy or sell. The market price and market return are then calculated. The market price
is updated according to
and return
is determined according to
where the excess demand
, the price impact function
, and
measures the market depth or liquidity.
Due to the tendency to form discrete clusters of traders [
32], we define different types of traders in this model based on their predefined trading rules. There are three different types of traders operating in the market. Noise traders are people who make decisions at random according to their news reactions and their propensity to sentiment contagion. Technical traders analyze charts and make decisions based on current patterns and trends analysis, and fundamental traders trade based on the fundamental profit-generating potential of the stock.
3.2. Noise Agent
Noise agents are traders who trade on the basis of misunderstanding information and news regarding future prices. They make decisions and trade based on inaccurate analysis of the market [
33]. In this model, noise agents rely only on the current market situation to make trading decisions: buy, sell, or hold [
13]. As the key variable, the sentiment of the noise agents implies their reaction to the news they get [
20]. Good sentiment means that agents see the news as good news and hope future prices will increase (bullish) and bad sentiment means that the agents consider the news to be bad and hope prices in the future will decrease (bearish).
The decision of noise agents is determined by the following process. At each time step t:
Agents receive public information as a signal .
Each agent i compares the signal to his threshold to make a decision.
After calculating the market return, he updates his threshold with a probability .
The inflow of news arrives to the market as a signal with . Each agent will decide whether the news is significant or not, in which case he will make a decision according to the sign of . To describe the heterogeneity, we introduce the sentiment of each agent to the news as a decision threshold with the initial trading threshold set between 1 and 2 times the standard deviation of the news, .
Let
denote the number of noise agents. The trading rule of each noise agent
is represented by
Market-related sentiments are formed differently for each agent and each responds differently to the information. To avoid the artificial ordering of agents as in sequential choice models, we follow [
20] to generate an asynchronous strategy to update the agents’ threshold. At each time step, each agent
i will update his threshold
with probability
. The threshold is set equal to the absolute return at time
t,
. Introducing independent and identically distributed random variables
uniformly distributed on [0, 1], the updating scheme is represented as
In the next addition to the model, technical agents and fundamental agents are introduced.
3.3. Technical Agent
Unlike the noise agents, technical agents are traders who use the past prices to infer private information. They make decisions by calculating the technical indicators from historical prices [
34]. The characteristic of technical analysis is to make decisions after identifying the trends at an early stage and reverse the decision when the trend reversal occurs [
35]. In this model, the agents are assumed to use a technique in the real world called a moving average-oscillator (MAO) to predict future price moves [
36]. The technique first involves taking two moving averages of the price, a short-term moving average
A and a long-term moving average
B, of different lengths
. The moving average crossover is calculated as the difference
between these two moving averages.
indicates that the price is trending upwards and the agents will make a buy.
indicates that price is trending down and the agents will sell the stock.
In order to account for individual heterogeneity, each agent can use different lengths of historical data, so one moving average strategy may indicate an uptrend while another moving average strategy indicates a downtrend. However, in our model, the difference in window lengths, and , has no effect on agents’ trading decision. When the historical stock price data has a strong uptrend or downtrend, all investors will make the same decision. Thus, we assume that all technical agents can use Bayesian optimization to estimate the optimal length for short and long windows.
We formulate an optimization problem with three main ingredients:
Domain space: The range of each hyperparameter is selected. Following the studies in [
37], our approach starts the domain from a wide range and then focuses on specific areas around the optimal parameters calculated from the previous run. Thus, each agent is assigned a random short window and long window derived from a random uniform distribution in [5, 40] and [50, 100], respectively.
Objective function: We define a score function that indicates how well a set of long-short periods performs. Cumulative returns and Sharpe ratio are usually used to indicate the performance of a technical strategy [
38]. In our model, the Sharpe ratio is used as the evaluation metric of choice. We put a minus sign before the objective function since Hyperopt by default is defining a function to minimize.
Surrogate function and selection function: The surrogate function is used to propose sets of values that increase performance in minimizing the score of the objective function. Then, they are selected by applying a criterion. In this model, we follow [
30] to use the tree Parzen estimator as the surrogate function. The expected improvement criterion is used as the selection function.
The optimal lengths for short and long windows with the largest Sharpe ratio are 35 and 51, respectively. The buy/sell signals are shown in
Figure 1.
To describe the heterogeneity, we introduce as the average profit a technical agent i gained in the previous trading day, , which is considered as a threshold to make a decision. Each agent i will update her threshold with probability at each time step t. The updating scheme is represented as in the description of noise agents.
Technical agents are also affected by the public information like the noise agents. The news reactions
are represented by
Define the sign function,
, as
Let
denote the total number of technical agents. The trading rule of the technical agent
is represented by
The amplification of trends and unlimited buying power of technical agents can cause problems because the price can grow to infinity or drop to extremely small values very quickly. Thus, fundamental agents are necessary to keep the market reasonably stable.
3.4. Fundamental Agent
Fundamental agents are traders who measure the intrinsic value by analyzing the accounting, finance, and economics of the stock [
39]. They make decisions with the belief that the stock price will return to its fundamental value in the long-run. The fundamental value of the stock
is public to all agents and is assumed to follow a random walk process
where the fundamental shocks
.
At each time step
t, fundamental agents make a decision based on the difference between
and
. Therefore, if the price is below (above) its fundamental value, the agents will make a buy (sell) order. This strategy shortens the difference between price and its fundamental value. They help to stabilize the market and cause the opposite effect on prices for technical agents. In order to account for individual heterogeneity, they are given heterogeneous beliefs about the fundamental price for more interesting dynamics [
40].
Let
denote the total number of fundamental agents. The trading rule of the fundamental agent
is represented by
where
is a positive coefficient that describes the speed of adjustment. The idiosyncratic term
embodies a random term that accounts for each individual’s own interpretation. We take it as being normally distributed around zero and with a standard deviation controlled by the user,
.
Finally, all agents are put together in the artificial financial market. This includes
noise agents,
technical agents, and
fundamental agents. The total number of traders is
N,
6. Discussion and Concluding Remarks
In this work we proposed a novel approach to calibrate hyperparameters in an agent-based model with different types of traders. The Bayesian calibration with Kolmogorov–Smirnov test proposed an optimal set of parameters. The model was able to highlight some of the important stylized facts of stock returns, such as the leptokurtosis, the heavy tail of the returns, and volatility clustering.
Our Bayesian approach is different from the recent studies on the calibration of ABMs applied to financial market [
12,
15,
16]. The calibration considers large parameter sets which can become quite a complex and costly operation. In particular, in [
15], the authors generated 400,000 initial points to calibrate their model. In [
12], the amount of data was reduced due to the high computational complexity of the Island model. Our approach is based on Bayesian rules and looks at previous experience to scale down the search space. Thus, the calibration requires less time and iterations to get the optimal hyperparameters. Moreover, the calibrated results showed that fundamental traders accounted for 9%–11% of all traders in the United States stock market. The proportion of traders in the stock market provides an additional indicator so that traders can come up with effective strategies.
Although Bayesian approaches provide several advantages, the complexity of the objective function could be a problem since it still has its own costs. In our model, the Sharpe ratio used as the objective function is very simple to calculate. However, if we want to consider a complex model with more types of investors and interactions between them, the dimension of domain space will increase. Optimal models require different settings between datasets, and with a high-dimensional space, the correlation between hyperparameters is difficult to study.
This work is only the first step toward fully assessing the properties of agent-based models in the United States stock market. In future research, the model in this research can be applied to other exchange such as the New York Stock Exchange or emerging markets in Asia. The different characteristics of the market and investors provide many interesting results for managers and investors. Moreover, deep learning is a good methodology for dealing with high-dimensional problems. Reinforcement learning can be considered to address Bayesian optimization issues [
42], in which our Bayesian approach can be used as a benchmark method for the comparison.