You are on page 1of 7

Stocks & Commodities V.

24:6 (21-30): Harnessing The (Mis)Behavior Of Markets by Rick Martinelli


QUANTITATIVE ANALYSIS

Harnessing The (Mis)Behavior


Of Markets
Do market prices vary due to large numbers of random
effects such as the whims of individual traders?

n 1900, Louis Bachelier was awarded a


doctorate from the University of Paris
following his defense of a dissertation
titled Thorie de la Spculation, an
event that marked the first time a serious academic paper addressed the behavior of the
financial markets. In his dissertation, Bachelier proposed that market prices vary due to large numbers of
random effects, such as the whims of individual
traders, and hence can be modeled as Brownian
motion. Slowly, the financial community adopted
his ideas, which are now the foundation of modern
financial engineering.

THE BROWNIAN MODEL


Three critical assumptions underlie the Brownian
model, namely:
1. Price changes are statistically independent
2. Price changes are normally distributed, and
3. Price-change statistics do not vary over time.
The first assumption means that price changes
behave like coin tosses, where the current change
was not influenced by past changes and has no
influence on future changes.
The second assumption says that the changes follow a bell-shaped curve. This assumption is relevant
whenever random behavior is due to many small
influences. It provides a distribution function characterized by only two parameters, the mean and stanby Rick Martinelli

dard deviation, and implies a certain contained


behavior of the changes.
The third assumption states that the mean and
standard deviation do not change with time.
Knowledgeable investors might take exception to
one or all of these assumptions. In fact, there is ample
evidence that these assumptions simply do not apply
in the real markets. The recent book by Benoit
Mandelbrot and Richard Hudson, The (mis)Behavior
Of Markets, documents many of these violations. For
example, it discusses the 1987 stock market crash,
where there was a price change in the Dow Jones
Industrial Average (DJIA) equal to about 18 standard
deviations, an event with a probability of about one
in 1017 if the second assumption is true. A glance at
price changes for many of the more volatile stocks
over a long-enough time span suggests that the third
assumption is often violated as well.
The violation of either assumption 2 or 3 may
produce similar effects namely, larger than usual
excursions in price. Are these excursions accompanied by precursors smaller changes but in the
same direction, like earthquakes? If so, the changes
are locally correlated in violation of assumptions 1
and 3, and it may be possible to harness those
correlations by means of a simple linear predictor
and some statistical data. I will describe some results
from my attempt to do just that. I focus on the
statistical behavior of the stock charts and ignore
real-world issues such as commissions on trades.
BROWNIAN MOTION AND STOCK PRICES
The three assumptions I listed constitute the technical definition of a white noise. Consequently, the
changes in a Brownian motion are white noise.
Suppose a sequence of stock closing prices (P0,
P1,, PN) is a sample from a Brownian motion

Copyright (c) Technical Analysis Inc.

MIKE CRESSY

Stocks & Commodities V. 24:6 (21-30): Harnessing The (Mis)Behavior Of Markets by Rick Martinelli

Copyright (c) Technical Analysis Inc.

form a white-noise sequence characterized by:


1. Each Wn is normally distributed with mean zero and
(fixed) standard deviation s
2. The Wn are statistically independent (uncorrelated).

1/1/05

3/1/05

5/1/05

7/1/05

9/1/05

FIGURE 1: NORMALIZED PRICE CHANGES FOR GENERAL MOTORS (GM). From 11/01/04
to 10/28/04 or 253 days, with a mean = -0.039, and standard deviation = 0.727, these are
the normalized price differences.

Sigma ()

A larger standard deviation of W means a broader bell


curve and greater volatility in the prices. Figure 1 shows a
graph of 253 days of price changes for General Motors
(GM), starting November 1, 2004, and ended October 28,
2005,with adjusted close. The numbers have been normalized so that vertical units are standard deviations (sigmas).
Their mean (-0.039) has been subtracted and the result
divided by their standard deviation (s = 0.727). For reference, Figure 2 shows a graph of 253 points of computergenerated white noise having the same mean and standard
deviation. This sequence is typical in that its values rarely
exceed two sigmas in contrast to GM, whose largest change
is more than seven sigmas. Your goal is to capitalize on
these large sigmas.
Prices may be recovered from their changes according to
the simple formula:

