recognition, and quantitative ®nance employs the tools of mathematicalanalysis and probability and statistics. In the wake of recent breakthroughsin ®nancial engineering, computer technology, and numerical algorithms, it isno wonder that quantitative ®nance has overtaken technical analysis inpopularity ± the principles of portfolio optimization are far easier to programinto a computer than the basic tenets of technical analysis. Nevertheless,technical analysis has survived through the years, perhaps because its visualmode of analysis is more conducive to human cognition, and because patternrecognition is one of the few repetitive activities for which computers do nothave an absolute advantage (yet).Indeed, it is dicult to dispute the potential value of price/volume chartswhen confronted with the visual evidence. For example, compare the twohypothetical price charts given in Figure 2.1. Despite the fact that the twoprice series are identical over the ®rst half of the sample, the volume patternsdier, and this seems to be informative. In particular, the lower chart, whichshows high volume accompanying a positive price trend, suggests that theremay be more information content in the trend, e.g. broader participationamong investors. The fact that the joint distribution of prices and volumecontains important information is hardly controversial among academics.
44
Advanced Trading RulesPrice
Volume
DatePrice
Volume
DateFigure 2.1 Two hypothetical price/volume charts
Why, then, is the value of a visual depiction of that joint distribution so hotlycontested?In this chapter we hope to bridge this gulf between technical analysis andquantitative ®nance by developing a systematic and scienti®c approach to thepractice of technical analysis and by employing the now-standard methods ofempirical analysis to gauge the ecacy of technical indicators over time andacross securities. In doing so, our goal is not only to develop a lingua francawith which disciples of both disciplines can engage in productive dialogue,but also to extend the reach of technical analysis by augmenting its tool kitwith some modern techniques in pattern recognition.The general goal of technical analysis is to identify regularities in the timeseries of prices by extracting nonlinear patterns from noisy data. Implicit in
Foundations of technical analysis
45
this goal is the recognition that some price movements are signi®cant ± theycontribute to the formation of a speci®c pattern ± and others are merelyrandom ¯uctuations to be ignored. In many cases, the human eye canperform this `signal extraction' quickly and accurately, and until recently,computer algorithms could not. However, a class of statistical estimators,called smoothing estimators, is ideally suited to this task because they extract^  by `averaging out' the noise. Therefore, we proposenonlinear relations musing these estimators to mimic, and in some cases, sharpen the skills of atrained technical analyst in identifying certain patterns in historical priceseries.In the next section we provide a brief review of smoothing estimators anddescribe in detail the speci®c smoothing estimator we use in our analysis:kernel regression. Our algorithm for automating technical analysis isdescribed in section 2.3. We apply this algorithm to the daily returns ofseveral hundred US stocks from 1962 to 1996 and report the results in section2.4. To check the accuracy of our statistical inferences, we perform severalMonte Carlo simulation experiments and the results are given in section 2.5.We conclude in section 2.6.2.2 SMOOTHING ESTIMATORS AND KERNEL REGRESSIONThe starting point for any study of technical analysis is the recognition thatprices evolve in a nonlinear fashion over time and that the nonlinearitiescontain certain regularities or patterns. To capture such regularities quantitatively, we begin by asserting that prices fPt g satisfy the following expression:Pt  m Xt   t ;
t  1; . . . ; T
2:1
where m Xt  is an arbitrary ®xed but unknown nonlinear function of a statevariable Xt and ft g is white noise.For the purposes of pattern recognition in which our goal is to construct a^  to approximate the time series of prices fPt g, we set thesmooth function mstate variable equal to time, Xt  t. However, to keep our notation consistentwith that of the kernel regression literature, we will continue to use Xt in ourexposition.When prices are expressed as Equation (2.1), it is apparent that geometricpatterns can emerge from a visual inspection of historical price series ± pricesare the sum of the nonlinear pattern m Xt  and white noise ± and that suchpatterns may provide useful information about the unknown function m  tobe estimated. But just how useful is this information?To answer this question empirically and systematically, we must ®rstdevelop a method for automating the identi®cation of technical indicators,i.e., we require a pattern-recognition algorithm. Once such an algorithm is
46
Advanced Trading Rules
developed, it can be applied to a large number of securities over many timeperiods to determine the ecacy of various technical indicators. Moreover,quantitative comparisons of the performance of several indicators can beconducted, and the statistical signi®cance of such performance can beassessed through Monte Carlo simulation and bootstrap techniques. 1In section 2.2.1, we provide a brief review of a general class of patternrecognition techniques known as smoothing estimators, and in section 2.2.2 wedescribe in some detail a particular method called nonparametric kernelregression on which our algorithm is based. Kernel regression estimatorsare calibrated by a bandwidth parameter and we discuss how the bandwidth isselected in section 2.2.3.2.2.1 Smoothing estimatorsOne of the most common methods for estimating nonlinear relations such asEquation (2.1) is smoothing, in which observational errors are reduced byaveraging the data in sophisticated ways. Kernel regression, orthogonal seriesexpansion, projection pursuit, nearest-neighbour estimators, average derivative estimators, splines, and neural networks are all examples of smoothingestimators. In addition to possessing certain statistical optimality properties,smoothing estimators are motivated by their close correspondence to the wayhuman cognition extracts regularities from noisy data. 2 Therefore, they areideal for our purposes.To provide some intuition for how averaging can recover nonlinearrelations such as the function m  in Equation (2.1), suppose we wish toestimate m  at a particular date t0 when Xt0  x0 . Now suppose that for thisone observation, Xt0 , we can obtain repeated independent observations of theprice Pt0 , say P 1t0  p1 ; . . . ; P nt0  pn (note that these are n independentrealizations of the price at the same date t0 , clearly an impossibility inpractice, but let us continue with this thought experiment for a few moresteps). Then a natural estimator of the function m  at the point x0 is:^ x0  m
nn1X1Xpi m x0    it n i1n i1
 m x0  
