Bet against the trend and cash in profits: An agent-based model of endogenous fluctuations of exchange rates

This paper intends to contribute to the literature on the determinants of exchange rate fluctuations. We build an agent-based model inspired by the literature on behavioral finance and by empirical surveys about the behavior of foreign exchange professionals. In our artificial economy, traders allocate their wealth across heterogeneous assets based on expectations about exchange and interest rate fluctuations. Fundamentalists use both fundamental and technical signals, but overweight the former, while chartists only employ technical signals, and are either trend followers or trend contrarians. Each class of traders represents a fixed share of total traders. We find that the simultaneous co-existence of heterogeneous strategies can explain most stylized facts of foreign exchange markets, despite the absence of short-run switching from less to more profitable rules. Moreover, contrary to the predictions of the Market Selection Hypothesis, we find that heterogeneity of expectations is an essential requirement for traders’ profitability, as no class of traders can dominate the market profitably.


Introduction
The shift from macro to micro analysis and the emergence of the behavioral finance approach to exchange rates is rooted at the crossroads of different lines of research: the 1980's attempts to explain the pattern of the US dollar, the general criticism on the rational expectations hypothesis, and the strive to grasp the functioning of asset markets. These strands interconnected when, following Meese & Rogoff (1983), scholars highlighted a series of puzzling asset price patterns that previous models could not account for, namely: (i) the excess volatility of the exchange rate with respect to its fundamentals; (ii) the existence of sequences of booms, busts, and precarious equilibria (Schulmeister, 1987); (iii) the presence of clusters of volatility, with long periods of tranquility following long periods of large fluctuations; (iv) long memory in power transformations or in absolute values of asset price returns; and (v) fat tails in the distribution of asset price returns (Cont, 2007;Chen et al., 2012).
Much of today's focus on fundamentalist and chartist traders comes from Shiller (1981Shiller ( , 1990, who observed that fluctuations in stock markets were larger than news about dividends would predict, thereby calling attention to the work of "fads and fashion" in determining prices. The US dollar's path could thus be explained through the interaction of two types of agents: those who "think of the exchange rate according to a model" -the fundamentalists -and those who extrapolate past exchange rate changes -the chartists (Frankel & Froot, 1986, p. 24). The existence of chartists was confirmed empirically through phone interviews (Allen & Taylor, 1990) and empirical surveys identifying the existence of a multitude of traders using purely statistical models to extrapolate future predictions (Taylor & Allen, 1992). In the 1980s, chartists were clearly gaining weight in the market (Frankel & Froot, 1990), reflecting a "passionate obsession of foreign exchange professionals with technical analysis" (Menkhoff & Taylor, 2007, p. 954). Recent empirical works confirm their relevance in financial markets (Cheung et al., 2004;Gehrig & Menkhoff, 2005;Menkhoff & Taylor, 2007;Schulmeister, 2009b;Hsu et al., 2016). Frankel & Froot (1986) were thus able to explain price movements through the evolving weight of fundamentalists and chartists. A plausible explanation is that both chartists and fundamentalists can change strategy; but why would a smart manager, as in Scharfstein & Stein (1990), decide to go dumb? (Kirman, 1993). According to Kirman (1993), the change of forecasts results from a herd behavior, similarly to ants searching for food or humans deciding which restaurant to go to: the majority chooses one of the options, but constantly revises its opinion, failing to produce an equilibrium (also see Lux, 1995 andAlfarano et al., 2005). A second answer emerged out of the debate on whether heterogenous strategies could survive in the same market, or whether the market would eventually select the (unique) profit-maximizing strategy and kick out the others, according to the Market Selection Hypothesis (MSH) (Dutta & Radner, 1999). The MSH is inspired by Friedman (1953), who argued that businessmen not maximizing profits would hardly survive. Scholars questioned how chartists would survive if surveys among FX traders reveal that fundamentalists increasingly make use of hybrid strategies (Taylor & Allen, 1992;Frankel & Froot, 1987;Cheung et al., 2004;Gehrig & Menkhoff, 2006;Menkhoff & Taylor, 2007).
Our model is rooted in this theoretical and empirical stream of research. We portray a market with a constant share of fundamentalists and chartists. Contrarily to models in which fundamentalists resort to technical analysis under some specific circumstances (Hommes, 2006), or choose to be a fundamentalist when the price reaches "unreasonable" levels (Giardina & Bouchaud, 2003), in our model, fundamentalists process both technical and fundamental "predictions", but attach different weights to each of these, consistent with the FX market strategies reported in empirical surveys. Hence, in our model, fundamentalists do not switch between fundamental and technical rules, but rather balance the two signals: fundamental signals suggesting to close a position when the price is higher or lower than its fundamental value and technical signals suggesting to follow (or revert) the current trend based on purely statistical models. This facilitates the calibration of the model, as these surveys report the relative importance attributed by traders to each strategy and the share of respondents attributing more relevance to fundamentals rather than trends (those who attribute a larger predictive power to fundamentals are qualified as "fundamentalists", while traders who attribute a larger predictive power to trends are qualified as "chartists"). Because they trade on lower frequency, fundamentalists update forecasts less often than chartists, creating non-uniform reactions (see also Dacorogna et al., 2001) and exhibiting heterogenous memory as they have different degrees of anchoring of current expectations to past expectations, a feature that turns out to be important for explaining bandwagons (Schulmeister, 2009) and intraday movements (Cheung et al. 2004) 2 . Also, chartists exhibit heterogeneous memory, as reflected in their moving averages' length. Our model includes two other elements observed in FX markets and recognized as important for explaining trend reversals, namely cash in and contrarian trading (Schulmeister, 1988(Schulmeister, , 2009. The fact that traders cash in their gains as they hit a target return is a common practice in FX markets. It is also in line with theoretical and empirical findings on agents weighting losses more than gains (Kahneman and Tversky, 1991) and looking for satisficing -as opposed to optimal -outcomes under uncertainty (Simon, 1955(Simon, , 1978: if traders were able to predict the future, they would maximize profits by closing positions right before a trend's reversal -a timing that is however impossible to know, and failure to predict it might be extremely costly. Pursuing reasonable and satisficing targets, because of limited information and confidence in own expectations, is therefore rational. Contrarian trading consists instead of selling (buying) when trend followers would rather buy (sell). Its theoretical relevance is broadly recognized (Brock & Hommes, 1997;Chiarella & He, 2002;Sansone & Garofalo, 2007;Galariotis, 2014;Jacob Leal, 2015;Schmitt & Westerhoff, 2021). Moreover, empirical evidence identifies certain classes of traders as contrarians (Barber & Odean, 2000;Kumar & Lee, 2006;Kaniel et al., 2008). Namely, Drehmann et al. (2005) 1 3 Bet against the trend and cash in profits: An agent-based model… find experimental evidence of people buying an asset B when the price of asset A is high, even if private information and current trends suggest a further appreciation of this latter, for not trusting on other traders' rationality.
Our main result is that the simultaneous co-existence of heterogeneous rules provides a sufficient condition to explain most stylized facts of foreign exchange markets, without needing to introduce specific switching mechanisms. Moreover, all traders turn out to be profitable, contrary to MSH predictions, even in absence of ad-hoc profit-oriented switching rules. In other words, we show that heterogeneity is a necessary condition for traders' profitability: as soon as a single class of traders dominates the market, its profitability shrinks relative to the others. Hence, our model goes a step further with respect to existing contributions based on fixed strategies (neither Sansone & Garofalo, 2007nor Jacob Leal, 2015 investigate the relative profitability of the rules). An additional innovation of our model is that we combine the stock-flow consistent and the agent-based approaches, by explicitly tracking sectoral and individual balance sheets and the flows between them 3 . As flows and stocks are accounted for, traders allocate their limited wealth across heterogeneous assets, namely currencies and bonds, according to their expected profitability, such that the demand for assets is a product of traders' expectations and portfolio decisions. Moreover, by modeling bond markets and their interaction with the FX market, fundamentalists have endogenous exchange rate expectations. In the behavioral literature, fundamentalists' expectations are modeled as exogenous and stochastic (De Grauwe & Grimaldi, 2006;Manzan & Westerhoff, 2005), a marked oversimplification given exchange rate's influence on variables affecting fundamentals (De Grauwe & Kaltwasser, 2012). Despite the lack of consensus about the variables that govern exchange rate expectations, there is a general agreement on the influence of interest rates (Harvey, 2001;Kirman et al., 2007), as confirmed by traders' close monitoring of monetary policy announcements (Cheung et al. 2004;Müller et al., 2017). Given heterogeneous expectations and some inertia in updating expectations, we assume that fundamentalists form exchange rate forecasts based on expected interest rate differentials, consistent with the empirical evidence regarding the increased magnitude of cross-border portfolio assets and liabilities (from 43% of the world's GDP in 2001 to 76% in 2015; Camanho et al., 2018). Therefore, our model has a greater explanatory power relative to standard twoor three-agent models, which replicate the main financial markets' stylized facts efficiently, but do not allow explaining them appropriately. We highlight the importance of each class of traders to replicate these facts and offers theoretical support to the conclusion that heterogeneity is not simply a possibility but a necessity to explain profitability. Moreover, despite the lack of a comprehensive macroeconomic structure, our model provides several interconnections between markets and sectors, thereby allowing extensions to account for the macro foundations of agents' behaviors and explore the micro foundations of macroeconomic outcomes.
The remainder of the paper is organized as follows. In the next section, we present the model. In Section 3, we discuss the results and validate the model by showing that it replicates the main stylized facts of FX markets. In Section 4, we perform experiments on key parameters to identify the determinants of exchange rate cycles and traders' profitability. In Section 5, we conclude and discuss possible extensions.