8
6
4
2
0
-2
-4
-6
-8
11/1/04

MICROSOFT EXCEL

process. In that case, its price changes (W1, W2,,WN)


defined by
Wn = Pn Pn-1,

Sigma ()

Stocks & Commodities V. 24:6 (21-30): Harnessing The (Mis)Behavior Of Markets by Rick Martinelli

4
3
2
1
0
-1
-2
-3
1

51

101

151

201

251

FIGURE 2: COMPUTER-GENERATED WHITE NOISE. Here is a plot of simulated white


noise using 253 points, a mean of -0.039, and standard deviation of 0.727. The values rarely
exceeded two sigmas, whereas in the case of GM, it fluctuated close to seven sigmas.

Pk = P0 +

n=1

40

n=1

Fk = A n 1
n=1

20
11/1/04

Wn
Pn 1

1/1/05

3/1/05

5/1/05

7/1/05

9/1/05

FIGURE 3: CLOSING PRICES FOR GM. Here you see the closing prices for the 253 days
generated from Figure 1.

60

Wn
Pn 1

55

represents the fractional change in price between day zero


and day k an investment of D dollars on day zero results
in a profit/loss of D * Fk on day k. For this reason, Fk is called
the fortune indicator. But suppose you modify the equation
slightly to get:
k

30
25

Price

Fk =

35

Price

where P0 is the starting price.


In the case of GM, P0 was 37.16 on November 1, 2004,
and the resulting prices are shown in Figure 3. Using the
same starting price and the computer-generated values in
Figure 2 give the simulated prices shown in Figure 4; the
obvious differences between Figures 1 and 2 are not so
obvious between Figures 3 and 4. As pointed out in
Mandelbrot and Hudsons work, fake charts as in Figure
4 are virtually indistinguishable from real stock charts.
The summation that appears in the last equation represents the difference in the stocks price between day zero
and day k. Consequently,

50
45
40
35
30
1

51

101

151

201

251

FIGURE 4: A BROWNIAN MOTION. Here are the 253 simulated closing prices from the
white noise sequence in Figure 2.

Copyright (c) Technical Analysis Inc.

Stocks & Commodities V. 24:6 (21-30): Harnessing The (Mis)Behavior Of Markets by Rick Martinelli

An-1 = +1 if Wn > 0
An-1 = -1 if Wn < 0
making An-1Wn always positive (the case Wn = zero is ignored). In this case, a graph of Fk starts at zero and increases
thereafter, which is sort of a Holy Grail for traders! The
problem, of course, is that An-1 must be calculated on the day
before measuring Wn predicted on the previous day. How
do you go about doing that?

THE TRADING SYSTEM OR ALGORITHM


In the trading system I devised, I applied a one-day ahead
predictor, which is based on the previous behavior of the
tradable. A buy signal occurs when the predicted price
change exceeds the standard deviation of the most recent
changes. A wager of one unit is placed and the resulting profit/
loss taken at the close on the following day (there is no explicit
sell signal). Each days profit/loss is added to the previous
days total to get the profit or fortune to date. I call it a wager
because it is not a buy & hold system; rather, it is designed
primarily to exploit any misbehavior in the data. It is unrealistic in the sense that no one can trade at exactly the closing
price each time. However, if the system is to be implemented
in the real world, you can monitor the stocks intraday price
and buy just before the close. Similarly, the stock may be sold
any time before the close on the following day.
A long or short position is determined by predicted direction of the price movement. The question of when to place
the wager is determined as follows. If P' denotes the
predicted closing price change, and the standard deviation
of the most recent price changes, then the alpha indicator is
defined as the ratio:

