• No results found

2 Technical Indicator based Trading Strategies

2.1 Technical Indicators as a Basis for Trading

Most of the last forty years of financial economics have been dedicated to the rational equi-librium model where asset prices follow a random walk, possibly disturbed by price shocks of smaller or bigger extends. By consequence, it would be vain to try and predict the direction of their next move.

Rational equilibrium prices are the result of the concerted actions of all agents in the market.

These agents are considered to be rational, i.e., to maximize expected utilities with the objective probabilities of the state of the economy (see e.g., Lucas (1978)). Agents who do not behave rationally in the above sense (the so-called ”Noise traders” (see Black (1986))) would eventually be driven out of the market by the rational investors. In the long run, only the rational agents would thus be able to influence the market prices. By the immediate incorporation of any new information into trading actions, price fluctuations would then become random.

However, as noted as early as in Fama (1965), large price fluctuations do occur much more frequently than they should if they would follow a random walk. The price difference distribution has, in fact, heavy (or fat) tails.

Also, the volatility of market prices tends to ”cluster”, i.e., to vary over time. Periods of little volatility are followed by periods where prices are substantially more volatile. According to the rational equilibrium framework, the volatility would have to be constant over time, though.

Furthermore, recent research gives strong support to the meaningfulness of price- and volume based technical trading strategies: Kogan, Ross, Wang, and Westerfield (forthcoming) show that ”noise” traders keep their impact on asset prices, even when their wealth in the market becomes negligible. Bucher (2005) shows that in markets with endogenous asset supply and demand, rational and noise traders will co-exist in the long run. Price fluctuations are thus not random anymore. As a consequence, technical indicators capable to capture elements of this non-randomness may be utilized successfully for trading.

Another attempt to explain the market phenomena that deviate from the rational equi-librium model comes from Behavioral Finance. During the last decade, it has gained a lot of popularity both in practice and academia. Behavioral Finance tries to understand market prices from a social psychological point of view, asking and answering questions like: What behavior of market participants leads to price bubbles? What is the influence of information or rumors on prices? How important are personal networks for the price formation? etc.For recent overviews of Behavioral Finance, see e.g., Shleifer (2000) and Barberis and Thaler (2003).

For the simulations below, only technical indicators that make sense from a behavioral finance point of view will be utilized, reflecting the following line of thought: Start from the premiss that prices represent the aggregated behavior of the traders in the market, and that these traders do not behave like ”rational robots”, but like emotional humans. The traders gather in crowds, look at price and volume histories, are sometimes fearful, sometimes euphoric, buying and selling based on facts as well as on emotions. Think of the price of an asset as

the traders’ momentary consensus of value of the asset. In order to make successful trading decision, assess if the majority of the traders is ’bullish’, i.e., expects prices to rise, or ’bearish’, i.e., expects prices to fall. Depending on wether bulls or bears are stronger, prices move up or down. Use technical indicators that allow to assess what market group is stronger.

Note that Technical Analysis provides a mean to analyze changes in the behavior of the market crowd, and to infer the direction of resulting price. It does, however, not attempt to predict future price levels or price rates of change. This point cannot be stressed enough, as it distinguishes technical indicators from seemingly related price forecast ”black boxes” like neural networks.

2.2 Overview of Technical Indicators used in the Simulations

For the simulations in Section4, I use some of the technical indicators that are among the most popular by traders. For a comprehensive discussion of technical indicators, see e.g., Achelis (1995) and Elder (1993). As the trades are restricted to be on the long side, the selection of indicators is limited to those that are potentially useful for generating buy signals2.

The indicators are grouped into four classes: trends, momentum, oscillators and indices.

Trends indicate the direction of a price, momentum tells about the trends acceleration or deceleration, oscillators try to capture short term fluctuations, and indices combine various prices and volumes into one measure.

2.2.1 Trends

The first group of indicators are price trends. They provide information about the market’s inertia.

Price trends are identified by filtering out the small fluctuations of prices over time. In this application, the filtering is done by calculating