A general overview
Our artificial economy contains two countries -A and B -and three institutional sectors in each country: households, governments, and central banks (Table 9). Each country has its own national currency, which the Central bank injects by purchasing a share of domestic treasury bonds at issuance. Since we abstract from firms' investments, bank loans, and central banks' open market operations, the central bank buying bonds is the only channel for money creation and the supply of liquid assets (currencies) 4 . The demand for domestic and foreign assets is determined by the number of traders who populate our artificial economies and speculate on the four existing assets, namely currency A, currency B, country A's government bonds, and country B's government bonds. Hence, there are three prices: the exchange rate between currencies A and B, the price of country A's bonds and the price of country B's bonds.
Traders have heterogeneous time horizons and therefore heterogeneous speculative strategies. More precisely, there are three trading rules. Trend-follower chartists follow the very simple and adaptive rule "the trend is your friend": if the price is increasing, they believe that it will keep increasing, and if the price is falling, they believe that it will keep falling. Trend-contrarian chartists do the opposite of trend-followers: if the market is bullish, they anticipate a sudden reversal and start closing their positions. Fundamentalists seek to speculate out of fluctuations of the market price around what they believe is the true, or fundamental price. For believing that prices cannot persist too long and too far from fundamentals, but still being aware that short to medium run market prices are also driven by chartist strategies, they follow a mixed strategy consisting of weighting both fundamental and technical signals, the former dominating the latter. As we stressed in the Introduction, these assumptions are inspired by empirical surveys showing that "fundamentalists" pay significant and increasing attention to signals produced by technical trading models. Moreover, fundamentalist traders seem to pay more attention to technical trading than chartist traders to fundamental analysis (See Gehrig & Menkhoff, 2005). As we will show, the interaction among these heterogeneous speculators who seek to make profits out of prices' fluctuations is able to generate endogenous and realistic fluctuations of the exchange rate and to replicate most of the stylized facts of FX markets.

The sequence of the model
Every period of the model corresponds to 1 day, and is composed of seven successive steps: 1. Governments spend and decide how many bonds to issue to finance the next period's desired expenditure. The government's expenditure finances social transfers to households. For simplicity, we assume that all households are traders and that they receive an equal amount of government benefits in each period. 2. Traders form their expectations about the evolution of asset prices, according to their own strategy, and decide how to allocate their wealth across the four different assets. After setting their portfolio choices, they decide whether to open, keep open, or close their positions in the markets, given the difference between the desired and the current amount they have of each asset. 3. The market for government bonds opens. Governments seek to sell new bonds at the current interest rate and traders seek to buy or sell bonds according to their portfolio choices. 4. The currency market opens. Traders exchange currencies according to the portfolio choices of step 2. 5. According and proportionately to the gap between demand and supply, the prices of assets increase (decrease) if the gap is positive (negative). 6. To reproduce intraday trading, steps 2 to 5 are simulated k = 3 times consecutively. 7. Global variables are updated.

The governments and the central banks
The government of country j issues treasury bonds that pay a face value set to 1 at 10 years of maturity 5 , such that the (endogenous) price P(B j ) t is an inverse function of the (endogenous) interest rate (i j t ): Treasury bonds issued at any period t in country j finance primarily desired public expenditure G j held constant for simplicity. From here on, the tilde above a variable will denote the desired level of a variable. Moreover, in order to avoid a lack of liquidity due to the inability to sell the desired amount of bonds at the current interest rate, the government owns deposits at the central bank (D j G ) and targets a fixed ratio of deposits to desired expenditure td j : (1) G is the desired amount of liquidity that the government deposits at the central bank. Hence, bonds issued by national governments finance both desired expenditure and liquidity targets: The central bank's desired demand for bonds is a fixed share cb j of government's desired expenditure: The desired amount of bonds that the government seeks to sell to the market is equal to the residual of the total desired amount of new bonds minus the desired share of bonds purchased by the central bank.
If the market is not willing to purchase the total amount of bonds at the current interest rate, the effective amount will be different from the desired If this difference is such that the government is unable to finance public expenditure with new liquidity, it will use its own liquidity deposited at the central bank to finance the residual. Nevertheless, if the government runs out of liquidity and is not able to finance current expenditure, the central bank steps in and buys the necessary amount of bonds to cover current expenditure. Hence, current expenditure is always equal to desired expenditure G j t =G j and the variation of government deposits will be equal to the effective amount of newly issued debt to the central bank and to households, minus government's current expenditure: and R j t the amount of undesired bonds purchased by the central bank, which is equal to 0 in normal times, and can take a positive value in the above-mentioned extreme case where the government runs out of liquidity and is unable to finance current expenditures 6 . (3) Bet against the trend and cash in profits: An agent-based model…