Use the built-in FORECAST function to calculate Pn+1',


the estimate of Pn+1, based on the previous three prices:
Pn, Pn-1, Pn-2
Calculate Pn' = Pn+1' - Pn, the estimated price change
for day n + 1
Use the built-in function STDEVP to find n, the standard
deviation of the last seven price changes: Pn, Pn-1,
Pn-2, Pn-3, Pn-4, Pn-5, Pn-6
Calculate n = Pn' / n
I used a forecast lag of three because it is the smallest value
that can capture a trend and yields more potential wagers than
larger values. In calculating n, I found that a lag of seven
produced enough averaging while not involving data from the
remote past. If the lag was too short, small values of n determine
large values of n which could lead to losses. Figure 5 shows n
values computed from the GM data in Figure 3. Values range
roughly between 2 and -2, but what constitutes a relatively
large value?
A crucial parameter in this algorithm is the alpha cutoff,
denoted by C, where n > C signals a long position, and n < C a short position. For a long position, An-1 is set to +1, and for
a short position it is set to -1; the 1 represents one investing
unit. Otherwise, it is set to zero, and there is no investment on
day n. Thus, the algorithm for finding An is:

Alpha ()

where the Ans have the special property that

= P'

2
1
0
-1
-2

CALCULATING ALPHA
Let Pn denote the closing price of a stock and Pn = Pn Pn-1
its price change on day n. The algorithm for finding on day
n, n, is as follows (based on Excel computations).

-3
11/1/04

1/1/05

3/1/05

5/1/05

7/1/05

9/1/05

FIGURE 5: ALPHA VALUES. Here you see the k values for the GM closing prices in Figure
3. The values range between 2 and -2.

Fortune indicator value

Note that alpha is dimensionless. If alpha is greater than 1


or less than 1, this indicates the predicted price change
exceeds the recent average. Relatively large, positive values
of alpha indicate a long position, and relatively large, negative values of alpha indicate a short position. On a buy signal,
a position of one investing unit is taken, and after the next
close, the position is canceled and a profit/loss taken. Then
tomorrows position is calculated and the procedure repeats.
Assume that correlation within the price changes will be
captured in the forecast to produce a larger P than usual,
which is in turn captured in . I will now show you how to
calculate .

0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
-0.05
11/1/04

1/1/05

3/1/05

5/1/05

7/1/05

9/1/05

FIGURE 6: THE FORTUNE INDICATOR, C = 1.04. Overall, the value increases over time,
even if the closing prices of GM is decreasing.

Copyright (c) Technical Analysis Inc.

Stocks & Commodities V. 24:6 (21-30): Harnessing The (Mis)Behavior Of Markets by Rick Martinelli

An = +1 if n > C
An = -1 if n < -C
An = Zero if -C n C

BUY & HOLD


For comparison purposes, I also calculated the buy & hold
position as:

But do most stocks operate as


Brownian models and does the
Brownian model have an effect?

-0.1
11/1/04

1/1/05

3/1/05

5/1/05

7/1/05

9/1/05

FIGURE 7: WIN/LOSS RATIO, C = 1.04. In this case, the wins were generally larger than
the losses.

(PN P0) / P0

0.18
0.16
0.14
0.12
0.10
-0.08
-0.06
0.04
0.02
0
11/1/04

1/1/05

3/1/05

5/1/05

7/1/05

9/1/05

Win / loss

FIGURE 8: FORTUNE INDICATOR FOR BROWNIAN MOTION DATA IN FIGURE 4,


C = 1.42. Although similar to Figure 6, the LDF in this case is smaller.

0.06
0.05
0.04
0.03
0.02
0.01
0
-0.01
-0.02
-0.03
-0.04
11/1/04

1/1/05

3/1/05

5/1/05

7/1/05

9/1/05

FIGURE 9: WIN/LOSS RATIO FOR BROWNIAN MOTION DATA IN FIGURE 4

34

Closing price

This represents the fraction of the wager on day zero that


