Following a Trend with an Exponential Moving Average: Analytical Results for a Gaussian Model
We investigate how price variations of a stock are transformed into profits and losses (P&Ls) of a trend following strategy. In the frame of a Gaussian model, we derive the probability distribution of P&Ls and analyze its moments (mean, variance, skewness and kurtosis) and asymptotic behavior (quantiles). We show that the asymmetry of the distribution (with often small losses and less frequent but significant profits) is reminiscent to trend following strategies and less dependent on peculiarities of price variations. At short times, trend following strategies admit larger losses than one may anticipate from standard Gaussian estimates, while smaller losses are ensured at longer times. Simple explicit formulas characterizing the distribution of P&Ls illustrate the basic mechanisms of momentum trading, while general matrix representations can be applied to arbitrary Gaussian models. We also compute explicitly annualized risk adjusted P&L and strategy turnover to account for transaction costs. We deduce the trend following optimal timescale and its dependence on both auto-correlation level and transaction costs. Theoretical results are illustrated on the Dow Jones index.
Systematic trading has grown as an industry in finance, allowing to take rapid trading decisions for multiple stocks Covel (); Clenow (); Chan96 (); Chan99 (); Jegadeesh01 (); Moskowitz12 (); Asness13 (). A strategy relies on price time series in the past in order to forecast price variations in near future and update accordingly its positions. Although the market complexity, variability and stochasticity damn such forecasting to fail in nearly half cases, even a tiny excess of successful forecasts is enhanced by a very large number of trades into statistically relevant profits. Many trading strategies attempt to detect an eventual trend in price series, i.e., a sequence of positively auto-correlated price variations which may be caused, e.g., by a news release or common activity of multiple traders. From a practical point of view, a strategy transforms the known past information into a signal for buying or selling a number of shares. From a mathematical point of view, systematic trading can be seen as a transformation of price time series into profit-and-loss (P&L) time series of the strategy, as illustrated on Fig. 1. For instance, the passive (long) strategy of buying and holding a stock corresponds to the identity transformation. The choice for the optimal strategy depends on the imposed risk-reward criteria.
In this paper, we study the transformation of price variations into P&Ls of a trend following strategy based on an exponential moving average (EMA). This archetypical strategy turns out to be the basis for many systematic trading platforms Covel (); Clenow (); Chan96 (); Chan99 (); Jegadeesh01 (); Moskowitz12 (); Asness13 (), while other methods such as the detrending moving average analysis or higher-order moving averages can also be employed Vandewalle98 (); Vandewalle99 (); Carbone04 (); Arianos11 (). A trend following strategy is known to skew the probability distribution of P&Ls Potters05 (); Martin12 (), as we illustrate on Fig. 2. This figure shows how empirically computed quantiles of price variations111 Here, by price variations we mean cumulative standardized logarithmic returns (normalized by realized volatility), to get closer to the Gaussian hypothesis Andersen00 (). are transformed into quantiles of P&Ls for the Dow Jones index (1900-2012). Even for such a long sample with 30733 daily returns, accurate estimation of quantiles remains problematic. Moreover, the basic mechanisms of this transformation remain poorly understood. For these reasons, we will study a simple model in which standardized logarithmic returns are Gaussian random variables Andersen00 () whose auto-correlations reflect random trends. Even though heavy tailed asymptotic distribution of returns and some other stylized facts are ignored Bouchaud (); Mantegna (); Mantegna95 (); Gabaix03 (); Bouchaud01 (); Sornette03 (); Bouchaud04 (); Stella08 (); Bouchaud01b (); Valeyre13 (), the Gaussian hypothesis will allow us to derive analytical results that can be later confronted to empirical market data. We will compute the probability distribution of P&Ls of a trend following strategy in order to understand how the Gaussian distribution of price variations is transformed by systematic trading. The respective roles of the market (positive auto-correlations) and of the strategy itself, onto profits and losses, will therefore be disentangled.
The paper is organized as follows. In Sec. 2, we introduce matrix notations, a market model and a trend following strategy. Main results about the probability distribution and moments of P&Ls are presented in Sec. 3. Discussion, conclusion and perspectives are summarized in Sec. 4.
2 Market model and trading strategy
2.1 Exponential moving average
The exponential moving average (EMA) is broadly employed in signal processing and data analysis Box (); Holt57 (); Winters60 (); Brown (). The EMA can be defined as a linear transformation of a time series to a smoother time series according to
where is the (inverse of) timescale. When , the EMA is the identity transformation: ; in contrast, many terms effectively contribute to when . The EMA is often preferred to simple moving average over a window of fixed length because it yields smoother results. In practice, it can be computed in real time according to a recurrent formula:
When a time series starts from , the non-existing elements , , , … are set to . This is equivalent to setting the upper limit in Eq. (1) to . In the analysis of a finite sample of length , the EMA can be written in a matrix form as
where is the matrix of size , whose elements are
2.2 Gaussian market models
The first Gaussian market model was introduced by Bachelier in 1900 and since that time, numerous models have been developed. For instance, the class of ARMA (Auto-Regressive Moving Average) models and their extensions were thoroughly employed in finance Box (). During decades, these models were getting more and more elaborate in order to account for various empirical features of markets. Our purpose is the opposite: we aim at understanding the basic mechanisms of trend following strategies, and we expect that qualitatively, these mechanisms weakly depend on market peculiarities. In turn, the quantitative behavior of P&Ls may of course be sensitive to particular features. For this reason, we choose a simple model exhibiting random trends, in order to be able to derive analytical results. At the same time, general matrix formulas used in this paper (see the beginning of Sec. 3) can be applied to arbitrary Gaussian market model. In this light, our methodology can be used for studying more elaborate models, though results will be less explicit.
In this paper, we consider a simple model of daily price variations, or returns,222 Throughout this paper, daily price variations will be called “returns” for the sake of simplicity. Rigorously speaking, we consider additive standardized logarithmic returns normalized by realized volatility. Such a resizing, which is a common practice on futures markets Martin12 (), allows one to reduce, to some extent, the impact of changes in volatility and its correlations Bouchaud01b (); Valeyre13 (), and to get closer to the Gaussian hypothesis of returns Andersen00 (). , in which random trends are induced by a discrete Ornstein-Uhlenbeck process, while short-time fluctuations are modeled by iid Gaussian variables with zero mean and unit variance:
where and are two parameters of the market model describing the characteristic timescale and the strength of the trend contribution, and are iid Gaussian variables (independent of ). This is a model of stochastic trends which are induced by a persistent process generated by exogeneous random variables which are independent from the short-time fluctuations . In a matrix form, one writes
where is the vector of returns (the superscript denoting the transpose), and and are two vectors of iid Gaussian variables. As a consequence, is a Gaussian vector with zero mean, , and the covariance matrix , for which
where stands for the identity matrix. The elements of this matrix are
The second term is the covariance of a discrete Ornstein-Uhlenbeck process. The diagonal elements approach the constant as , i.e., auto-correlations increase the variance of returns. It is convenient to make the limiting variance independent of the timescale by rescaling the parameter as
so that , independently of . In other words, the new parameter is the asymptotic excess variance of returns due to their auto-correlations. This parameter can be calibrated from empirical price series. For this purpose, we consider the variogram of returns over the lag time
where an initiation period of duration can be ignored to approach the stationary regime. The variogram would be equal to for iid random variables, while its deviations from characterize auto-correlations between variables. Expressing the variogram through the covariance matrix in Eq. (5), one gets in the stationary limit :
Figure 3 shows the empirical variogram of returns obtained from the Dow Jones index (1900-2012), and its fit according to Eq. (9). Although the model fails to reproduce a steep growth of auto-corrections at short times, it captures correctly the behavior of the variogram at longer times and allows us to get realistic values for the parameters and of the model: and . At the same time, these values are market dependent and, in general, difficult to calibrate. In what follows, the representative values and will be used for illustrative purposes.
For comparison, we also consider an auto-regressive model with exponential weights,
where are iid Gaussian variables. This is a model of autoregressive trends which are induced through auto-correlations with earlier returns. Writing Eq. (10) in a matrix form, and inverting this relation yields
where the explicit matrix inversion was possible due to the specific triangular structure of the matrix . As a consequence, is a Gaussian vector with zero mean and the covariance matrix
where . Comparing this relation to Eq. (5), one notes the effective timescale (instead of ), and an additional term . Although both models exhibit many similar features, they are not identical due to the presence of this term. For the sake of simplicity, we focus on the stochastic trend model (defined by Eq. (3)), while similar results for the auto-regressive trend model are derived and discussed in SM (). Qualitative conclusions of the paper do not depend on this choice.
It is worth noting that we focus on trends that are induced by auto-correlations, while mean returns are zero. While an extension to the case is relatively straightforward, the studied situation with allows us to easier illustrate the role of trend following strategy because the passive holding strategy is profitless in this case.
2.3 Trading strategy
The trading strategy relies on an EMA of returns in order to detect eventual trends in price time series Box (); Holt57 (); Winters60 (); Brown (). We consider the signal , which is proportional to the EMA of returns:
where and are two parameters of the strategy (in what follows, we will relate to , the latter remaining the only parameter of the strategy). It is crucial that the signal at time is determined by earlier returns , , … and does not rely on unavailable information on the present return . In a matrix form, Eq. (13) reads as
The cumulative P&L of a trend following strategy after steps is defined as
where is the duration of an initiation period,
is a symmetric matrix, and is the matrix which has in the diagonal positions between and , and elsewhere. The cumulative P&L in Eq. (15) is written as a quadratic form of the Gaussian vector . Similarly, an incremental P&L reads as
where is a shortcut notation for .
3 Profit-and-loss of trend following strategy
The representations (15, 17) of cumulative and incremental P&Ls as quadratic forms of Gaussian vectors allow one to investigate their properties. For a discrete Gaussian process with mean zero and covariance matrix , the quadratic form defined by a symmetric matrix is a random variable whose moments and probability distribution are well known Grebenkov11 (). In fact, a matrix representation of the characteristic function of ,
yields the probability density of through the inverse Fourier transform:
As described in Grebenkov11 (), the determinant can be expressed through the eigenvalues of the matrix that speeds up numerical computations. Moreover, the smallest and the largest eigenvalues, and , essentially determine the asymptotic behavior of the probability density :
(note that to ensure the decay of the density as ).
Finally, the cumulant moments of the quadratic form are
where denotes the trace. In particular, and are the mean and variance of , while higher-order cumulant moments determine the skewness () and kurtosis ().
3.1 Mean incremental P&L
We first consider the incremental P&L, , for which the matrix from Eq. (16) has a particularly simple structure, with nonzero contributions only at -th row and column. The product of this matrix with the covariance matrix can be written explicitly, e.g.,
where . In the special case , this expression reduces to
In the stationary limit (we recall that ), Eq. (23) yields the mean stationary daily P&L:
The mean cumulative P&L, , can be obtained by summing contributions in Eq. (23). In the stationary limit , the mean cumulative P&L is simply proportional to :
3.2 Variance of incremental P&L
The variance of the incremental P&L, , is
Since is a Gaussian vector, the Wick’s theorem allows one to express the fourth-order correlation of Gaussian variables through the covariance matrix:
Substituting Eq. (5) yields
In the special case , one gets
In the stationary limit , Eq. (27) reduces to
Setting the parameter of the strategy to
ensures the unit variance of the incremental P&L for the case of independent returns (i.e., when ). The condition allows one to properly compare trend following and passive (long) strategies. When , and , one gets , while the stationary variance of returns was . In other words, the correction term is enhanced by the large factor .
One can also consider the variogram of incremental P&Ls for which we derive in B the exact formula in the stationary limit . Interestingly, the variogram of incremental P&L can be larger or smaller than the variogram of returns, depending on the timescale of the strategy. It is worth noting that the variogram of incremental P&Ls is equal to for the case of independent returns.
It is instructive to consider the net risk adjusted P&L of the strategy, , in which the mean turnover is included to account for transaction costs. In A, we derive the exact formula for the mean daily turnover and its stationary limit . For , , and linear transaction costs (i.e., in Eq. (42)), Eq. (48) becomes . Using this approximate relation and approximations of Eqs. (25, 28) for , , and , we obtain
When there is no transaction cost (i.e., ), this function is maximized at , as illustrated on Fig. 4 (solid curve). For and , the position of the maximum is around , while the maximum level of the annualized risk adjusted P&L (given by Eq. (30) conventionally multiplied by ) is a typical value for systematic trading. Interestingly, the optimal timescale of the strategy is not equal to the timescale of the market model but it is enhanced by the factor due to auto-correlations of returns. When transaction costs are included, an explicit expression for the optimal timescale is too lengthy.333 In fact, , where is the positive root of the cubic polynomial which determines zeros of the derivative of Eq. (30) (here, and ). Although an exact solution can be written, the formula is too lengthy for further theoretical analysis. In turn, this formula can be used for numerical computation of the optimal timescale. As expected, an increase of the transaction cost reduces the risk adjusted P&L but also shifts the position of the maximum to smaller in order to get smoother signal and thus reduce transactions. This behavior is illustrated in Fig. 4. Note that general formulas in A are also applicable to nonlinear transaction costs. Interestingly, the optimal timescale depends on and through the ratio which is of the order of unity.
Finally, the strategy is profitable only if the net risk adjusted P&L is positive, i.e., , from which one gets a simple condition on transaction costs
The inequality (31) can be seen as a limitation either on the maximal transaction cost , or on the minimal level of auto-correlations , or on the maximal timescale of the strategy.
3.3 Skewness and kurtosis
In principle, one can compute explicitly the other cumulant moments and access skewness and kurtosis of the cumulative P&L. However, these expressions become too lengthy for practical use. In turn, the general matrix formula (21) allows for rapid numerical computation of these quantities. Figure 5 shows skewness () and kurtosis () of the cumulative P&L, , as functions of the lag time . Both quantities exhibit a maximum at , i.e., the timescale of trend following strategy. In other words, the strategy induces auto-correlations of P&Ls that are significant up to time and then slowly decay. In fact, if incremental P&Ls, , … , , were independent and identically distributed, the skewness and kurtosis of their sum, , would decay as and , respectively. We emphasize that this behavior of is induced by the trend following strategy itself, irrespectively of auto-correlations of returns. This is confirmed by the fact that both skewness and kurtosis behave similarly for independent and auto-correlated returns.
3.4 Distribution of incremental P&L
According to Eq. (17), the incremental P&L, , is the quadratic form defined by the symmetric matrix from Eq. (16). The probability distribution of can therefore be determined through the inverse Fourier transform (19).
3.4.1 Independent returns
We first consider the case of independent returns (), for which the covariance matrix is trivial: . In that case, there are only two nonzero eigenvalues of the matrix ,
where Eq. (29) was used in the last relation. As a consequence, the characteristic function of the incremental P&L is , from which the inverse Fourier transform yields
where is the modified Bessel function of the second kind. For large , the asymptotic behavior is
Note that is the variance of the incremental P&L. The skewness and kurtosis are and , respectively (see Fig. 5, on which an incremental P&L corresponds to ). In the stationary limit , one gets .
Figure 6 compares the probability density of the incremental P&L, , with the Gaussian density of a single return (with the unit variance). Although the mean and variance of these two distributions are identical, their overall behaviors are drastically different. The incremental P&L is peaked at (in fact, logarithmically diverges at ), while the tail decay is much slower than for returns. This transformation from a Gaussian density to is the effect of a trend following strategy.
3.4.2 Auto-correlated returns
For auto-correlated returns (), the diagonalization of the matrix and computation of the probability density can be performed numerically. As illustrated on Fig. 6, small auto-correlations of returns () slightly modify the probability distribution (33) by shifting the mean from zero to a small positive value and by increasing the probability of extreme values of (both positive and negative tails).
3.5 Distribution of cumulative P&L
The probability distribution of the cumulative P&L, , can be obtained numerically through the inverse Fourier transform (19). Figure 7 shows the probability density of for independent returns () and for auto-correlated returns (with and ). The initiation period of points was ignored to achieve stationary properties. In sharp contrast to symmetric (or almost symmetric) distributions of the incremental P&L from Fig. 6, the distribution of the cumulative P&L is strongly skewed and asymmetric, even for independent returns, in agreement with earlier observations Potters05 (); Martin12 (). The most probable P&L is negative, while the mean is nonnegative (it is for and strictly positive for ). The positive mean P&L for is ensured by relatively large probability for getting large positive profits. This result agrees with earlier observations that trend followers experience often small losses, waiting for a trend that may lead to considerable profits Potters05 (). We emphasize again that skewness of emerges due to the trading strategy itself, irrespectively of auto-correlations of returns.
Inspecting the distribution on Fig. 7, one can clearly observe an exponential decay of both positive and negative tails, in agreement with the expected asymptotic behavior (20). Importantly, the decay of the probability of negative P&Ls is much steeper than that of positive P&Ls. These extreme events can be characterized by quantiles. For this purpose, one first integrates the density to get the cumulative probability distribution and then solves the equation with that determines the -quantile of the distribution. In a first approximation, power law corrections in Eq. (20) can be ignored (by setting ) so that
Extreme negative values of the cumulative P&L correspond to the limit for which the equation can be approximately solved as
As expected, the behavior of the small -quantile is essentially determined by the smallest eigenvalue of the matrix . In turn, extreme positive values of P&L correspond to the limit for which
The large -quantile is therefore mainly determined by the largest eigenvalue of the matrix .
The behavior of the smallest and the largest eigenvalues of the matrix for the cumulative P&L is illustrated on Fig. 8. The largest eigenvalue grows with time and slowly approaches a constant value at long . In turn, the smallest eigenvalue decreases and approaches a constant value much faster. For independent returns, we compute in C the asymptotic values :
These values are shown on Fig. 8b by horizontal dash-dotted lines. One can see that is 8 times larger than . Most importantly, Eq. (38) turns out to be an accurate approximation for the smallest eigenvalue even for auto-correlated returns. In other words, extreme negative P&Ls weakly depend on the market features (here, and ) and are mainly determined by the trend following strategy (timescale ). In turn, the largest eigenvalue for auto-correlated returns may attain much larger values than from Eq. (37). In other words, the presence of trends due to auto-correlations of returns increases and thus enhances the probability of extreme positive P&Ls. In contrast to , the largest eigenvalue is sensitive to the market features.
We also analyzed the behavior of the largest and the smallest eigenvalues in the opposite case of short times . For independent returns, we compute in SM () the eigenvalues of the matrix for and . These explicit results suggest the conjectural asymptotic relation
which is applicable for small and moderate values of (see Fig. 8a). At short times, the small -quantile can be approximated as
This behavior can be compared to the quantile of price variation over the time , . For independent returns, this is a Gaussian variable with mean zero and variance , independently of the initiation period duration . The cumulative probability distribution is , from which the -quantile is given by the inverse error function:
One can see that this quantile grows as , while is constant. In turn, the quantile for the P&L, even after normalization by , exhibits a power law increase according to Eq. (40).
3.6.1 Auto-correlated returns
For auto-correlated returns (), the quantiles were computed numerically by solving the equation , in which the cumulative probability distribution was found by integrating the probability density .
Figure 9 illustrates the behavior of quantiles for the cumulative P&L, , and for price variation over the same time , . For independent returns (), the Gaussian quantile grows as according to Eq. (41). In turn, the quantiles for exhibit quite different behavior showing a strong asymmetry between positive and negative values. This asymmetry is further enhanced by auto-correlations of returns. The most interesting feature is the behavior of the renormalized quantile for small illustrated on Fig. 9d. At short time , the negative values of this quantile are smaller for P&L than for price variation. In other words, a trend following strategy may lead to more significant losses than one could naively anticipate from a Gaussian distribution of price variations. At larger times, the situation changes to the opposite: the quantile for the P&L exceeds that for price variation quite significantly. In other words, the trend following strategy ensures smaller losses at longer times, even in the absence of trends (when , see Fig. 9a,c).
One can also observe many similarities between Fig. 2a,b (Dow Jones) and Fig. 9a,b (present model). In particular, the quantiles in both cases are close to each other, confirming that quantiles for extreme negative P&Ls weakly depend on market features and may be well approximated even by a simple model. In turn, the quantiles on Fig. 2b and Fig. 9b are not so close, i.e., quantiles for extreme positive P&Ls are sensitive to market features.
In this paper, we investigated how price variations of a stock are transformed into profits and losses of a trend following strategy. We started by deriving simple formulas for the mean and variance of the P&L, as well as the mean turnover of the strategy. The explicit expression for the net annualized risk adjusted P&L allowed us to analyze the profitability of trend following strategies in the presence of auto-correlations and transaction costs, and their sensitivity to the choice of parameters. We next proceeded in computing explicitly the probability distribution of P&L and investigating its asymptotic behavior. The theoretical analysis was mainly done for independent returns and confronted to numerical results for auto-correlated returns. Although the model of correlated returns was over-simplified, it allowed us to illustrate the basic features and mechanisms of a trend following strategy. Moreover, the general matrix formulas provided at the beginning of Sec. 3 are applicable to arbitrary Gaussian models.
It is worth emphasizing that quantitative results of this study are model dependent. For instance, we analyzed the asymptotic behavior of the probability density for extreme losses and showed its exponential decay with the rate . An exponential decay is a universal feature for quadratic forms of Gaussian vectors. However, the dependence of the smallest eigenvalue on the parameter was only derived for the studied trend following strategy. Moreover, the unknown prefactor in the asymptotic formula (20) and related quantiles may strongly depend on other parameters, rendering quantitative estimates of quantiles model dependent. Finally, the asymptotic exponential decay of may settle at extremely large values of , at which the probability density is negligible and out of practical interest. At the same time, qualitative conclusions of the study are expected to be general. In fact, a trend following strategy strongly modifies probabilistic properties of price time series, yielding skewed asymmetric distributions, with often small losses and less frequent high profits. The probability of extreme losses decays much faster than the probability of extreme profits. Moreover, the occurence of extreme losses is more influenced by the trend following strategy than by the market itself. In turn, the occurence of extreme profits depends on both the strategy and the market. We showed that the usual Gaussian paradigm may lead to erroneous conclusions about trend following strategies. For instance, at short times, trend following strategies admit larger losses than one may anticipate from standard Gaussian estimates. This is an important message for systematic traders and risk analysts.
The present analysis can be extended to arbitrary Gaussian models of returns and to multiple correlated stocks. The practical advantage of choosing linear equation (13) is that the signal from EMAs of individual stocks is simply the sum of the related signals. As a consequence, the P&L of a portfolio is again a quadratic form of Gaussian vectors for which general matrix formulas at the beginning of Sec. 3 are still applicable. One can therefore study the role of inter-stock correlations which may significantly improve risk control of trend following strategies.
Appendix A Mean turnover of trend following strategy
Accounting for transaction costs is important for a comprehensive analysis of trading strategies. We define the daily turnover of the trend following strategy as
where represents transaction cost, and is an appropriate exponent (typically or ). The mean turnover can be evaluated by using the identity
where is a continuous function of the scalar product , is a Gaussian vector with mean zero and covariance matrix , and is a fixed vector. Setting and , one gets
where is Gamma function. Using Eq. (5), one obtains explicitly
In the special case , one gets
In the stationary limit, one finds
that simplifies when and to
Appendix B Variogram of incremental P&L
We sketch the derivation of the variogram of incremental P&Ls in the stationary limit . The variogram is defined as
The variances in the denominator are given by Eq. (27). One can explicitly compute their sum for ranging from to and then take the limit . As expected, this limit is simply equal , where the stationary variance is given by Eq. (28). The major difficulties rely in the computation of the numerator of Eq. (49) which contains correlations between incremental P&Ls.
We start by writing the definition of the variance
where the second relation implied by the Wick’s theorem. Lengthy but straightforward computation yields