2Of course, some of the selected indicators might be useful for short trades, too

• Exponential Moving Averages in various time windows

• The Average Convergence Divergence Histogram MACDH.

Let start with the Exponential Moving Average ¯pn,kt : It is calculated for the price p of each asset k in time t and time window n:

¯

pn,kt = pkt · κ + ¯pn,kt−1· (1 − κ) (1)

Where:

κ= 2 n+ 1

The time window n varies, depending on the trend to be identified. Trends that receive most attention in practice are the ones lasting one week, two weeks, four weeks, a quarter of a year and half a year. Note that during a week, there are five trading days. The time window nthus becomes:

n= [5, 10, 20], with p as daily closing prices

n= [12, 26], with pw as the weekly average of closing prices

The most important information of a price trend is included in the m periods slope n,kt :

n,kt = d

³

¯ pn,kt

´

m (2)

Note that m = 1 trading day will be used in all applications. An upward sloping trend indicates a bullish market. The price of the asset (i.e., the consensus of the market participants about the value of the asset) has, on average over the period of observation, been increasing.

Buyers have been optimistic that prices will further rise. Their increased demand has pushed prices up. The opposite is the case in a pessimistic (bearish) market where the trend is downward sloping: Price are expected to sink, demand is decreasing.

pel. It consists of the MACD line and its 9-period exponential average, the so-called signal line .

The MACD line macdkt is calculated by subtracting the 26-period exponential moving average of the closing prices p from their 12-period moving average:

macdkt = pt12,k − ¯pt26,k (3)

The signal line signalkt is obtained as the 9-period exponential average of the MACD line:

signaltk= macdt9,k (4)

To form the MACD - Histogram, the signal line is subtracted from the MACD line:

macdhkt = macdtk − signalkt (5)

The MACD-Histogram indicates the difference between longer-term (signal) and shorter-term (macd) consensus of value of the market participants. The slope of the MACD-Histogram tells us about the dominant market group. It is rising when bulls become stronger, it falls when bears gain strength.

2.2.2 Momentum

The price momentum is calculated as the second difference of the price trend:

mmp,m,n,kt = d³

n,kt ´

m (6)

While the slope of a price trend tells about the market mood, the momentum indicates the development of the mood. An increasing momentum means that bulls are gaining power, while a decreasing momentum hints at the fact that bears become stronger.

2.2.3 Oscillators

Oscillators help identifying turning points of price trends. A price trend may change direction when bulls are unsustainably optimistic or bears overly pessimistic. When market crowds emotionally overshoot, it may pay to trade against them. Oscillators help timing such trades.

The Williams Percentage Range indicator wprtr,kwas developed by Larry Williams in 1973.

It compares the closing price pkt of an asset k in time t to the highest high hr,k and lowest low lr,k in the recent range r.

wprtr,k= pkt − lr,kt

hr,kt − lr,kt

· 100 (7)

The wprr,kt fluctuates between 0 and 100 percent. It reaches 100 percent when bulls are at the peak of their power, and descends to 0 when bears are dominating the market3. Here, the range r = 5 is used, i.e., one week of trading.

Stochastic stochn,m,kt is an oscillator that is based on wprtr,k. It is calculated as the 3-day exponential moving average of the 5-day exponential moving average of wprtr,k:

stoch3,5,kt = percD3,kt (8)

Where:

percD 5,kt = wprr,kt 5,kt

It measures the capacity of bulls or bears to close the market near the upper or lower edge of the recent range r. The closing prices are important, as they settle the trading accounts of the day. If bulls can lift the prices during the day, but fail to close them near the peak, Stochastic turns down. It shows that bulls appear stronger than they are. Inversely, an upturn of Stochastic during a downtrend indicates that bears are weaker than they seem.

3In the original formula of the Williams Percentage Range, bears reached their power at 100, and bulls at 0.

For convenience, the formula has been modified.