is won or lost by simply waiting for day N, and must be
compared with the LDF. In the case of GM, the stock decreased in value, the B&H position was -0.266, and hence the
difference between the LDF and B&H was 0.560. This means
a trader employing the current scheme realizes 56% more
return than an investor holding the stock.
The fortune indicator for the Brownian motion in Figure 4
can be seen in Figure 8. Here, C = 1.42, the LDF is 0.117, the
maximum fortune is 0.160 occurring at day 144, and the
number of wagers is 30, with 18 winners and 12 losers for a
win ratio of 0.60. The B&H value for this simulation was
0.45, with a difference of 0.333.
Figures 6 and 8 are similar in that they are both increasing
on average, but the LDF in the Brownian case is somewhat
smaller. Figure 9 shows fewer wagers than GM, as would be
expected from a comparison of Figures 1 and 2. However,
this behavior is not typical. After numerous experiments, it
appears that most any other LDF, from zero to greater than
one, can be obtained with a different computer-generated
white noise sequence, depending on how the prices are
patterned.
Price patterns can be understood by looking more closely
at price data in the vicinity of a win or loss. Figure 10 shows

0.1
0.05

-0.05

Fortune indicator value

However, these Ans will not always yield a positive factor


in An-1Wn. Figure 6 shows a graph of the fortune indicator for
GM using C = 1.04. Overall, the graph is increasing with
time, while GM is generally decreasing over the same time
period. The Excel spreadsheet was programmed to test values of C between 1 and 4 in increments of 0.01. The value that
maximized the fortune on the last day (the LDF) was chosen as
optimal C (1.04 in GMs case). The LDF for GM was 0.294,
with the maximum fortune of 0.305 occurring at day 239, just
14 days before datas end. The number of wagers was 49, with
26 winners and 23 losers for a win ratio of 0.531 (see Figure 7).
The two factors contributing to the rise in the fortune are the
win ratio and the sizes of the wins and losses. In the case of GM,
the winners were generally larger than the losers.

Win / loss

0.2
0.15

32

GM

30
28
26

24
Day 121

May 4, 2005

122

123

124

125

126

127

128

129

130

131 132

FIGURE 10: MISBEHAVIOR OF MARKETS. Here you see the closing prices of GM in the
vicinity of a large price change.

Copyright (c) Technical Analysis Inc.

Stocks & Commodities V. 24:6 (21-30): Harnessing The (Mis)Behavior Of Markets by Rick Martinelli

STOCK

SDATE

EDATE

BM-1

MAXF

B&H

LDF

DIFF

#W

WLR

1.27

2.924

1.614

2.606

0.992

29

0.55

RMBS

01/03/05

12/30/05

1.00

0.536

-0.292

0.488

0.780

64

0.75

01/03/05

01/06/06

1.10

0.243

-0.410

0.213

0.623

52

0.62

GM

11/01/04

10/28/05

BM-3

1.04

0.305

-0.266

0.294

0.560

49

0.53

1.00

0.216

-0.365

0.128

0.493

59

0.51

SYMC

01/10/05

01/09/06

1.31

0.172

-0.180

0.172

0.352

41

0.54

IBM

10/22/04

10/21/05

1.19

0.242

-0.038

0.231

0.269

47

0.65

SUNW

11/08/04

11/07/05

1.19

0.169

-0.191

0.077

0.268

45

0.64

DELL

11/09/04

11/07/05

1.91

0.026

-0.209

0.018

0.227

10

0.50

GE

01/07/05

01/05/06

2.22

0.000

-0.207

0.000

0.207

CSCO

11/09/04

11/07/05

1.04

0.077

-0.096

0.072

0.168

49

0.56

MSFT

01/10/05

01/09/06

1.00

0.203

0.014

0.177

0.163

76

0.66

ZMH

01/07/05

01/06/06

2.04

0.000

-0.144

0.000

0.144

ORCL

01/07/05

01/06/05

BM-2

1.04

0.174