n1Xin i1 t
2:22:3
and by the Law of Large Numbers, the second term in Equation (2.3)becomes negligible for large n.Of course, if fPt g is a time series, we do not have the luxury of repeatedobservations for a given Xt . However, if we assume that the function m  issuciently smooth, then for time-series observations Xt near the value x0 , the
Foundations of technical analysis
47
corresponding values of Pt should be close to m x0 . In other words, if m  issuciently smooth, then in a small neighbourhood around x0 , m x0  will benearly constant and may be estimated by taking an average of the Pt s thatcorrespond to those Xt s near x0 . The closer the Xt s are to the value x0 , thecloser an average of corresponding Pt s will be to m x0 . This argues for aweighted average of the Pt s, where the weights decline as the Xt s get fartheraway from x0 . This weighted-average or `local-averaging' procedure ofestimating m x is the essence of smoothing.More formally, for any arbitrary x, a smoothing estimator of m x may beexpressed as:^ x m
T1X! xPtT t1 t
2:4
where the weights f!t xg are large for those Pt s paired with Xt s near x, andsmall for those Pt s with Xt s far from x. To implement such a procedure, wemust de®ne what we mean by `near' and `far'. If we choose too large aneighbourhood around x to compute the average, the weighted average willbe too smooth and will not exhibit the genuine nonlinearities of m . If wechoose too small a neighbourhood around x, the weighted average will be toovariable, re¯ecting noise as well as the variations in m . Therefore, theweights f!t xg must be chosen carefully to balance these two considerations.2.2.2 Kernel regressionFor the kernel regression estimator, the weight function !t x is constructedfrom a probability density function K x, also called a kernel: 3K x  0;
K udu  1
2:5
By rescaling the kernel with respect to a parameter h > 0, we can change itsspread, i.e., let:1Kh u  K u=h;h
Kh udu  1
2:6
and de®ne the weight function to be used in the weighted average (Equation2.4) as:!t;h x  Kh xgh x 
Xt =gh x
T1XK xT t1 h
Xt 
2:72:8
If h is very small, the averaging will be done with respect to a rather smallneighbourhood around each of the Xt s. If h is very large, the averaging will be
48
Advanced Trading Rules
over larger neighbourhoods of the Xt s. Therefore, controlling the degree ofaveraging amounts to adjusting the smoothing parameter h, also known asthe bandwidth. Choosing the appropriate bandwidth is an important aspect ofany local-averaging technique and is discussed more fully in section 2.2.3.Substituting Equation (2.8) into Equation (2.4) yields the Nadaraya±^ h x of m x:Watson kernel estimator mTX
Kh x Xt YtT1Xt1^ h x ! xYt  TmXT t1 t;hKh x X t 
2:9
t1
Under certain regularity conditions on the shape of the kernel K and themagnitudes and behaviour of the weights as the sample size grows, it may be^ h x converges to m x asymptotically in several ways (seeshown that mHaÈrdle, 1990 for further details). This convergence property holds for a wideclass of kernels, but for the remainder of this chapter we shall use the mostpopular choice of kernel, the Gaussian kernel:x21Kh x  p e 2h2h 2
2:10
2.2.3 Selecting the bandwidthSelecting the appropriate bandwidth h in Equation (2.9) is clearly central to^ h  in approximating m  ± too little averaging yields athe success of mfunction that is too choppy, and too much averaging yields a function that istoo smooth. To illustrate these two extremes, Figure 2.2 displays theNadaraya±Watson kernel estimator applied to 500 datapoints generatedfrom the relation:Yt  sin Xt   0:5Zt ;
Zt  N 0; 1
2:11
where Xt is evenly spaced in the interval 0; 2. Figure 2.2(a) plots the rawdata and the function to be approximated.Kernel estimators for three dierent bandwidths are plotted as solid lines inFigure 2.2(b)±(c). The bandwidth in Figure 2.2(b) is clearly too small; thefunction is too variable, ®tting the `noise' 0:5 Zt as well as the `signal' sin .Increasing the bandwidth slightly yields a much more accurate approximationto sin  as Figure 2.2(c) illustrates. However, Figure 2.2(d) shows that if thebandwidth is increased beyond some point, there is too much averaging andinformation is lost.
Foundations of technical analysis
49
Simulated Data: Y  Sin X  :5Z
32
Y
10
12DataSin(X)
30.00
1.57
3.14
4.71
6.28
X(a)Kernel Estimate for Y  Sin X  :5Z, h  :1
32
E[Y/X]
10
123
KernelDataSin(X)
0.00
1.57
3.14
4.71
X(b)Figure 2.2 Illustration of bandwidth selection for kernel regression
6.28
50
Advanced Trading RulesKernel Estimate for Y  Sin X  :5Z, h  :3
3
E[Y/X]
210
12
KernelDataSin(X)
30.00
1.57
3.14
4.71
6.28
X(c)Kernel Estimate for Y  Sin X  :5Z, h  2:0
32
E[Y/X]
10
123
KernelDataSin(X)
0.00
1.57
3.14X(d)Figure 2.2 (continued)
4.71
6.28
Foundations of technical analysis
51
There are several methods for automating the choice of bandwidth h inEquation (2.9), but the most popular is the cross-validation method in which his chosen to minimize the cross-validation function:CV h 
T1XPT t1 t
^ h;t 2m
2:12
where^ h;t m
T1X! YT 6t ;h 
2:13
^ h;t is the kernel regression estimator applied to the priceThe estimator mhistory fP g with the tth observation omitted, and the summands in Equation^ h;t s, each evaluated at the omitted(2.12) are the squared errors of the mobservation. For a given bandwidth parameter h, the cross-validationfunction is a measure of the ability of the kernel regression estimator to ®teach observation Pt when that observation is not used to construct the kernelestimator. By selecting the bandwidth that minimizes this function, we obtaina kernel estimator that satis®es certain optimality properties, for example,minimum asymptotic mean-squared error. 4Interestingly, the bandwidths obtained from minimizing the cross-validation function are generally too large for our application to technical analysis ±when we presented several professional technical analysts with plots of cross^ h , they all concluded that the ®tted functionsvalidation-®tted functions mwere too smooth. In other words, the cross-validation-determined bandwidthplaces too much weight on prices far away from any given time t, inducingtoo much averaging and discarding valuable information in local pricemovements. Through trial and error, and by polling professional technicalanalysts, we have found that an acceptable solution to this problem is to use abandwidth of 0:3  h  , where h  minimizes CV h. 5 Admittedly, this is an adhoc approach, and it remains an important challenge for future research todevelop a more rigorous procedure.Another promising direction for future research is to consider alternativesto kernel regression. Although kernel regression is useful for its simplicity andintuitive appeal, kernel estimators suer from a number of well-knownde®ciencies, e.g., boundary bias, lack of local variability in the degree ofsmoothing, etc. A popular alternative that overcomes these particularde®ciencies is local polynomial regression in which local averaging ofpolynomials is performed to obtain an estimator of m x. 6 Such alternativesmay yield important improvements in the pattern-recognition algorithmdescribed in the next section.
52
Advanced Trading Rules
2.3 AUTOMATING TECHNICAL ANALYSIS^  of fPt g with which geometricArmed with a mathematical representation mproperties can be characterized in an objective manner, we can now constructan algorithm for automating the detection of technical patterns. Speci®cally,our algorithm contains three steps:1 De®ne each technical pattern in terms of its geometric properties, e.g.,local extrema (maxima and minima).^  of a given time series of prices so that2 Construct a kernel estimator mits extrema can be determined numerically.^  for occurrences of each technical pattern.3 Analyse mThe last two steps are rather straightforward applications of kernel regression. The ®rst step is likely to be the most controversial because it is here thatthe skills and judgement of a professional technical analyst come into play.Although we will argue in section 2.3.1 that most technical indicators can becharacterized by speci®c sequences of local extrema, technical analysts mayargue that these are poor approximations to the kinds of patterns that trainedhuman analysts can identify.While pattern-recognition techniques have been successful in automating anumber of tasks previously considered to be uniquely human endeavours ±®ngerprint identi®cation, handwriting analysis, face recognition, and so on ±nevertheless it is possible that no algorithm can completely capture the skillsof an experienced technical analyst. We acknowledge that any automatedprocedure for pattern recognition may miss some of the more subtle nuancesthat human cognition is capable of discerning, but whether an algorithm is apoor approximation to human judgement can only be determined byinvestigating the approximation errors empirically. As long as an algorithmcan provide a reasonable approximation to some of the cognitive abilities of ahuman analyst, we can use such an algorithm to investigate the empiricalperformance of those aspects of technical analysis for which the algorithm is agood approximation. Moreover, if technical analysis is an art form that canbe taught, then surely its basic precepts can be quanti®ed and automated tosome degree. And as increasingly sophisticated pattern-recognition techniques are developed, a larger fraction of the art will become a science.More importantly, from a practical perspective, there may be signi®cantbene®ts to developing an algorithmic approach to technical analysis becauseof the leverage that technology can provide. As with many other successfultechnologies, the automation of technical pattern recognition may not replacethe skills of a technical analyst, but can amplify them considerably.In section 2.3.1, we propose de®nitions of ten technical patterns based ontheir extrema. In section 2.3.2 we describe a speci®c algorithm to identify
Foundations of technical analysis
53
technical patterns based on the local extrema of price series using kernelregression estimators, and we provide speci®c examples of the algorithm atwork in section 2.3.3.2.3.1 Definitions of technical patternsWe focus on ®ve pairs of technical patterns that are among the most popularpatterns of traditional technical analysis (see, for example, Edwards andMagee, 1966, Chapters VII±X): head-and-shoulders (HS) and inverse headand-shoulders (IHS), broadening tops (BTOP) and bottoms (BBOT), triangletops (TTOP) and bottoms (TBOT), rectangle tops (RTOP) and bottoms(RBOT), and double tops (DTOP) and bottoms (DBOT). There are manyother technical indicators that may be easier to detect algorithmically ±moving averages, support and resistance levels, and oscillators, for example± but because we wish to illustrate the power of smoothing techniques inautomating technical analysis, we focus on precisely those patterns that aremost dicult to quantify analytically.Consider the systematic component m  of a price history fPt g andsuppose we have identi®ed n local extrema, i.e., the local maxima andminima, of fPt g. Denote by E1 ; E2 ; . . . ; En the n extrema and t 1 ; t 2 ; . . . ; t nthe dates on which these extrema occur. Then we have the followingde®nitions:De®nition 1 (Head-and-Shoulders) Head-and-shoulders (HS) and invertedhead-and-shoulders (IHS) patterns are characterized by a sequence of ®veconsecutive local extrema E1 ; . . . ; E5 such that:8E is a maximum>>> 1<E3 > E1 ; E3 > E5HS >E1 and E5 are within 1.5 per cent of their average>>:E2 and E4 are within 1.5 per cent of their averageIHS 
8E1 is a minimum>><E < E ;E < E3
1
3
5
>E and E5 are within 1.5 per cent of their average>: 1E2 and E4 are within 1.5 per cent of their average
Observe that only ®ve consecutive extrema are required to identify a headand-shoulders pattern. This follows from the formalization of the geometry ofa head-and-shoulders pattern: three peaks, with the middle peak higher thanthe other two. Because consecutive extrema must alternate between maximaand minima for smooth functions, 7 the three-peaks pattern corresponds to asequence of ®ve local extrema: maximum, minimum, highest maximum,
54
Advanced Trading Rules
minimum, and maximum. The inverse head-and-shoulders is simply themirror image of the head-and-shoulders, with the initial local extrema aminimum.Because broadening, rectangle, and triangle patterns can begin on either alocal maximum or minimum, we allow for both of these possibilities in ourde®nitions by distinguishing between broadening tops and bottoms:De®nition 2 (Broadening) Broadening tops (BTOP) and bottoms (BBOT)are characterized by a sequence of ®ve consecutive local extrema E1 ; . . . ; E5such that:88>>E is a minimumEisamaximum>>1<< 1BTOP 
E1 < E3 < E5>>:E > E2
4
BBOT 
E1 > E3 > E5>>:E <E2
4
De®nitions for triangle and rectangle patterns follow naturally.
De®nition 3 (Triangle) Triangle tops (TTOP) and bottoms (TBOT) arecharacterized by a sequence of ®ve consecutive local extrema E1 ; . . . ; E5such that:88>>> E1 is a maximum> E1 is a minimum<<TTOP E1 > E3 > E5TBOT E1 < E3 < E5>>>>:E < E:E >E2
4
2
4
De®nition 4 (Rectangle) Rectangle tops (RTOP) and bottoms (RBOT) arecharacterized by a sequence of ®ve consecutive local extrema E1 ; . . . ; E5such that:8E1 is a maximum>>>< tops are within 0.75 per cent of their averageRTOP >bottoms are within 0.75 per cent of their average>>:lowest top > highest bottom8E1 is a minimum>>>< tops are within 0.75 per cent of their averageRBOT >bottoms are within 0.75 per cent of their average>>:lowest top > highest bottom
The de®nition for double tops and bottoms is slightly more involved.Consider ®rst the double top. Starting at a local maximum E1 , we locatethe highest local maximum Ea occurring after E1 in the set of all local extremain the sample. We require that the two tops, E1 and Ea , be within 1.5 per centof their average. Finally, following Edwards and Magee (1966), we require
Foundations of technical analysis
55
that the two tops occur at least a month, or 22 trading days, apart. Therefore,we have the following de®nition:De®nition 5 (Double Top and Bottom) Double tops (DTOP) and bottoms(DBOT) are characterized by an initial local extremum E1 and subsequentlocal extrema Ea and Eb such that:Ea  supfP tk : t k > t 1 ; k  2; . . . ; ng
Eb  inffP tk : t k > t 1 ; k  2; . . . ; ngand
8>< E1 is a maximumDTOP  E1 and Ea are within 1.5 per cent of their average>: t a t 1 > 228>< E1 is a minimumDBOT  E1 and Eb are within 1.5 per cent of their average>: t a t 1 > 222.3.2 The identification algorithmOur algorithm begins with a sample of prices fP1 ; . . . ; PT g for which we ®tkernel regressions, one for each subsample or window from t to tld 1,where t varies from 1 to T l d 1, and l and d are ®xed parameters whosepurpose is explained below. In the empirical analysis of section 2.4, we setl  35 and d  3; hence each window consists of 38 trading days.The motivation for ®tting kernel regressions to rolling windows of data isto narrow our focus to patterns that are completed within the span of thewindow ± ld trading days in our case. If we ®t a single kernel regression tothe entire dataset, many patterns of various durations may emerge, andwithout imposing some additional structure on the nature of the patterns, it isvirtually impossible to distinguish signal from noise in this case. Therefore,our algorithm ®xes the length of the window at l  d, but kernel regressionsare estimated on a rolling basis and we search for patterns in each window.Of course, for any ®xed window, we can only ®nd patterns that arecompleted within ld trading days. Without further structure on thesystematic component of prices m , this is a restriction that any empiricalanalysis must contend with. 8 We choose a shorter window length of l  35trading days to focus on short-horizon patterns that may be more relevant foractive equity traders, and we leave the analysis of longer-horizon patterns tofuture research.
56
Advanced Trading Rules
The parameter d controls for the fact that in practice we do not observe arealization of a given pattern as soon as it has completed. Instead, we assumethat there may be a lag between the pattern completion and the time ofpattern detection. To account for this lag, we require that the ®nal extremumthat completes a pattern occurs on day tl 1; hence d is the number of daysfollowing the completion of a pattern that must pass before the pattern isdetected. This will become more important in section 2.4 when we computeconditional returns, conditioned on the realization of each pattern. Inparticular, we compute post pattern returns starting from the end of tradingday tld, i.e., one day after the pattern has completed. For example, if wedetermine that a head-and-shoulders pattern has completed on day tl 1(having used prices from time t through time tld 1), we compute theconditional one-day gross return as Z1  Ytld1 =Ytld . Hence we do notuse any forward information in computing returns conditional on patterncompletion. In other words, the lag d ensures that we are computing ourconditional returns completely out-of-sample and without any `look-ahead'bias.Within each window, we estimate a kernel regression using the prices inthat window, hence:
^ h  m
tldX1
Kh 
sttldX1
Kh 
sPss
t  1; . . . ; T l d 1
2:14
st
where Kh z is given in Equation (2.10) and h is the bandwidth parameter (see^ h  is a dierentiable function of .Section 2.3.3). It is clear that m^ h  has been computed, its local extrema can beOnce the function m^ 0h  1 ,^ 0h   Sgn mreadily identi®ed by ®nding times  such that Sgn m^ h with respect to  and Sgn  is the^ 0h denotes the derivative of mwhere m^ 0h  1 are 1 and 1, respectively,^ 0h  msignum function. If the signs of mthen we have found a local maximum, and if they are 1 and 1, respectively,then we have found a local minimum. Once such a time  has been identi®ed,we proceed to identify a maximum or minimum in the original price seriesfPt g in the range t 1; t1, and the extrema in the original price series areused to determine whether or not a pattern has occurred according to thede®nitions of section 2.3.1.^ 0h   0 for a given , which occurs if closing prices stay the sameIf mfor several consecutive days, we need to check whether the price we havefound is a local minimum or maximum. We look for the date s such that
Foundations of technical analysis
57
^ 0h s 6 0g. We then apply the same method as discusseds  inffs >  : m^ 0h s .^ 0h  1 and Sgn mabove, except here we compare Sgn mOne useful consequence of this algorithm is that the series of extrema whichit identi®es contains alternating minima and maxima. That is, if the k thextremum is a maximum, then it is always the case that the k1 th extremumis a minimum and vice versa.An important advantage of using this kernel regression approach toidentify patterns is the fact that it ignores extrema that are `too local'. Forexample, a simpler alternative is to identify local extrema from the raw pricedata directly, i.e., identify a price Pt as a local maximum if Pt 1 < Pt andPt > Pt1 and vice versa for a local minimum. The problem with thisapproach is that it identi®es too many extrema, and also yields patternsthat are not visually consistent with the kind of patterns that technicalanalysts ®nd compelling.Once we have identi®ed all of the local extrema in the windowt; tld 1, we can proceed to check for the presence of the varioustechnical patterns using the de®nitions of section 2.3.1. This procedure isthen repeated for the next window t1; tld, and continues until the endof the sample is reached at the window T l d 1; T.
2.3.3 Empirical examplesTo see how our algorithm performs in practice, we apply it to the dailyreturns of a single security, CTX, during the ®ve-year period from 1992 to1996. Figures 2.3±2.7 plot occurrences of the ®ve pairs of patterns de®ned insection 2.3.1 that were identi®ed by our algorithm