Similarly to Stochastic, Accumulation/Distribution tracks the relationship between the price cornerstones of a day (high, low, close). However, it attributes the outcome of the day’s battle between bulls and bears to the winning camp by pondering it with the volume vkt that has been traded. Bulls and bears accumulate or distribute, thus, a part of their power to close the market over time.

adkt = ¡pkt − lkt¢ − ¡hkt − pkt

¢ hkt − lkt

· vtk + adkt−1 (9)

The Chaikin Oscillator, designed by Marc Chaikin, is calculated by subtracting the 10-day exponential moving average of adkt from its 3-day exponential moving average:

cokt = ad3,kt − ad10,kt (10)

It compares the current market power of bulls and bears to their power over the last two weeks.

2.2.4 Indices

The Relative Strength Index rsir,kt has been developed by J.Welles Wilder Jr. It monitors the closing prices over the range r of previous trading days. It is calculated as:

rsir,kt = 100 − 100

1 + rsr,kt (11)

Where:

rsr,kt = P ∆+pr,k

P ∆pr,k (12)

Note thatP ∆+pr,k is the sum of all positive closing price differences in r andP ∆pr,kis the sum of all negative closing price differences in r. The range r of 5 trading days is used. A high Relative Strength Index indicates that bulls have been comparatively strong in the period of range, as they have been able to close the day higher. A low rsi indicates that bears are in

power.

The Force Index has been proposed by Alexander Elder. It combines information contained in closing prices with information of trading volume. It is calculated as the 2-day exponential moving average f i2,kt of f ikt, where:

f ikt

pkt − pkt−1

´

· vkt (13)

The Force Index reflects the outcome of the day’s battle between bulls and bears. High volume gives price changes in favor of bulls or bears weight, while low volume may relativize the importance of the price development.

The Positive Volume Index pvikt intends to filter out the important changes in the closing prices. For this purpose, it tracks the volume of the trading day t relative to the day before.

Only if the traded volume is higher in t, the index is updated:

pvikt =

2.3 Generating Trading Signals from Technical Indicators

The trading signals are generated in three steps:

• Selection of reference measures to compare the Indicators to

• Generation of raw signals by executing the comparison

• Combination of the raw signals using the trading strategy

The selection of reference measures can be summarized as follows: In the case of Trend indicators, observe if the trend slope is positive, turns up or down. Regarding the Momentum, check if they are positive or not. Compare the Oscillators to a pre-defined level, and measure if they turn up or down. When it comes to the Indices, follow the development of their slope.

The raw signal vectors θt are obtained by evaluating the reference measures for all assets k = 1...K in time t. Note that j = 1...J references the j-th vector in the set Θ of all raw signal vectors. A comprehensive overview of the set of all reference measures Θ used in the simulations is given in the Appendix on page48.

Finally, the raw signals are combined according to the trading strategy s. A trading strategy may contain one or several of the Boolean functions AND, OR, IS, NOT. These functions accept as argument(s) elements of the set of raw signals. The result of the strategy are the buy signals ̺Kt

The following example illustrates the above procedure. Assume the following development of two price trends:

day price trend of asset a price trend of asset b

1 1 5

2 2 4

3 5 5

The trend slope becomes:

day trend slope of asset a trend slope of asset b

2 1 -1

3 3 1

Two reference measures are observed:

• Is the price slope positive?

• Has the price slope turned up?

Evaluate if the reference measures are fulfilled. As results, obtain the following Boolean vectors:

θ41,K = [ 1 1 ] θ42,K = [ 0 1 ]

To get the buy signals ̺K4 , evaluate the trading strategy s. The trading strategy is to buy if the price slope has been positive but it has not turned up in the last day. Using the raw signals as input to s, get:

̺K4 = s

³

θ1,K4 , θ42,K

´

̺K4 = AN D

³