-0.016

0.106

0.122

54

0.54

1.41

0.108

-0.001

0.102

0.103

23

0.52

AMZN

01/07/05

01/06/06

1.00

0.263

0.131

0.233

0.102

68

0.58

DJ

01/07/05

01/06/06

1.50

0.028

-0.054

0.024

0.078

13

0.38

INTC

11/09/04

11/08/05

1.34

0.145

0.074

0.120

0.046

32

0.72

SEBL

01/07/05

01/06/06

1.28

0.178

0.130

0.172

0.042

18

0.44

SIRI

01/10/05

01/09/06

1.30

0.076

-0.008

0.025

0.033

30

0.57

TWX

08/06/04

08/04/05

1.01

0.097

0.075

0.081

0.006

59

0.54

1.17

0.112

0.101

0.102

0.001

40

0.65

QQQQ

11/23/04

11/21/05

1.10

0.088

0.077

0.076

-0.001

50

0.61

DJI

01/07/05

01/06/06

1.40

0.024

0.026

0.010

-0.016

26

0.58

KCN

01/07/05

01/06/06

1.65

0.006

0.035

0.006

-0.029

0.67

DIA

01/06/05

01/06/06

1.35

0.021

0.055

0.016

-0.039

31

0.58

DUK

01/07/05

01/06/06

1.00

0.046

0.166

0.017

-0.149

60

0.43

AZN

01/07/05

01/06/06

1.02

0.256

0.435

0.197

-0.238

65

0.63

LSI

01/07/05

01/06/06

1.12

0.308

0.554

0.291

-0.263

46

0.62

WFMI

01/03/05

12/30/05

2.42

0.000

0.666

0.000

-0.666

GOOG
AAPL

01/03/05
01/10/05

12/30/05
01/09/06

1.41
1.38

0.116
0.188

1.047
1.206

0.075
0.163

-0.972
-1.043

29
29

BM-4

0.59
0.52

FIGURE 11: RESULTS SUMMARY. Here you see the results of experiments on 28 stocks/indexes. Four simulated
Brownian motions were used in this study.

a segment of GM data near day 128 (May 4, 2005). On this date,


GM jumped by 4.88 points, while price changes for the
previous seven days had a standard deviation of only 0.319.
The three previous closes were nicely aligned, yielding a
predicted close of 27.45, with a change of 0.51, and an alpha
equal to 1.59.
Since this exceeded the cutoff of 1.04, the wager was set to
+1 and a win of 0.181 was realized. This is a clear example of
a large change being preceded by several smaller ones, all in
the same direction. (Note that this win was immediately
followed by a loss of 0.059 when the stock had a loss of 1.89
on a predicted gain of 2.03.) This win can be traced directly
back to the +7 sigma outlier on day 128, an apparent violation

of the Brownian assumption. The other large outlier in Figure


1 is about -7 sigmas at day 94 (March 16, 2005) and yielded a
win of 0.140. How many other stocks enjoy this type of
misbehavior?

MORE EXAMPLES
I conducted 32 more experiments on 28 stocks/indexes and four
simulated Brownian motions. I selected the stock charts at
random from Yahoo!s most-active list as well as some popular
stocks from the DJIA and NASDAQ. The results are summarized
in Figure 11. Items BM-1 through BM-4 are the simulated
Brownian motions. Column headings Sdate and Edate represent
start and end dates, respectively, for the item in the first column.

Copyright (c) Technical Analysis Inc.

Stocks & Commodities V. 24:6 (21-30): Harnessing The (Mis)Behavior Of Markets by Rick Martinelli

BUT WHAT ABOUT


