A bounded operator approach to technical indicators without lag
AA bounded operator approach to technicalindicators without lag
Fr´ed´eric BUTIN ∗ September 21, 2020
Abstract
In the framework of technical analysis for algorithmic trading we use alinear algebra approach in order to define classical technical indicators asbounded operators of the space l ∞ ( N ). This more abstract view enablesus to define in a very simple way the no-lag versions of these tools.Then we apply our results to a basic trading system in order to comparethe classical Elder’s impulse system with its no-lag version and the so-called Nyquist-Elder’s impulse system. Keywords: bounded operators, technical indicators without lag, linearalgebra, algorithmic trading.
JEL Classification:
C60, C63, G11, G15, G17.
Delay in response is a major drawback of many classical technical indicatorsused in algorithmic trading, and this often leads to a useless or wrong informa-tion. The aim of this paper is to define in terms of bounded operators some ofthese classical indicators, in order to give and study their no-lag versions: theseno-lag versions provide a better information that is closer to the instantaneousvalues of the securities, thus a better return rate of the trading system in whichthey occur.For this purpose, we will define moving averages and exponential moving aver-ages as bounded operators in
Section 1 . Then,
Section 2 will be devoted tothe definition and the properties of the lag (in particular Proposition 4); we willalso make use of Nyquist criterium. Finally, all these results will enable us to ∗ Universit´e de Lyon, Universit´e Lyon 1, CNRS, UMR5208, Institut Camille Jordan, 43blvd du 11 novembre 1918, F-69622 Villeurbanne-Cedex, France, [email protected] a r X i v : . [ q -f i n . T R ] S e p ive no-lag versions of famous indicators that we will compare in Section 3 .We denote by E = l ∞ ( N ) the vector space of bounded real sequences, endowedwith the norm (cid:107)·(cid:107) ∞ defined by (cid:107) x (cid:107) ∞ = sup n ∈ N | x n | , and by L ( E ) the algebra ofcontinuous endomorphisms of E . Then, every sequence of values of a securitycan be identified with an element of E . Let us denote by H the affine hyperplane of R p with equation p − (cid:88) j =0 w j = 1 inthe canonical basis, by K the standard ( p − − simplex (also called standardsimplex of dimension p − K := w = ( w , . . . , w p − ) ∈ [0 , p / p − (cid:88) j =0 w j = 1 , and by K ∗ the subset of K that consists of elements whose no coordinate iszero. Definition 1.
Let w = ( w , w , . . . , w p − ) be in K ∗ . The weighted movingaverage with p periods and the weights defined by the vector w is the map M w from E to E defined, for every x ∈ E , by M w ( x ) = y , where y n = p − (cid:88) j = p − − n w j x n − p +1+ jp − (cid:88) j = p − − n w j if n ∈ [[0 , p − p − (cid:88) j =0 w j x n − p +1+ j if n ≥ p − . Proposition 1.
For every w ∈ K ∗ , M w belongs to L ( E ) .Proof. The map M w is clearly linear. Let us prove that this map is continuous:for every x ∈ E , let us set M w ( x ) = y as in Definition 1. Then, for every n ∈ [[0 , p − For example daily or monthly values. y n | ≤ (cid:80) p − j = p − − n w j p − (cid:88) j = p − − n w j | x n − p +1+ j | ≤ (cid:80) p − j = p − − n w j p − (cid:88) j = p − − n w j (cid:107) x (cid:107) ∞ , hence | y n | ≤ (cid:107) x (cid:107) ∞ ; and for every n ≥ p − | y n | ≤ p − (cid:88) j =0 w j | x n − p +1+ j | ≤ p − (cid:88) j =0 w j (cid:107) x (cid:107) ∞ = (cid:107) x (cid:107) ∞ , thus (cid:107) M w ( x ) (cid:107) ∞ ≤ (cid:107) x (cid:107) ∞ , which proves that M w is continuous. Example 1. M w ( x ) = y (2) , with y (2) n = p − (cid:88) i =0 w i p − (cid:88) j =0 w j x n − p +2+ i + j ∀ n ≥ p − . Example 2.
More generally, for every k ∈ N , M kw ( x ) = y ( k ) , with y ( k ) n = p − (cid:88) i =0 p − (cid:88) i =0 · · · p − (cid:88) i k =0 w i w i . . . w i k x n − k ( p − i + i + ··· + i k for every n ≥ k ( p − . Example 3.
For every polynomial P = d (cid:88) k =0 a k X k ∈ R [ X ] , we have P ( M w )( x ) = y ,with y n = d (cid:88) k =0 a k y ( k ) n for every n ≥ d ( p − .According to Proposition 1, P ( M w ) belongs to L ( E ) . Let us now define exponential moving averages . Definition 2.
Let α ∈ ]0 , . The exponential moving average of parameter α is the map M E α from E to E defined, for every x ∈ E , by M E α ( x ) = y , where y n = (cid:26) x if n = 0 αx n + (1 − α ) y n − if n ≥ . For example, when α is equal to p +1 , where p ∈ N ∗ , then p is called the num-ber of periods of M E α . In that case, we will denote M E α by M E p instead of M E p +1 .From Definition 2, we immediately deduce the following proposition. Note that these exponential moving averages are not weighted moving averages. roposition 2. Let α ∈ ]0 , . Let x ∈ E , and set y = M E α ( x ) . Then forevery n ∈ N , we have y n = (1 − α ) n x + α n (cid:88) j =1 (1 − α ) n − j x j . In the same way as for weighted moving averages, we have the following propo-sition.
Proposition 3.
For every α ∈ ]0 , , M E α belongs to L ( E ) .Proof. The map
M E α is clearly linear. Let us prove that it is continuous: forevery x ∈ E , let us set M E α ( x ) = y as in Definition 2. Then, for each n ∈ N , | y n | ≤ (1 − α ) n | x | + α n (cid:88) j =1 (1 − α ) n − j | x j | ≤ (cid:107) x (cid:107) ∞ (1 − α ) n + n (cid:88) j =1 (1 − α ) n − j , hence | y n | ≤ (cid:107) x (cid:107) ∞ (cid:18) (1 − α ) n + α − (1 − α ) n α (cid:19) = (cid:107) x (cid:107) ∞ , thus (cid:107) M E α ( x ) (cid:107) ∞ ≤ (cid:107) x (cid:107) ∞ , which proves that M E α is continuous. Here, we use some results obtained by Patrick Mulloy in the article [M94] (seealso [B17] and [E01]).We denote by τ the time difference between two measures: if x n is the value atthe time t n , then τ = t n − t n − . Definition 3.
Let w = ( w , w , . . . , w p − ) be in R p . Let M be a linear mapfrom E to E . For every x ∈ E , let us set y = M ( x ) . We assume that M satisfies ∀ n ≥ p − , y n = p − (cid:88) j =0 w j x n − p +1+ j . Then the lag of M is defined by lag ( M ) = τ p − (cid:88) j =0 w j ( p − − j ) . Let us note that lag ( id ) = 0. Let us also note that this definition is of coursevalid for every weighted moving average (i.e. with w ∈ K ∗ ). However, it is validfor more general linear maps. Example 4.
For w = p (1 , , . . . , ∈ K ∗ , the lag of M w ( classical movingaverage with p periods) is lag ( M ) = τp p − (cid:88) j =0 ( p − − j ) = ( p − τ . xample 5. For w = p ( p +1) (1 , , . . . , p ) ∈ K ∗ , the lag of M w ( simple weightedmoving average with p periods) is given by lag ( M ) = 2 τp ( p + 1) p − (cid:88) j =0 ( j + 1)( p − − j ) = 2 τp ( p + 1) p (cid:88) j =1 j ( p − j ) = ( p − τ . The following proposition establishes the fundamental property of the lag.
Proposition 4.
For every polynomial P = d (cid:88) k =0 a k X k ∈ R [ X ] , we have the for-mula lag ( P ( M w )) = lag ( M w ) d (cid:88) k =0 ka k = lag ( M w ) P (cid:48) (1) .Proof. For every k ∈ N , we have lag ( M kw ) = τ p − (cid:88) i =0 p − (cid:88) i =0 · · · p − (cid:88) i k =0 w i w i . . . w i k ( k ( p − − i − i − · · · − i k )= k (cid:88) l =1 τ p − (cid:88) i =0 p − (cid:88) i =0 · · · p − (cid:88) i k =0 w i w i . . . w i k ( p − − i l )= k (cid:88) l =1 τ p − (cid:88) i l =0 w i l ( p − − i l )since p − (cid:88) j =0 w j = 1. Hence lag ( M kw ) = k (cid:88) l =1 lag ( M w ) = k lag ( M w ).Finally, lag ( P ( M w )) = d (cid:88) k =0 a k lag ( M kw ) = lag ( M w ) d (cid:88) k =0 ka k . We can now get no-lag versions of weighted moving averages: this is the aim ofPropositions 5 and 6.
Proposition 5.
The only polynomial of the form P = aX + bX such that a + b = 1 and lag ( P ( M w )) = 0 is P = 2 X − X .Proof. We have a + b = 1. And according to Proposition 4, lag ( P ( M w )) =( a + 2 b ) lag ( M w ), thus a + 2 b = 0, so that the unique solution of the system is( a, b ) = (2 , − Proposition 6.
The only polynomial of the form Q = aX + bX + X suchthat a + b = 0 and lag ( Q ( M w )) = 0 is Q = 3 X − X + X .Proof. In the same way as in Proposition 5, we have a + b = 0 and lag ( Q ( M w )) =( a + 2 b + 3) lag ( M w ), thus a + 2 b + 3 = 0, and the unique solution of the systemis ( a, b ) = (3 , − .3 Using Nyquist criterium Here we recall some results obtained by D¨urschner in his article [D12]. Weconsider two weighted moving averages M w and M w with respectively p and p periods. Let x ∈ E , and let us set y (1) = M w ( x ) and y (2) = M w ( y (1) ). Weconsider the angles a and a as on Figure 1.Figure 1: Nyquist criteriumWe have a (cid:39) a , hence d l (cid:39) d l , i.e. l l (cid:39) d d . Moreover, d = x n − y (1) n and d = y (1) n − y (2) n , thus α n := l l (cid:39) x n − y (1) n y (1) n − y (2) n .We now define z = ( z n ) n ∈ N such that for every n ∈ N , α n := l l = z n − y (1) n y (1) n − y (2) n , i.e. z n = (1 + α n ) y (1) n − α n y (2) n .Now, we want α n not to depend on n . For this, we consider the lags of M w and M w that equal ( p − τ and ( p − τ when M w and M w are classical movingaverages, so that lag ( M w ) lag ( M w ) = p − p − , and we set α = p − p − . Finally, we define anew weighted moving average N by z n = (1 + α ) y (1) n − αy (2) n for every n ∈ N ,where z = N ( x ). In terms of linear maps, we have N = (1 + α ) M w − αM w ◦ M w . The stability Nyquist criterium concerning the choice of p and p is p p ≥ Definition 4.
Let M w and M w be two simple weighted moving averages withrespectively p and p periods and p ≥ p . Let us set α = p − p − .Then, we call Nyquist moving average with periods p , p the element N p ,p of L ( E ) defined by N p ,p = (1 + α ) M w − αM w ◦ M w . According to example 5, their weights are defined by w = p ( p +1) (1 , , . . . , p ) and w = p ( p +1) (1 , , . . . , p ). Technical indicators without lag
Here, we make use of the results of Section 2 in order to define technical indica-tors “without lag”. We begin with the exponential moving average, then definethe MACD and use them for Elder’s impulse system.
For every α ∈ ]0 , define the exponential moving average without lag asthe element M E α,wl := P ( M E α ) of L ( E ), where P is defined in Proposition 5. • Let us recall the definition of the MACD (moving average convergence diver-gence) introduced by Gerald Appel in 1979 in his financial newsletter “Systemsand Forecasts” and presented in his book [A85].First we set
M ACD = M E − M E , then M ACDS = M E ◦ M ACD , and
M ACDH = M ACD − M ACDS . These three maps belong to L ( E ). • We define the MACD without lag as follows: first we set M ACD wl = M E ,wl − M E ,wl , then M ACDS wl = M E ,wl ◦ M ACD wl , and M ACDH wl = M ACD wl − M ACDS wl . These three maps also belong to L ( E ). • In the same way, we define the Nyquist-MACD as follows: first we set
M ACD N = N , − N , , then M ACDS N = N , ◦ M ACD N , and M ACDH N = M ACD N − M ACDS N . Here again these three maps belong to L ( E ). By making use of the exponential moving average without lag and the MACDwithout lag, we can give a “no-lag version” of Elder’s impulse system. Let usfirst recall the definition of the impulse system introduced by Alexander Elderin his best-seller [E02]. 7et us set C = { R, G, B } and denote by F the set C N of sequences with valuesin C . Then, Elder’s impulse system can be defined in an algorithmic way asfollows. Definition 5.
Elder’s impulse system is the map IS from E to F defined, forevery x ∈ E , by IS ( x ) = y , where y = B and for every n ∈ N ∗ , y n = G if M E ( x ) n > M E ( x ) n − and M ACDH ( x ) n > M ACDH ( x ) n − R if M E ( x ) n < M E ( x ) n − and M ACDH ( x ) n < M ACDH ( x ) n − B else . Let us now give a “no-lag version” of Elder’s impulse system
Definition 6.
Elder’s impulse system without lag is the map IS wl from E to F defined, for every x ∈ E , by IS wl ( x ) = y , where y = B and for every n ∈ N ∗ , y n = G if ME ,wl ( x ) n > ME ,wl ( x ) n − and MACDH wl ( x ) n > MACDH wl ( x ) n − R if ME ,wl ( x ) n < ME ,wl ( x ) n − and MACDH wl ( x ) n < MACDH wl ( x ) n − B else . We also define the Nyquist-Elder’s impulse system.
Definition 7.
Nyquist-Elder’s impulse system is the map IS N from E to F defined, for every x ∈ E , by IS N ( x ) = y , where y = B and for every n ∈ N ∗ , y n = G if N , ( x ) n > N , ( x ) n − and MACDH N ( x ) n > MACDH N ( x ) n − R if N , ( x ) n < N , ( x ) n − and MACDH N ( x ) n < MACDH N ( x ) n − B else . Here we use a very simple trading system in order to compare the three versionsof Elder’s impulse system given in section 3.3. See for example [K19] and [JT09]for more information about trading systems. We use x = ( x n ) n ∈ [[0 , d ]] the dailyvalues of S&P index on the time period from 2017-11-01 to 2018-10-31. Algorithm 1. (very simple trading system)
For n ∈ [[0 , d ]] :Long entry : if f(x)_n=Gthen buy 1 mini contractShort entry : if f(x)_n=Rthen sell short 1 mini contractLong exit : if f(x)_n=Rthen sell 1 mini contractShort exit : if f(x)_n=Gthen buy 1 mini contract “R” (resp. “G”, “B”) stands for “red” (resp. “green”, “blue”). In this trading system, every position is automatically closed one day before the end ofthe test.
8e use Algorithm 1 with f = IS , f = IS wl and f = IS N . The results aregiven by Table 1, in which all values are in USD. Let us note that the value ofthe S&P index is 2 572 .
625 (resp. 2 706 . T P I = $6 675 for one mini contract during this period.Table 1: Comparison of the three various trading systems f = IS f = IS wl f = IS N Number of trades 27 35 52Total net profit 13 549 20 489 31 395Percentage of winning trades 52% 46% 50%Average net profit per trade 502 585 604Total net profit of winning trades (
T P ) 32 452 41 278 49 835Average net profit per winning trade ( AP ) 2 318 2 580 1 917Total net lost of losing trades ( T L ) −
18 903 −
20 789 −
18 440Average net lost per losing trade ( AL ) − − − −
10 231 − − T P/ | T L | .
72 1 .
99 2 . AP/ | AL | .
59 2 .
36 2 . T P/T P I .
86 6 .
18 7 . here the Nyquist-Elder’s impulse system is much better thanthe Elder’s impulse system without lag, which is itself better than the classi-cal impulse system: the information given by Nyquist-Elder’s impulse systemis indeed closer to the instantaneous value of the index since it has less delaythan the classical impulse system. We can also note that the number of tradesas well as the average net profit per trade are increasing when f is respectivelyequal to IS , IS wl and IS N . And the repartition of profit among long and shorttrades is more uniform with IS wl and IS N than with IS .Figure 2 eventually shows the S&P index from 2017-11-01 to 2018-10-31, withthe Nyquist moving averages N , (dotted line) and N , (solid line), thegraphs of M ACD N and M ACDS N with the histogram M ACDH N , and thethree versions of Elder’s impulse system (from bottom to top: IS , IS wl and IS N ). Here the transaction cost for every entry/exit is $3. S & P M A C D / S N , M A C D H N I S , I S w l , I S N Figure 2: S&P index from 2017-11-01 to 2018-10-31
References [A85] Gerald Appel, The Moving Average Convergence-Divergence Trading Method,
Traders Pr (1985).[B17] Eric Benhamou, Trend without Hiccups, a Kalman filter approach,
IFTA Jour-nal , 38–46 (2017).[D12] Manfred G. D¨urschner, Moving Averages 3.0,
IFTA Journal , 27–31 (2012).[E01] John F. Ehlers, Rocket Science for Traders,
John Wiley & Sons , New York(2001).[E02] Alexander Elder, Come Into My Trading Room,
John Wiley & Sons , New York(2002).[EW10] John F. Ehlers, Ric Way, Zero Lag (Well, Almost),
Stocks & Commodities , 30–35 (2010).[JT09] Emilio Tomasini, Urban Jaekle, Trading Systems: A New Approach to SystemDevelopment and Portfolio Optimisation,
Harriman House Publishing (2009).[K19] Perry J. Kaufman, Trading Systems and Methods,
John Wiley & Sons , NewYork (2019).[M94] Patrick Mulloy, Smoothing Data With Less Lag,
Stocks & Commodities (1994).(1994).