θ1,K4 , N OT ( θ2,K4

̺K4 = [ 1 0 ]

In trading day 4, asset a would have been bought, but not asset b.

2.4 Trading Execution

To obtain valid conclusions when testing trading strategies, special attention must be paid to trading execution. The simulations in section4have been designed to be as realistic as possible.

When it comes to the cost associated with trading, one should count, at the Swiss Stock Exchange, with approximately 10 basis points on the traded volume for slippage and commis-sions. To increase the margin for error, this amount is doubled up in the simulations: A cost of 20 basis points is assumed.

Trades are executed as follows:

• In the morning of day t (before the markets open), the raw signal vectors θtj,K are calculated, using the data of t-1 as input.

• The strategy to be tested generates the buy signal vector ̺t that indicates what assets are to be bought during t.

• The execution of the signals is triggered by so-called ’trailing buy stops’. A trailing buy stop indicates a price level at which the buy transaction is executed. If the trailing buy stop lies between the day’s high price and low price, the order is executed. Otherwise, it is cleared from the order books.

The trailing buy stops are set a tick above the level of the previous day’s high price. Only if the intraday prices of the target asset move in the anticipated direction, the trade is executed.

Trailing buy stops have thus the advantages of both defining a precise price level when to enter a trade and providing a certain filtering of the strategy signals.

Another very important aspect of trading execution is the money management. For an in-depth discussion of this aspect, see e.g., Elder (1993). Our money management is built on three pillars:

• Automated stop losses

• Restricted liquidity exposure

• Restricted equity exposure

At the moment of entering a trade, a stop loss order is placed. The stop loss level is set at the lowest low of x previous days. Typically, the horizon for obtaining the stop loss level is slightly larger than for obtaining the trailing buy level. In the simulations, the stop losses are set at the low price of the previous two days, x = 2.

The liquidity exposure by a single trade is restricted to 7 percent. In other words, in one trade cannot buy more of an asset than 7 percent of the current cash in the portfolio.

Equally, the exposure of the equity by one trade is restricted. The maximum amount of

equity mlet that can be lost by one trade of asset k is

mlekt

˜

pkt − slkt

´

· ˜qtk

where ˜pkt is the trailing buy stop (and thus the potential transaction price), ˜qtk the transaction quantity, and slkt the stop loss associated with the trade. The ˜qkt is adjusted to limit the equity exposure to 361 , given the trailing buy stop and the stop loss.

Note that a sound money management does not convert a bad trading system into a gold mine. However, it limits the risk that a good trading system is wiped out because of an adverse price streak.

To limit the risk associated with our portfolio further, a minimal diversification is imposed:

If the value of an asset exceeds 40 percent of the total portfolio value, no further buys of this asset are possible.

2.5 Finding optimal Trading Strategies

In the above examples and explanations, the trading strategy, i.e., the Boolean combination of technical indicators, has been pre-defined. Consider now how to create strategies.

One could try a brute force approach. However, in the case of the simulations to be undertaken, the set of variables Θ comprises 31 elements. The search space is thus vast. A brute force approach that targets to calculate all logical combinations of these indicators would request unrealistically large computational resources. It is thus not an option.

The search space for trading strategies is also unstructured and deceptive, featuring many local optima and minima. Traditional search algorithms such as gradient search are thus condemned to fail, too.

Therefore, I suggest the use of evolutionary algorithms for the creation of trading strategies, as their natural domains are vast, unstructured and deceptive search spaces.

Genetic Algorithms, and variable length solutions like Genetic Programming. Algorithms fea-turing variable length solutions are a better choice here, as neither the size nor the complexity of the optimal trading strategy is known in advance. A fixed length solution approach would either not find the optimal solution (in case the solution size is chosen too small), or it would slow the search unnecessarily down (with too big a solution).

Genetic Programming has an inconvenience, though: Its solutions tend to bloat, i.e., to in-crease in an uncontrolled manner in size during evolution. This code bloat leads to an excessive consumption of machine resources that slows down the search for optimal programs. Given the realistic trading setup, the evaluation of a trading strategy requires massive computational resources. Algorithmic inefficiency is thus highly undesirable.

In the following Section3, I propose an alternative algorithm for the evolutionary creation of programs, an algorithm that does not suffer from bloat: Parse Tree Evolution (PARTE).