THE OTHERS?
My intention in this analysis was to test the
feasibility of harnessing any misbehavior in
stock prices, which amounted to calculating
the Ans that appear in the equation for the
fortune indicator. In this regard, the majority of items in
Figure 11 did indeed beat their buy & hold position, the
reason for which was traced to a particular price pattern as
exemplified in Figure 10. Essentially, the price must move in
the same direction for four consecutive days and, if the last
change is large enough, a profit is realized.
But do most stocks operate as Brownian models and does the
Brownian model have an effect on the fortune indicator? The
answer to this question is not as clear. It appears as though most
tradables work approximately as a Brownian motion, and
Bacheliers model works well most of the time. But when it
fails, such as with large price excursions, the scheme often

1.5
1.0

Buy & Hold

0.5

DIFF

Approximately one year of data was used in each case.


The optimal C value is in the column labeled C; MaxF,
B&H, and LDF are, respectively, the maximum fortune
achieved in the date range, the buy & hold position, and the
last-day fortune value. The difference between the LDF and
B&H position are shown in column DIFF; the table is ordered
by decreasing values of DIFF. Column #W is the total number
of wagers and WR is the win ratio.
Several observations can be made. Items with a positive
DIFF fare better under the scheme than buy & hold positions;
22 of the 32 items are in this category, including all four
simulations. The win ratio in the last column usually exceeds
0.5, indicating the linear predictor usually had more successes
than failures. It also appears to be uncorrelated with the DIFF.
Stocks that performed the best by DIFF ordering generally had
a negative B&H, the notable exception being BM-1, the top
performer. This is because the fortune indicator can increase
on a short position.
The worst performers were those with a large B&H value
like AAPL and GOOG, and, presumably, poor price patterns.
Figure 12 displays a graph of differences versus buy & hold
positions, which reveals a downward trend in agreement with
this observation.
General Electric (GE), Zimmer Holdings (ZMH), and Whole
Foods Market (WFMI) appear in their respective locations with
zero wagers, indicating there is no value of C that produces a
nonnegative LDF. Other items that appear near the top like
SUNW have very small LDFs, which are likely to disappear if
commissions are involved.
WFMI is interesting in that its B&H value is relatively large
yet no wagers were made. A close examination of its pricechange data suggests that the signs changed too often from plus
to minus for the linear predictor to be effective; this stock does
not misbehave.

0.0
-0.5
-1.0
-1.5
1.614

-0.180

-0.096

0.131

0.075

0.055

1.047

FIGURE 12: LAST-DAY FORTUNES VS. BUY & HOLD. Here you see the results for the
32 securities listed in Figure 11. Red points are simulated Brownian motions.

captures this behavior with an accompanying increase in the


fortune indicator. For GM, the pattern had a seven-sigma price
change, reducing the likelihood that it is a Brownian motion.
However, the data in Figure 11 suggests there is no difference
between true Brownian motions and real-world market items,
as far as the trading scheme is concerned.
The results suggest there are many tradables that would
yield a positive DIFF under this scheme. But how do you
choose? Will a stock continue to behave as it did historically,
or will the assumption that price-change statistics do not vary
over time be violated with disastrous consequences? How do
you choose optimal C in the real world?
Perhaps you can apply a more sophisticated technique such
as a Kalman filter to capture curvature in a trend. Or see what
happens when C is allowed to be smaller than one. This opens
the door to several other possibilities, which could be addressed in another article.
Rick Martinelli is owner of Haiku Laboratories, which supplies
customized technical and scientific software to individuals and
small businesses. He is an applied mathematician with a
masters degree in mathematics. He has over 20 years
experience in research and development in both private and
military sectors. His main areas of expertise involve using
computers to solve complex, real-world problems. His latest
research interests are in applying the statistical techniques he
developed for military applications to financial markets. He
has 16 scientific publications, holds a US patent, and has
published numerous technical publications.

RELATED READING
Bachelier, Louis [1900]. Thorie de la Spculation, Annales
de lEcole normale superiure.
Mandelbrot, Benoit, and Richard Hudson [2004]. The
(mis)Behavior Of Markets, Basic Books.
See our Traders Tips section for program code implementing Rick
Martinellis technique.
See Traders Glossary for definition

Copyright (c) Technical Analysis Inc.

S&C

You might also like