The traders
Each of the traders who populate countries A and B of our artificial economy owns a financial portfolio composed of all the four assets traded in the markets, namely currency A (M A ), currency B (M B ), country A's treasury bonds (B A ), and country B's treasury bonds (B B ). We define the exchange rate (Er t ) as the amount of currency A necessary to buy one unit of currency B (an increase of the exchange rate reflects an appreciation of currency B): Hence, traders' wealth is given by: W i, j, t is the wealth of trader i living in country j at time t. Hereafter, the subscripts refer to traders while the superscripts refer to assets. Hence, M A i, B, t denotes the amount of currency A held by trader i, who lives in country B, at time t. Because traders define their own portfolios in terms of their national currency, in what follows we will specify behavioral equations twice, for traders in country A and for traders in country B. For traders living in country j, the share of each asset in their own portfolio, represented by the vector (α i, j, t ;β i, j, t ; γ i, j, t ; Δ i, j, t ), is:

Open or expand a position
The vector (α i, j, t ;β i, j, t ; γ i, j, t ; Δ i, j, t ) is endogenous and determined by traders' expectations on asset price fluctuations, which drive their decisions to open, keep open, expand, or close a position. Namely, traders wish to increase the share of those assets that they expect to appreciate and wish to reduce the share of those assets that they expect to depreciate. Hence, they can either open a long position (buy an asset to sell it back at a hopefully higher price) or open a short position (sell an asset to buy it back at a hopefully lower price), if they expect, respectively, an increase or a fall in the asset's price (see Fig. 1). For example, if they expect a positive variation of the exchange rate (ΔEr t > 0) implying an appreciation of B (a depreciation of A), they can either go long (buying) by increasing the share of currency B or go short (selling) by decreasing the share of currency A. In our model, we treat traders' demand for domestic currency as an exogenous and stochastic variable. This allows us to capture and simulate the effect of changes to factors affecting traders' liquidity preference beyond speculative motives. Together with fundamentalists' expectations about fundamental prices (see Section 2.4.3), changes in liquidity preference are the only stochastic triggers in our model. Hence, in the foreign exchange market, traders open or expand a long position if they expect an appreciation of foreign currency, and they open or expand a short position if they expect a depreciation of foreign currency: short position (sell) if they expect the price of Z to fall and just wait if they expect that the price of Z will remain constant. At time t = 1, they keep expanding the long (short) position if positive (negative) expectations are confirmed, wait if they expect that the price will remain constant or close the long (short) position either if they expect a reversal of the trend or if the market price hits the target price. As of time t = 2, traders keep following these same sequential choices 1 3 Bet against the trend and cash in profits: An agent-based model… E i, t (ΔEr t + 1 ) is the expectation at time t of the variation of the exchange rate from to t to t + 1, ω er is a parameter defining the sensitivity of speculative demand for foreign currency to expected variations of the exchange rate, and ϵ i, j, t is a uniformly distributed shock reflecting cyclical changes to the demand for national currency, our exogenous variable.
The same mechanism applies to treasury bonds. If traders expect an appreciation (depreciation) of treasury bonds of country j, they can go long (short) on the treasury bonds market by increasing (reducing) the share of treasury bonds in their portfolio. Because price is inversely related to the (endogenous) interest rate (Eq. 1), traders in country j open or expand their positions on the treasury bonds market according to the expected variations of the interest rate: ω ir represents the sensitivity of speculative demand for treasury bonds to expected variations of the interest rate. Note that we do not let expectations on the exchange rate to affect the demand for bonds. The reason is that traders can speculate on both bonds and currencies, and that they exploit exchange rate fluctuations by varying their demand for currencies, rather than their demand for bonds. This assumption is consistent with a risk-minimizing approach: when closing a long position on foreign bonds, traders need to go to both markets, the bonds' market to sell foreign bonds against foreign currency, and the foreign exchange market to sell foreign currency against domestic currency. Hence, if they expect the foreign currency to appreciate, they prefer to buy foreign currency instead of foreign bonds, because they can close the position more quickly if they observe a reversal of the trend. For this reason, we shall make the simplifying assumption that demand and supply of bonds only depend on expected changes in the interest rate, while expected changes of the exchange rate affect in turn the demand of currencies.
By normalizing ( i,j,t ) such that they sum to 1, we can compute, for each trader, the desired share of each asset in her or his own portfolio, and derive his or her desired amount ( shares within (Eq. 10), given the assets' prices and the exchange rate. This ultimately allows computing, for each trader, the demand (supply) of each asset, which is equal to the difference between desired and current amount. Namely, in the treasury bonds market, the demand or supply of treasury bonds is equal to: Because traders cannot barter national (foreign) bonds against foreign (national) bonds, nor they can barter national (foreign) bonds against foreign (national) currency, the desired demand of bonds is limited by their liquidity. Moreover, transactions can take place at a non-market clearing price, therefore the actual shares of bonds can be different from the desired shares of bonds ex post. In this case, because the currency market takes place after the treasury bonds market (see Section 2.2), traders take account of the unsatisfied supply or demand of treasury bonds when trading in the FX market, such that: Equation (14) tells that traders demand the exact amount of currency that is necessary to buy the desired bonds and simultaneously hold the desired share of currency in the portfolio. Because traders cannot sell assets that they do not hold, and because they are liquidity-constrained, it follows that the desired demand and supply of currency can be different from the actual demand or supply ex post.

Wait or close a position
As shown in Fig. 1, traders open or keep expanding a long (short) position if they expect that the price of an asset is going to increase (decrease). After opening a position in a market, they either wait if they are not confident about their expectations of market price evolution, or they close the position if they are sufficiently confident that the trend is going to reverse 7 . Traders can also decide to close a position before the reversal of the trend, because they enjoy realizing "what have been up to now only paper profits" (Harvey, 2009, p. 53, italics added). In practice, when opening a position, traders usually set an ex-ante price target such that if the market price hits this target, they automatically send an exit order. As stressed in the Introduction, this hypothesis is consistent with behavioral findings and represents a common practice in financial markets. We thus assume that traders fix a target price ∼ p Z j when they Bet against the trend and cash in profits: An agent-based model… open a position on asset Z j , based on the desired profit margin ψ i, j , and if the market price hits the target price, they automatically close the position: ψ i, j is constant and heterogeneous across traders and follows the same uniform distribution U(0, ψ + ). To close a position, traders set the desired share of the asset at the initial and exogenous level prior to opening the position. Namely, for each trader in country j: λ and μ are positive and constants, equal for all traders for simplicity. To close a position, traders follow equations (13) and (14) and sell (or buy) the amount necessary to reach the desired share of assets.

Trading rules and expectations
We consider three different trading rules, hence three different types of traders: chartist trend followers, chartists trend contrarians, and fundamentalists. The share of fundamentalists on the whole population is equal to the parameter f, while the share of chartists traders is equal to (1 -f). Out of chartists traders, the share of trend contrarians is equal to the parameter c, and the share of trend followers is equal to (1-c). Hence, if the total number of traders is equal to N, the number of fundamentalist traders is equal to (f*N), the number of chartists trend contrarian is equal to (1 -f)*c*N and the number of chartists trend follower is equal to (1 -f)*(1 -c)*N. As already stressed in the Introduction, we assume that the share of each type of traders over the whole population of traders remains constant over time (although we perform a sensitivity analysis on both f and c). This choice reflects the results of empirical surveys showing that trading strategies reflect traders' time preference and institutional role. Namely, while private traders speculate over short horizons and rely almost exclusively on technical signals, investment funds' managers speculate over medium to long horizons and mostly rely on fundamental signals, despite keeping an eye also on technical signals (Gehrig & Menkhoff, 2005;Dick & Menkhoff, 2013).
Trend-follower chartists Trend-follower chartists are speculators who seek to exploit short to medium run fluctuations. Their strategy consists of buying when the price is increasing and selling when the price is decreasing, according to the rule "the trend is your friend". These traders have bandwagon expectations, as Frankel & Froot (1990) would put it. Hence, they open positions when asset prices have a welldefined positive or negative trend and bet that this trend is going to persist, whereby a well-defined trend is a positive or negative trend that is larger than the individual thresholds i Z (Cont, 2007). Hence, the parameter s i Z captures a measure of confidence in their own expectations or risk aversion: traders with a lower s i Z enter relatively faster, because they are relatively confident that the expected positive or negative trend is going to persist. Traders with a larger s i Z , on the other hand, will wait relatively longer before opening a position because they are relatively less confident about their own expectations about the trend. The presence of s i Z therefore creates a band within which the exchange rate can fluctuate without generating buy or sell signals, preventing whiplash signals (Brock et al., 1992). Their trading strategy follows the empirically observed moving average model (Brock et al., 1992;Schulmeister, 2008Schulmeister, , 2009b. If the difference between the moving average of market price in the latest m days and the moving average of market price in the latest n days, MA i , with m<n, is positive (negative)  E i, t (ΔP(Z) t + 1 ) is the expected future price variation of asset Z and P(Z) t − k is the price of asset Z at a certain past date (t-k). Trend followers have heterogeneous trends (m i , n i ) and thresholds (s i Z ). Namely, we assume uniform distributions such that m i~U (m − , m + ), n i~U (n − , n + ) and s i Z~U (0, s Z, + ). The calibration follows the empirical work of Brock et al. (1992) and Schulmeister (2008) (see Appendix 1).

Trend-contrarian chartists
Trend-contrarian traders, or contrarians, are chartists going against the trend (Brock & Hommes, 1998;Chiarella & He, 2002;Sansone & Garofalo, 2007;Chen et al., 2012;Galariotis, 2014;Jacob Leal, 2015). Their strategy consists of selling when the price is increasing (because they expect a sudden fall) and buying when the price is decreasing (because they expect a sudden increase). They also follow the empirically observed moving average model (Brock et al., 1992;Schulmeister, 2008), but invert the signal with respect to trend followers: if the difference between the moving average of market price in the latest m days and the moving average of market price in the latest n days is positive (negative), reflecting a positive (negative) price trend, they sell (buy). Formally: Bet against the trend and cash in profits: An agent-based model… As for trend followers, n i , m i and s i Z are uniformly distributed and follow the empirical work of Brock et al. (1992) and Schulmeister (2008) (see Appendix 1).
Fundamentalists As stressed in the Introduction, fundamentalists believe that the price cannot fluctuate too far and for too long from its fundamental value, but they are also aware that technical signals have short-term effects on asset prices, and that they can make profits out of short-run fluctuations. Their strategy can thus be formalized as a weighted average of fundamental and technical signals: the fundamental signal suggests to go long (short) on asset Z if the price of Z is higher (lower) than its fundamental price, while the technical signal suggests to go long (short) on asset Z if the price of asset Z is raising (falling). Formally: FA i is the expected price variation according to fundamental analysis, whereby E i, t (P f (Z) t + 1 ) is the expected future fundamental price of asset Z, ζ i ̴ ~U(0, ζ + ) is a coefficient that reflects the expected speed of adjustment of the current market price to the fundamental price and ξ i is a coefficient that reflects the weight of technical trading in fundamentalists' expectations. The reference threshold s i Z follows a uniform distribution, such that s i Z~U (0, s f, + ), while ξ i~U (0, ξ + ). As mentioned, assets Z can be either treasury bonds or currencies. Therefore, E i, t (P f (Z) t + 1 ) represents either the expected exchange rate or the expected interest rate of treasury bonds. Fundamentalists' exchange rate expectations are centered on the treasury bonds' market, as a change in the interest rate differential of the two countries can trigger financial flows, affecting exchange rates. Interest rate expectations, in turn, depend on common information received by the market. The forecasted value however varies among traders, as they anchor expectations to their prior forecasts with different degrees. Moreover, because fundamentals are relatively stable, news affecting the fundamental value arrives with probability π < 1. In both countries A and B, expectations concerning interest rates are thus given by: The parameter τ reflects the degree of anchoring of current information to the past fundamental value and follows a uniform distribution with τ i~U (τ − , τ + ). News affecting the fundamental interest rate follows a stochastic process around a center of gravity j , which captures the structural determinants of the fundamental interest rate, and a stochastic noise ε j t . The process j 1 + | | j t | | may thus be thought of as a formalization of announcements related to monetary policies, or to other macroeconomic shocks that can affect interest rates but that we model for simplicity as a stochastic process. By assuming that the fundamental interest rates of countries A and B co-move, the stochastic noise ε j t is equal to: with ω A t ~N(0, 0.3) and ω B t ~N(0, 0.05) When building their expectations concerning the fundamental exchange rates (Er f ), fundamentalists take information related to the fundamental interest rate differential in the two countries (i f, B /i f, A − 1) 8 . The sensitivity of fundamental exchange rate fluctuations to fundamental interest rates fluctuations is given by ρ i~U (0, ρ + ). Current expectations are anchored to a fixed center of gravity, Er f -which can also be thought of as a formalization of (exogenous) macroeconomic, structural determinants of the exchange rate that we do not model explicitly, and take as a givenaccording to the parameter τ, which follows the same distribution as in the treasury bond market:

Trading
Based on price expectations, traders allocate their wealth across currencies and bonds. First, they go to the treasury bond market (see also Section 2.2), whereby The rationale is the following: if fundamentalists expect that the fundamental interest rate of country B will increase above the fundamental exchange rate of country A, they expect capital flowing from country A to country B, leading to a higher demand of currency B and an increase in the exchange rate.
governments sell newly issued bonds, and trade on both the primary and secondary markets. Each trader selects, randomly and sequentially, all traders who are willing to trade domestic (foreign) treasury bonds against domestic (foreign) currency, until his or her demand or supply of treasury bonds is exhausted, or until there are no traders left. Next, they go into the FX market and trade currency B against currency A following the same sequential random pairing. Because transactions can take place at a non-market-clearing price, some traders might end up with an undesired portfolio composition. Therefore, ex-post positive or negative gaps between demand and supply lead to a higher interest rate (hence, a lower price) if the supply of treasury bonds is higher than demand, or a lower interest rate (hence, a higher price) if the supply of treasury bonds is lower than demand. This process depends entirely on the gap between demand and supply (DSG Bonds, j ): The same applies to the foreign exchange market. Ex-post positive or negative gaps between demand and supply (DSG Er ) lead to a higher exchange rate (appreciation of currency B) if demand for currency B is higher than supply, or to a lower exchange rate (depreciation of currency B) if supply of currency B is higher than demand:

Booms, busts, and precarious equilibria
We run the model for 4000 periods, which correspond to 4000 artificial trading days, using the baseline parameters calibrated to obtain reasonable and realistic values (see Table 8), and discard the first 1000 periods to eliminate initial fluctuations caused by the initial values, which are set arbitrarily and consistently with (23) stock-flow consistent norms (see Table 9) 9 . The only exogenous stochastic shocks in the model are shocks in the demand for national currency (Section 2.4.1) and in the expectations about fundamental interest rates (Section 2.4.3.3). Figure 2 shows that the artificial exchange rate and the artificial interest rates follow short to long cycles, characterized by slowly increasing or decreasing trends and sudden reversals. Moreover, fluctuations are characterized by sustained periods of tranquility alternating with sustained periods of volatility, generating clusters of volatility affecting all markets simultaneously: periods of tranquility in the treasury bonds market are associated with periods of tranquility in the FOREX, and periods of volatility in the treasury bonds markets are associated with periods of volatility in the FOREX.
This multiplicity of dynamics reflects the existence of alternative strategies and generates alternative sources of profitability: trend-contrarians exploit the reversal of trends; trend followers exploit the continuation of trends; fundamentalists exploit the long-run tendencies to the fundamental price.
Cycles start in the treasury bond market when fundamentalists receive and process news about changes in the fundamental interest rate (see Fig. 3). When the interest rate is below what fundamentalists believe is the fundamental interest rate, they open short positions and generate an upward cycle in the interest rate. If the expected fundamental interest rates of one of the two countries diverge, changing the fundamental interest rates differential away from the previously expected level, the fundamental exchange rate also moves away from its previous trend (according to Eq. 22). Trend followers detect the upward cycle in both treasury bond markets and the FOREX (foreign exchange) market and keep fueling it, while trend contrarians create some short run noise. When market prices rise above their expected fundamental anchor, fundamentalists start closing their positions and slow down the cycle, which is still fueled by trend followers and trend contrarians, until they realize that the trend is about to revert or has already reverted. Consequently, the exchange rate and the interest rates of countries A and B, although constantly attracted by their fundamental price, display a much larger volatility than this latter, giving rise to booms, busts, and precarious equilibria (Schulmeister, 1987).
Conflicting portfolio choices of traders contribute to reinforce these dynamics. Figure 4 shows the portfolio choices of traders in relation to market prices dynamics (exchange and interest rates). The market for treasury bonds B is relatively stable until period 1420 (bottom left chart), when the desired share of treasury bonds B sharply increases, generating an upward cycle (upper left chart) that lasts shortly beyond period 1500. Consequently, the interest rate on treasury bonds B goes down while the exchange rate goes up (bottom right) because of the increasing demand of currency B to finance the increasing desired share of treasury bonds B (although the desired share of currency B is stable).
In period 1500, the fundamentalists expect an increase in the interest rate of bonds A beyond the interest rate on bonds B, leading to a fall in the expected fundamental exchange rate (see Eq. 22). Consequently, they go short currency B and long currency A. Moreover, because the desired share of bonds B is rapidly falling, they also go short on bonds B, by creating a further pressure on the exchange rate due to the expected increased availability of currency B. Consequently, the exchange rate rapidly converges to the new fundamental value. Shortly after period 1700, fundamentalists expect a large fundamental shock on both treasury bonds A and B, such that the expected fundamental exchange rate increases. Traders should thus go short on A and long on B by generating a sudden increase in the interest rate. However, the shock on the treasury bonds market also generates a sudden fall in the desired share of bonds B that finances the increased demand of currency B without need to go short on currency A. Consequently, the exchange rate keeps fluctuating below the new fundamental rate for few days until a sudden fall in the desired share of bonds A generates an increased availability of currency A that creates an upward pressure on the exchange rate, which overshoots its expected fundamental rate.
At this point, the exchange rate should decrease under the pressure of fundamentalists traders who consider it overpriced with respect to the fundamental value. Nevertheless, the desired share of bonds A keeps falling rapidly, by producing, conversely, a sustained increase in the desired share of bonds and currency B. This keeps the exchange rate over-appreciated due to both the large demand of currency B (produced by the bandwagon effect of chartist traders who keep going long on currency B) and the large demand of bonds B (produced by the bandwagon effect of chartist traders who keep going long on bonds B). This precarious equilibrium also affects the bond market, in particular bonds B, as the interest rate fluctuates persistently below the fundamental interest rate, given the conflicting upward pressure of the positive gap between the fundamental and the current interest rate, and the downward pressure of the increasing demand of bonds B generated by chartists' bandwagon effect. In period 1850, as a new fundamental shock moves the fundamental exchange rate upwards and the fundamental interest rates downward, market prices finally converge to their fundamental values.

Heterogeneous strategies vs. market selection hypothesis
According to the market selection hypothesis (hereafter MSH), heterogeneous strategies cannot coexist in the same market, since the most profitable strategy -which is the fundamentalists' strategy consistent with rational expectations -would eventually kick the less profitable strategies out of the market. Theoretical and empirical studies reject the MSH by proving that, contrarily to conventional wisdom, financial speculators would be able to make consistent profits in real markets by using purely statistical, technical trading strategies (Brock et al., 1992;Dutta & Radner, 1999;Hsu et al., 2016;Bottazzi et al., 2018). This result is consistent with empirical surveys showing the simultaneous co-existence of heterogeneous trading rules within the same markets, which reflects heterogeneous time horizons and heterogeneous propensities to risk (Taylor & Allen, 1992;Cheung et al., 2004;Gehrig & Menkhoff, 2005;Menkhoff & Taylor, 2007;Dick & Menkhoff, 2013). Our findings are in line with these studies.
By computing daily returns as the average rate of change of wealth for each class of agents (followers, contrarians, and fundamentalists) we can compare profitability across the different types of agents. As shown in Fig. 5, there are no significant differences in terms of average profitability, although there is a substantial difference in terms of the variance of returns. Indeed, all trading strategies have comparable means and median, although contrarians display a slightly positive mean (the dot) and slightly negative median (the grey band) while followers display a slightly negative mean but Fundamentalists display a zero mean and zero median. This result clearly contrasts with the MSH, which predicts that fundamentalists prosper and force chartists out of the market. Moreover, the three strategies display substantially different variances: the contrarian strategy implies a larger variance, with both strongly positive and strongly negative returns; the trend-follower strategy, on the other hand, allows reducing the variance by reducing both losses and gains; the fundamentalist strategy allows reducing variance even further. Furthermore, this heterogeneity in terms of risk attitude reflects heterogeneity in time horizons, as also revealed by empirical surveys.
As shown in Fig. 6, the contrarian's short-run focus results in them constantly trading (more frequently opening and closing positions) as opposed to fundamentalists, the quietest in the market. Once more, our artificial results confirm surveys' findings that heterogeneous strategies reflect heterogeneous attitudes to risk and heterogeneous time horizons.

Long memory, fat tails, and clusters of volatility
To validate our model, we compare the statistical properties of our artificial series of the exchange rate with the statistical properties of the corresponding empirical series. Note that we do not aim to calibrate the model in order to provide the best fit with empirical series, we simply aim at validating the model by proving that the qualitative results produced are empirically sound. Financial markets are characterized by six main statistical properties or stylized facts (Sansone & Garofalo, 2007;Cont, 2007;Chen et al., 2012). Namely, the exchange rate (i) is more volatile than its fundamental value and (ii) follows a cyclical dynamic characterized by booms, crashes, and periods of precarious equilibria (Schulmeister, 1987). Exchange rate returns (iii) are uncorrelated, (iv) cluster together, alternating periods of high volatility with periods of low volatility and (v) their distribution displays heavier tails than the Gaussian distribution. Absolute returns, on the other hand, (vi) are highly correlated and their autocorrelation function decays slowly, exhibiting long memory. The graphical inspection of our results suggests that the model is able to reproduce most of these facts.
The excess volatility of market prices with respect to fundamentals, as well as the sequence of booms, busts, and precarious equilibria, emerges from Fig. 3, which plots the exchange rate and the interest rates against their fundamental values. Moreover,  Fig. 7 shows that the model is also able to replicate the other stylized facts (Figs. 13, 14 and 15 of Appendix 2 report the same graphical inspection with the empirical series from the main FX markets: US dollar, Euro, Canadian dollar, Australian dollar, and UK pound). Namely, exchange rate returns tend to cluster together, alternating sustained periods of high volatility and sustained periods of tranquility (upper-left chart). Volatility clustering is also captured by the exponentially decaying autocorrelation function of absolute returns (upper right chart) 10 , which reflects the well-known asset prices' property of long memory, as opposed to raw returns that are serially uncorrelated, as reflected by their white noise autocorrelation function (bottom-right chart). Finally, by comparing the quantiles of the distribution of returns in our simulated series with the quantiles of a Gaussian distribution, we can observe that the distribution of artificial returns is significantly leptokurtic, thereby exhibiting fat tails (bottom-left chart).
To confirm the graphical analysis, we compute some typical indices capturing these statistical properties in our artificial series and in the four biggest foreign exchange markets: the US dollar-Euro market, the US dollar-Canadian dollar market, the US dollar-Australian dollar market and the US dollar-UK pound market. To measure the length of memory, we estimate the exponential function that fits the most the autocorrelation function of absolute exchange rate returns (upper-right chart of Fig. 7): Whereby σ t, t − 1 − j is the autocorrelation of absolute residuals at lag j, β and λ are the intercept and the pace of decaying of the exponential function and ε j are the residuals. Therefore, the vector (β * , λ * ) that minimizes the sum of the squared residuals captures the long-memory of absolute residuals. To measure the heaviness of tails (bottom-left chart of Fig. 7), we estimate the index of excess kurtosis of the distribution of exchange rate returns: a heavily tailed distribution exhibits a value of excess kurtosis (the difference between actual kurtosis and the value of kurtosis of a Gaussian distribution) larger than 0 11 . We finally compute the mean, standard deviation, and skewness of exchange rate returns to capture general properties of the distribution of returns. Table 1 shows that the average values of our artificial indices, computed using Monte Carlo simulations of our baseline model, are consistent with the empirical indices (see also Appendix 2): Table 1 reports the estimated parameters of the exponentially decaying function of absolute exchange rate returns and the first four moments of the distribution of returns, comparing a representative simulation of the model using baseline parameters (DEXAB_B), the Monte Carlo average using the baseline parameters (DEXAB_ MC), the US dollar-Euro exchange rate (USDEUR), the Canadian-US dollar exchange rate (CADUSD), the Australian-US dollar exchange rate (AUDUSD) and the US dollar-UK pound exchange rate (USDGBP). Source: Federal Reserve Bank of Saint Louis, Economic Research Division.

Experiments and sensitivity analysis
To explore the properties of the model and gain insight on the role of technical trading, we analyze the relationship between exchange rate's statistical properties (excess volatility relative to fundamentals, fat tails and clusters of volatility) and traders' profitability relative to the composition of traders (parameters f and c) and the weight given by fundamentalists to technical trading (the parameter ξ + ).
To test the impact on excess volatility, we first focus on the variance of the exchange rate gap, which is the difference between the current exchange rate and the average of fundamentalists' expected fundamental exchange rate. This indicator provides a measure of dispersion of the exchange rate from its fundamental anchor. Next, we include, in our analysis, an indicator of the average time spent, on average, by the exchange rate above or below the fundamental equilibrium, computed using the Wald-Wolfowitz runs test. More precisely, we assign a "+" to periods in which the exchange rate is above the (expected) fundamental exchange rate, and a "-" to periods in which the exchange rate is below the (expected) fundamental exchange rate. Then, we compute the number of sequences, or runs, of adjacent "+" or "-", counting how many times the exchange rate and its expected fundamental value were the same. Therefore, each sequence identifies the number of periods between the moment the exchange rate crosses the fundamental exchange rate, such that the lower (higher) the number of sequences, the longer (shorter), on average, the time spent above or below the fundamental exchange rate. By using both indicators -the variance and the number of runs -we distinguish the size effects (variance; σ 2 in Table 2) from the persistence effects (number of runs; "# of Runs" in Table 2): while an increase in variance reflects the noise around the fundamental exchange rate, the number of runs reflect the attraction force of the fundamental exchange rate. In other words, the number of runs allows capturing the persistence and frequency of precarious equilibria, not necessarily the size of the gap between the current exchange rate and the fundamental exchange rate, which the variance captures more efficiently.
To test the impact on the tails of the distribution and on volatility clustering, we use standard indicators: the index of kurtosis of exchange rate returns to identify heavy tails, and the estimated coefficients of the exponentially decaying function (23) to identify the persistence of the autocorrelation function of absolute exchange rate returns, respectively, "ACF returns" and "Fat tails" in Table 3. Table 2 Traders' composition and the exchange rate gap All values represent the average across 20 simulations with 20 random seeds, relative to the baseline scenario. The values in parenthesis represent the p value of the t test relative to the baseline scenario. Hence, a low p value suggests that the estimated parameter is significantly different from the baseline. *p < 0.1, **p < 0.05, ***p < 0.01. To test the impact on traders' profitability, we focus on the distributional properties of returns for each class of traders, namely the 1st decile, the 1st quartile, the 3rd quartile, and the 9th decile of the distribution. We thus consider the inter-quartile and the inter-decile spreads to capture, respectively, the symmetry of returns around the median and extreme returns. For instance, positive spreads reflect a distribution skewed towards positive returns, while negative spreads reflect a distribution skewed towards negative returns. Moreover, an increase in the absolute value of the spreads reflects an increasing dispersion of returns, therefore larger risks and larger premiums from speculation. On the other hand, a decrease in the absolute value of the spreads reflects a decreasing dispersion of returns, therefore lower risks but also lower premiums from speculation.

Traders' composition
We start by varying the composition of fundamentalists (by assigning the values 0.1, 0.3, 0.5, 0.7, and 0.9 to the parameter f) while setting a constant proportion of trend followers relative to trend contrarians (at the baseline value c = 0.5). Next, we vary the proportion of trend followers relative to trend contrarians (by assigning the values 0.1, 0.3, 0.5, 0.7, and 0.9 to the parameter c), while maintaining the share of fundamentalists at the baseline value (f = 0.7).

Exchange rate stability
As shown in Table 2, when the share of fundamentalists increases relative to the share of chartists, the variance of the exchange rate drops and the number of runs increases Table 3 Traders' composition, fat tails, and clusters of volatility All values represent the average across 20 simulations with 20 random seeds. The values in parenthesis represent the p value of the t test relatively to the baseline scenario. Hence, a low p value suggests that the estimated parameter is significantly different from the baseline. *p < 0.1, **p < 0.05, ***p < 0.01.
Fundamentalists' share 0,1 0,3 0,5 0,7 0,9 significantly, suggesting that the expected fundamental exchange rate becomes a stronger attractor for the current exchange rate. We find the same dynamics when we increase the share of contrarians from 10 to 90%: the variance of the exchange rate drops, and the number of runs increases significantly. These results suggest that contrarian and fundamentalist traders play a complementary role, by increasing the attraction force of the fundamental exchange rate. We thus confirm the result by Jacob Leal (2015) about the stability potential of contrarian traders, although we focus on the exchange rate gap instead of the ratio of the exchange rate volatility over the fundamental exchange rate volatility. Nevertheless, contrary to Jacob Leal (2015), we are able to analyze both the distance from the fundamental exchange rate (the variance) and the persistence of precarious equilibria (the number of runs). We can thus conclude that chartist traders -contrarians, particularly -do not just amplify the fluctuations around the fundamental rate, but also produce precarious equilibria by amplifying the time spent below or above the fundamental rate.

Fat tails and clusters of volatility
While we do not find significant effects on the index of kurtosis when we vary the composition of traders between fundamentalists and chartists, we find a significant effect on the emergence of clusters of volatility, especially at very low shares of fundamentalist traders. As shown in Table 3, for a share of fundamentalists equal to 10%, the autocorrelation of absolute returns is significantly larger during the first 100 lags with respect to the baseline scenario. This result suggests that chartists can amplify the persistence of absolute returns although they do not necessarily generate it, as fundamentalist-dominated financial markets also generate significant clusters of volatility (see Fig. 8). Contrarians, on the other hand, seem to play a major role on generating clusters of volatility: when the share of contrarian traders falls, the degree of persistence of absolute returns drops significantly, suggesting that they generate and amplify volatility clusters (see Fig. 8).

Distribution of returns
Changes in the composition of traders also have significant impacts on their profitability. As we see in Fig. 9, as the share of fundamentalists increases, the distribution of returns becomes less dispersed for all traders, meaning that returns are more similar inside each category. This is consistent with the observed drop in the exchange rate that we observed at the beginning of this section.
It is however interesting to note that not all types of traders are affected equally. While the distribution of chartists' returns is relatively unaffected at low and increasing shares of fundamentalist, and mildly changes as fundamentalists become the dominant trading class, the dispersion of returns for fundamentalists drops dramatically. Moreover, fundamentalists' extreme positive returns fall faster than extreme negative returns, as suggested by the significant fall in both the inter-quantile and the inter-deciles spreads (Table 4). For instance, a decrease in the inter-quartile and in the inter-decile spreads reflects an asymmetric dispersion of returns towards the negative side of the distribution: while the interquartile spread captures the distribution of returns closer to the median, the inter-decile spread captures the extreme returns, either negative or positive.
The same applies when we vary the share of contrarians out of chartists: as the share of contrarians increases, the exchange rate gap shrinks, such that returns' volatility decreases significantly for all traders (Fig. 10). Nevertheless, contrarian returns' volatility falls significantly faster, with positive returns (the 9th decile and the 3rd quartile) decreasing faster than negative returns (1st decile and 1st quartile), such that the inter-decile and the inter-quartile spreads go down (Table 4).
Hence, in a virtual fundamentalist world, fundamentalist traders make very little profits. Moreover, the likelihood of extreme negative returns increases while the likelihood of extreme positive returns decreases, thereby compromising any interest from speculation. The reason is that fundamentalists make profits out of the equilibrium by betting on a return to equilibrium. Therefore, if the exchange rate is too stable around the fundamental equilibrium, as shown earlier in this section, there is Fig. 9 Fundamentalists' share and distribution of returns. 1st decile (10%), 1st quartile (25%), 3rd quartile (75%) and 9th decile (90%) of returns' distribution for each class of traders. Note: all series represent the average across 20 simulations with 20 random seeds no room for speculation. Similarly, in a virtual contrarian world, contrarian traders lose much of the interest in speculation, as returns' volatility drops down, with positive returns decreasing faster than negative returns. The reason is that contrarian traders make profits during upward or downward cycles as these trends revert, but in a world of contrarians and fundamentalists only, the exchange rate is too stable to create opportunities for speculation.
These results indicate that the co-existence of heterogeneous traders is not only an empirically observed feature of financial markets but also a necessary condition for their profitability and existence, as well as a sufficient condition to generate empirically sound exchange rate fluctuations. As a corollary, financial markets cannot be reduced to systems dominated by a representative class of agents: in fundamentalist-dominated or contrarian-dominated financial markets, there are no returns and therefore no gains from speculation for the dominant class. Table 4 Traders' composition and the inter-quantile and inter-decile spreads All values represent the average across 20 simulations with 20 random seeds, relatively to the baseline scenario. The values in parenthesis represent the p value of the t test relatively to the baseline scenario. Hence, a low p value suggests that the estimated parameter is significantly different from the baseline. *p < 0.1, **p < 0.05, ***p < 0.01.

Fundamentalists' weight to technical trading
Lastly, we test the effect of the "obstinate passion for technical trading" (Menkhoff & Taylor, 2007) by increasing the weight of technical trading in fundamentalists' expectations (Eq. 19). Specifically, we vary ξ + from 10% to 90%, while keeping all other parameters fixed at their baseline values.

Exchange rate stability
One of the main contributions of fundamentalists' attention to technical trading is to destabilize the exchange rate from its fundamental anchor. As shown in Table 5, excess exchange rate volatility (σ 2 ) increases sharply and significantly as fundamentalists attach an increasing importance to technical trading. Simultaneously, the  number of runs drops, suggesting longer exchange rate fluctuations above or below its fundamental value (maintaining precarious equilibria): Note, however, that the impact on the volatility of the exchange rate gap of an increasing focus on technical trading (ξ + ) is stronger than that of an increasing share of chartist traders, while the impact on the number of runs is stronger when the proportion of chartist traders increases (compare with Table 2 in Section 4.1.1). This suggests that an increase in fundamentalists' attention to technical trading is mainly responsible for generating noise in the exchange rate gap, while an increase in the share of technical traders mainly affects the gravitation force of the fundamental exchange rate.

Fat tails and clusters of volatility
As shown in Table 6, we also find a significant impact on volatility clustering: the more fundamentalists weight technical trading, the higher the intercept (β * ) and the persistence (λ * ) of the ACF.
Nevertheless, as shown in Fig. 11, the autocorrelation function at high levels of ξ + is still larger than the autocorrelation function at low levels of ξ + , suggesting that the positive level effect on β * more than compensates the negative persistence effect on λ * . We expected this result: an increase in the weight given to technical trading has a similar impact than an increase in the share of trend followers, thereby raising absolute exchange rate volatility, as shown in Section 4.1.2.

Distribution of returns
Finally, we find that an increase in the weight of technical trading increases the overall volatility of the exchange rate gap, thereby increasing the dispersion of returns for all classes of traders (Fig. 12). Moreover, starting from low levels of fundamentalists' attention to technical trading (ξ + = 0.1), both the inter-decile and the inter-quartile spreads of fundamentalists increase, suggesting that the trend is also a friend of fundamentalist traders (Table 7). Nevertheless, as fundamentalists keep overvaluing chartist signals, they widen the inter-quartile spread (such as trend followers) while simultaneously worsening the inter-decile spread, as extreme negative returns dominate the extreme positive returns. Therefore, this result rationalizes the fundamentalists' "obstinate passion" for technical trading, since keeping an eye on technical signals increases profitability relative to a pure strategy consisting of processing fundamental signals only.

Conclusion
We contribute to the theoretical literature on the determinants of exchange rate fluctuations, by building a model based on behavioral assumptions inspired by the behavioral finance literature and by empirical surveys about foreign exchange (FX) professionals' behavior.

Fig. 12
Fundamentalists' weight to technical trading and distribution of returns. 1st decile (10%), 1st quartile (25%), 3rd quartile (75%) and 9th decile (90%) of returns' distribution for each type of traders. Note: all series represent the average across 20 simulations with 20 random seeds We build an agent-based model in which heterogeneous traders interact according to different speculative strategies, based on fundamental and technical analysis. While fundamentalists use both fundamental and technical analysis, chartists only refer to technical analysis, and they either follow the trend or bet against it. By introducing these interactions in an artificial economy with two countries, in which traders can speculate on both exchange and interest rates, and allocate their wealth across heterogeneous assets, we are able to reproduce and explain observable features of financial markets, such as (i) the excess volatility of the exchange rate with respect to its fundamentals, (ii) booms, busts, and precarious equilibria, (iii) clusters of volatility, (iv) long memory, and (v) fat tails.
We find that the introduction of contrarian traders in standard "two-types" models allows reproducing realistic fluctuations of the exchange rate while simultaneously providing a theoretical justification of the co-existence of chartist and fundamentalist traders, contrarily to the predictions of the market selection hypothesis (MSH). For instance, we find that so long as a given class of traders dominates the market, returns' opportunities for the dominant class shrink faster than returns' opportunities for the other classes of traders, thereby eliminating any gain from speculation. In contrast, when heterogeneous speculative strategies co-exist, each strategy benefits from significant returns' opportunities (either positive or negative) that vary according to the speculative strategy: while the fundamentalist strategy is associated to long horizons and low volatility of returns, chartist strategies, and particularly the contrarian strategy, are short run strategies characterized by highly volatile returns. This result justifies the analysis of financial markets in terms of complex ecological systems, whereby different species (traders) interact with each other by creating, through their interaction, the conditions for their own Table 7 Fundamentalists' weight to technical trading and the inter-quantile and inter-decile spreads Note: all values represent the average across 20 simulations with 20 random seeds, relatively to the baseline scenario. The values in parenthesis represent the p value of the t test relatively to the baseline scenario. Hence, a low p value suggests that the estimated parameter is significantly different from the baseline. *p < 0.1, **p < 0.05, ***p < 0.01. survival and for the survival of the other species, instead of a simple ecosystem populated by a unique, dominant species (the fundamentalists). As a corollary, we suggest considering the empirically observed increasing share of technical traders not as evidence of high frequency behavioral switching from fundamentalist to chartist strategies, but as a structural and long run feature of financial markets in times of uncertainty about the "fundamentals" and increasing appetite for risk and speculation.
Our model also has limitations, which are as many possible extensions for future research. First, the macroeconomic structure of the model can easily be extended to provide both microeconomic foundations of macro fluctuations (by extending the macroeconomic structure of the model) and/or macroeconomic foundations of microeconomic behaviors (through the fundamentalist's expectation rules). A possible extension of our work might also consist of increasing the heterogeneity of chartists' forecasting rules to reflect more accurately the complexity of technical trading beyond moving averages and momentum models. Thirdly, since the focus of the paper is not on monetary policy, the central bank is currently much too passive, as it does not react to exchange rates and interest rate fluctuations. Introducing a central bank's reaction function and discretionary monetary policies could help in getting interesting insights regarding the effect of different monetary policies on the exchange rate, a topic that is crucial to economic policymaking and to the understanding of the evolution of the exchange rates. Along the same lines, exploring the effects of a liquidity crisis and comparing the effects of fiscal-dominated against monetary-dominated regimes would constitute an interesting extension. Finally, for the sake of thoroughness, our model is also stock-flow consistent. Nevertheless, contrary to the tradition in SFC modeling, our macroeconomic part might be seen as overly simple. We have made this choice deliberately to stay focused on daily exchange rates' dynamics and microeconomic analysis. In future work, this part could be further developed in order to explore the possible interactions among the dynamics of financial markets and macroeconomic outcomes, in both directions: how the key economic sectors' behavior can influence the exchange rate via fundamental analysis, and how, in return, the speculative dynamics of the exchange rate market might affect the productive side of an economy and its fundamentals. Our model could therefore be seen as laying the bases for the microeconomic structure of a micro-founded macroeconomic model, still to be developed.
Finally, some colleagues might argue that an alternative research agenda might be to simplify our model to gain more specific insights on key mechanisms and be able to estimate it empirically. Unquestionably, our model is currently too complex to be estimated empirically. Nevertheless, as stated in the previous sections, we did not aim at producing a model simple enough to replicate quantitative facts but rather a model realistic and complex enough to explain qualitative facts with the best possible fit. Our main objective in this paper is thus to reproduce and provide realistic and convincing explanations of the qualitative emerging economic and statistical properties of exchange rate fluctuations, given the still limited yet increasing knowledge that we have, as economists, about the real mechanisms driving financial markets.