23.07.2013 Views

Evaluating automated trading systems using random walk securities

Evaluating automated trading systems using random walk securities

Evaluating automated trading systems using random walk securities

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Evaluating</strong> <strong>automated</strong> <strong>trading</strong> <strong>systems</strong> <strong>using</strong> <strong>random</strong><br />

<strong>walk</strong> <strong>securities</strong><br />

Tomoyasu Oya 1<br />

1 Department of Computer Science and Engineering, Waseda University, Tokyo, Japan<br />

Abstract - <strong>Evaluating</strong> <strong>automated</strong> <strong>trading</strong> <strong>systems</strong> (<strong>using</strong><br />

technical analysis) is sometimes difficult because of curvefitting,<br />

survivorship bias, etc. In this paper, we report our<br />

use of <strong>random</strong> <strong>walk</strong> stocks (GARCH (1, 1) model) to<br />

evaluate <strong>automated</strong> <strong>trading</strong> <strong>systems</strong>. We created three<br />

conditions: an uptrend market, a downtrend market, and an<br />

oscillating market generating 10000 paths <strong>using</strong> the<br />

GARCH model. We applied the simple strategies <strong>using</strong><br />

technical analysis to the <strong>random</strong> <strong>walk</strong> <strong>securities</strong> as future<br />

stock prices. We observed the approximate characteristics<br />

of the <strong>automated</strong> <strong>trading</strong> system in the three conditions.<br />

This approach has a possibility to evaluate the <strong>automated</strong><br />

<strong>trading</strong> <strong>systems</strong> in the same scale regardless of the<br />

complexity of the algorithms.<br />

Keywords: <strong>random</strong> <strong>walk</strong>, <strong>automated</strong> <strong>trading</strong>, technical<br />

analysis, investment science, GARCH model, VaR (Value at<br />

Risk)<br />

1 Introduction<br />

Determining the usefulness of <strong>automated</strong> <strong>trading</strong><br />

<strong>systems</strong> is difficult because of curve-fitting, survivorship<br />

bias, etc. Backtesting is a common way of evaluating these<br />

<strong>trading</strong> <strong>systems</strong>. However, they do not always work because<br />

past market prices differ from future ones.<br />

Past stock prices are about as natural to use as<br />

backtesting. Backtesting describes the past performance of<br />

the <strong>automated</strong> <strong>trading</strong> system well. Frequently, the best<br />

strategy is defined as one that performed the best in<br />

backtesting. However, <strong>using</strong> that strategy does not always<br />

work in actual future <strong>trading</strong>. Also, curve-fitting is a major<br />

problem in backtesting. Determining which strategies overfit<br />

is difficult.<br />

Thus, we created <strong>random</strong>-<strong>walk</strong> <strong>securities</strong> as virtual<br />

future stocks. In actual global markets, some researches<br />

[5][6] refer to the <strong>random</strong>ness of the stock markets these<br />

days. Creating an uptrend market, an oscillating market, and<br />

a downtrend market enabled us to get hold of the<br />

performance and the characteristics in <strong>automated</strong> <strong>trading</strong><br />

(<strong>using</strong> technical analysis). An <strong>automated</strong> <strong>trading</strong> algorithm is<br />

like a black box when it is collected publicly (A Kaburobo<br />

contest [1] is a competition of <strong>automated</strong> <strong>trading</strong> algorithms<br />

between programmers). Using only backtesting based on<br />

past stock prices seems insufficient as an evaluation tool.<br />

We determined the approximate performance of<br />

<strong>automated</strong> <strong>trading</strong> <strong>systems</strong> by <strong>using</strong> <strong>random</strong> <strong>walk</strong> <strong>securities</strong><br />

for the uptrend, oscillating, and downtrend markets.<br />

2 Generating the <strong>random</strong> <strong>walk</strong> <strong>securities</strong><br />

system<br />

We created paths <strong>using</strong> GARCH (1, 1) models. This<br />

method is similar to the Monte Carlo simulation of value at<br />

risk (VaR)[2]. In order to check the usefulness of technical<br />

analysis, GARCH model or other stochastic models were<br />

used[4][7].We used the prices of the Softbank Company in<br />

2006-2007 as sample data. We divided the paths into<br />

uptrend, oscillating, and downtrend markets, and we<br />

backtested some algorithms <strong>using</strong> the <strong>securities</strong> in the<br />

Kaburobo platform (written in JAVA ).<br />

Figure 1 shows our methodology for simulating<br />

backtesting <strong>using</strong> <strong>random</strong> <strong>walk</strong> <strong>securities</strong>.<br />

Figure 1: The methodology for simulating backtesting <strong>using</strong><br />

<strong>random</strong> <strong>walk</strong> <strong>securities</strong>


3 Kaburobo platform<br />

Kaburobo SDK is a programming tool for <strong>automated</strong><br />

<strong>trading</strong> <strong>systems</strong>. This is easy to create the algorithm based<br />

on technical analysis (Ex. RSI, MACD, Bollinger band,<br />

Moving average, etc.) and easy to backtest. We can also<br />

manage the portfolio of the algorithm <strong>using</strong> the Kaburobo<br />

SDK.<br />

4 GARCH model<br />

We chose the GARCH model. GARCH stands for the<br />

generalized autoregressive conditional heteroscedasticity,<br />

and the model is one approach to modeling a time series with<br />

heteroscedastic errors. This model was proposed by Engle<br />

(1982).<br />

The GARCH model describes volatility clustering, which<br />

refers to the observation "large changes tend to be followed<br />

by large changes, of either sign, and small changes tend to be<br />

followed by small changes." Volatility clustering is often<br />

observed in the stock market. The GARCH model<br />

parameters are often estimated <strong>using</strong> the maximum<br />

likelihood estimation.<br />

R = µ + ε<br />

(1)<br />

t<br />

t<br />

ε = σ ( σ > 0,<br />

z is i.<br />

i.<br />

d(<br />

0,<br />

1))<br />

(2)<br />

t<br />

t zt t t<br />

=<br />

p<br />

∑ i t−i<br />

q<br />

∑ j t−<br />

j<br />

j i<br />

i=<br />

1<br />

j=<br />

1<br />

2<br />

2<br />

2<br />

σ ω + β σ + α ε ( ω > 0,<br />

α , β ≥ 0)<br />

(3)<br />

t<br />

The GARCH (p, q) model is described in the above<br />

equations where t R is the return and µ t is the drift and ε t is<br />

the innovation and σ t is the volatility. To simplify<br />

estimating the parameters, we chose the GARCH (1, 1)<br />

model. We chose a normal distribution for this study. A<br />

Student's t-distribution is sometimes applied for describing<br />

the fat tail distribution observed in the stock market. GJR<br />

and EGARCH models are also used.<br />

We selected the GARCH (1, 1) model and estimated its<br />

parameters <strong>using</strong> the maximum likelihood estimation. We<br />

used the prices of the Softbank Company in 2006-2007 as<br />

the sample data.<br />

5 Pre-estimating<br />

First of all, does the GARCH (1, 1) model represent the<br />

prices of the real market?<br />

We determined <strong>using</strong> a statistical method whether the sample<br />

data (the Softbank prices in 2006-2007) were appropriate for<br />

the GARCH (1, 1) model.<br />

5.1 Ljung-Box-Pierce Q test<br />

A Ljung-Box-Pierce Q test determines whether any of a<br />

group of autocorrelations of a time series differs from zero.<br />

The result was that when the lag was 2, 5, 10, 15, or 20<br />

(daily basis), the autocorrelations of a time series were<br />

almost zero.<br />

t<br />

5.2 Engle's arch test<br />

This test provided evidence supporting the GARCH effects<br />

(i.e., heteroscedasticity). We checked whether residuals have<br />

volatility clustering. The results were that GARCH effects<br />

were evident when the lag was 2, 5, and 10 but not when the<br />

lag was 15 or 20.<br />

These tests were implemented by MATLAB[3]. The pvalue<br />

was 0.05.<br />

These results provide what might be a good reason to use<br />

the GARCH model, and the sample data seems sufficient for<br />

the GARCH model.<br />

6 Estimating parameters<br />

We then estimated the parameters <strong>using</strong> the maximum<br />

likelihood estimation.<br />

The estimated parameters are the following.<br />

µ = 0.0001103, ω =0.00028359, β 1 =0.36043,<br />

α 1 =0.20118<br />

7 Creating the paths<br />

We simulated the sample paths <strong>using</strong> the aforementioned<br />

estimated parameters on a daily basis. Figure 2 shows the<br />

paths were replicated 50 times. We created 10000 paths and<br />

divided them into three parts. The upper part of one third of<br />

the observed paths was defined as the uptrend market. The<br />

middle part of one third of the observed paths was defined as<br />

the oscillating market. The lower part of one third of the<br />

observed paths was defined as the downtrend market.<br />

Figure 2 : Generating the paths (replicated 50 times)<br />

8 The strategies<br />

We created seven kinds of strategies. These strategies<br />

consist of the following trends, and the contrarian includes<br />

short selling.<br />

Here are the strategies:<br />

1. When the RSI (10 days) < 30, they enter, when the RSI<br />

(10 days) > 70 they exit. (contrarian)(The strategy 1.)


2. When the RSI (10 days) > 70, they enter, when the RSI<br />

(10 days) < 30 they exit. (trend following) (The strategy<br />

2.)<br />

3. When the prices are down for 4 consecutive days, they<br />

enter, when the prices are up for 4 consecutive days,<br />

they exit. (contrarian)(The strategy 3.)<br />

4. When the prices are up for 4 consecutive days, they<br />

enter, when the prices are down for 4 consecutive days,<br />

they exit. (trend following) (The strategy 4.)<br />

5. When the RSI (10 days) < 30, they enter, when the RSI<br />

(10 days) > 70 they exit. (short selling, trend following)<br />

(The strategy 5.)<br />

6. When the RSI (10 days) < 30, they enter, when the RSI<br />

(10 days) > 70 they exit. (reversal, trend following) (The<br />

strategy 6.)<br />

7. When the moving average (5 days) < the moving<br />

average (14 days)*0.96, they enter, when the moving<br />

average (5 days) > the moving average (25 days)*1.04,<br />

they exit (reversal) (The strategy 7.)<br />

* RSI = Average of the closes on up days/ (Average of the<br />

closes on up days + Average of closes on down days)*100<br />

Strategy 6 and Strategy 7 are a bit complicated. Reversal<br />

<strong>trading</strong> involves the following strategy: When investors have<br />

stocks (a long position) and they have a sell signal, they sell<br />

the stocks and start short selling at the same time. When they<br />

have a short position and they have a buy signal, they buy<br />

stocks back and start to have a long position.<br />

9 The conditions of the strategies<br />

The commission rate is 0.1% a trade. They spend half of the<br />

money on one trade. They are allowed to buy extra positions<br />

when they have another signal. They have an initial amount<br />

of 50,000,000 yen. The initial price of the stock is 2,500 yen.<br />

frequency<br />

0.4<br />

0.35<br />

0.3<br />

0.25<br />

0.2<br />

0.15<br />

0.1<br />

0.05<br />

Buy and hold<br />

-100 -50<br />

0<br />

0<br />

-0.05<br />

50 100 150<br />

profit(%)<br />

Figure 3 : Buy and hold<br />

uptrend<br />

downtrend<br />

oscillating<br />

frequency<br />

0.3<br />

0.25<br />

0.2<br />

0.15<br />

0.1<br />

0.05<br />

-0.05<br />

RSI contrarian<br />

0<br />

-100 -50 0 50 100 150<br />

Figure 4 : RSI contrarian<br />

frequency<br />

0.35<br />

0.3<br />

0.25<br />

0.2<br />

0.15<br />

0.1<br />

0.05<br />

profit(%)<br />

RSI trend following<br />

-100 -50<br />

0<br />

0<br />

-0.05<br />

50 100 150<br />

profit(%)<br />

Figure 5 : RSI trend following<br />

frequency<br />

0.35<br />

0.3<br />

0.25<br />

0.2<br />

0.15<br />

0.1<br />

0.05<br />

Contrarian(4 days)<br />

-100 -50<br />

0<br />

0<br />

-0.05<br />

50 100 150<br />

profit(%)<br />

Figure 6 : Contrarian (4 days)<br />

frequency<br />

0.35<br />

0.3<br />

0.25<br />

0.2<br />

0.15<br />

0.1<br />

0.05<br />

Trend following (4days)<br />

-100 -50<br />

0<br />

0<br />

-0.05<br />

50 100 150<br />

profit(%)<br />

Figure 7 : Trend following (4 days)<br />

uptrend<br />

oscillating<br />

downtrend<br />

uptrend<br />

downtrend<br />

oscillating<br />

uptrend<br />

downtrend<br />

oscillating<br />

uptrend<br />

downtrend<br />

oscillating


frequency<br />

0.35<br />

0.25<br />

0.15<br />

0.05<br />

RSI trend following (short selling only)<br />

0.3<br />

0.2<br />

0.1<br />

0<br />

-100 -50 0 50 100 150<br />

-0.05<br />

profit(%)<br />

Figure 8 : RSI trend following (short selling only)<br />

frequency<br />

0.2<br />

0.18<br />

0.16<br />

0.14<br />

0.12<br />

0.1<br />

0.08<br />

0.06<br />

0.04<br />

0.02<br />

Reversal 1<br />

-100 -50<br />

0<br />

-0.02<br />

0 50 100 150<br />

profit(%)<br />

Figure 9 : Reversal 1.<br />

frequency<br />

0.8<br />

0.7<br />

0.6<br />

0.5<br />

0.4<br />

0.3<br />

0.2<br />

0.1<br />

Reversal 2<br />

-100 -50<br />

0<br />

-0.1 0 50 100 150<br />

profit(%)<br />

Figure 10 : Reversal 2.<br />

uptrend<br />

downtrend<br />

oscillating<br />

uptrend<br />

downtrend<br />

oscillating<br />

uptrend<br />

downtrend<br />

oscillating<br />

Table 1 : The annual average returns and standard deviations<br />

The strategy 1. Average Standard<br />

return(%) deviation(%)<br />

Uptrend 6.34 7.47<br />

Oscillating 0.88 7.30<br />

Downtrend -7.85 8.76<br />

The strategy 2. Average Standard<br />

return(%) deviation(%)<br />

Uptrend 8.24 11.44<br />

Oscillating -1.87 7.42<br />

Downtrend -7.01 6.69<br />

The strategy 3. Average Standard<br />

return(%) deviation(%)<br />

Uptrend 5.46 7.16<br />

Oscillating -0.19 6.98<br />

Downtrend -7.53 7.99<br />

The strategy 4. Average Standard<br />

return(%) deviation(%)<br />

Uptrend 6.43 9.84<br />

Oscillating -1.77 7.08<br />

Downtrend -7.40 6.63<br />

The strategy 5. Average Standard<br />

return(%) deviation(%)<br />

Uptrend -7.36 6.76<br />

Oscillating -2.66 7.08<br />

Downtrending 5.92 9.51<br />

The strategy 6. Average Standard<br />

return(%) deviation(%)<br />

Uptrend 0.78 14.68<br />

Oscillating -4.14 12.43<br />

Downtrending 0.94 13.11<br />

The strategy 7. Average Standard<br />

return(%) deviation(%)<br />

Uptrend 0.23 9.51<br />

Oscillating -2.20 6.22<br />

Downtrending 1.13 8.04<br />

10 Experimental results<br />

The annual returns and volatilities were shown in Table1.<br />

The seven graphs show the results of each algorithm.<br />

1. RSI contrarian(The strategy 1.)<br />

2. RSI trend following(The strategy 2.)<br />

3. Contrarian (4 days) (The strategy 3.)<br />

4. Trend following (4 days) (The strategy 4.)<br />

5. RSI contrarian (short selling only) (The strategy 5.)<br />

6. Reversal 1. (The strategy 6.)<br />

7. Reversal 2. (The strategy 7.)<br />

These numbers are the same as the aforementioned<br />

strategy.<br />

First of all, we considered the RSI contrarian and RSI<br />

trend following strategies. These strategies have a tendency<br />

to link the profit with the original price itself. In short, if the<br />

market is trending upwards, profit will likely increase. If the<br />

market is trending downwards, profit will likely decrease.<br />

We determined a similar situation in the contrarian (4 days)<br />

and trend following (4 days) strategies.<br />

The short selling strategies have a tendency for profit as<br />

opposed to the market price; that is, if there is an uptrend<br />

market, the profit likely decreases. If there is a downtrend<br />

market, the profit likely increases.<br />

These results seem natural. The profits are affected by the<br />

original prices. The difference between the contrarian and<br />

trend following strategies is small. A very simple technical<br />

analysis does not seem superior to a buy and hold strategy in<br />

the <strong>random</strong> <strong>walk</strong> market. But contrarian strategies and trend<br />

following strategies seem to have the different kinds of the<br />

distributions(We can see the difference of the standard<br />

deviations in Table 1).<br />

Now, let's consider the reversal strategies. These strategies<br />

are complicated because they can frequently switch the long<br />

and short positions. As a result, interestingly, the uptrend and<br />

downtrend markets outperform the oscillating market. That is<br />

not so easy to imagine even if we understand the algorithm.


Furthermore, the signal frequency affects the results. A<br />

reversal 1 strategy generates buy and sell signals more<br />

frequently than a reversal 2 strategy. Hence, we explain the<br />

fact that the standard deviation of reversal 2 is smaller than<br />

the reversal 1.<br />

11 Conclusion<br />

We observed the characteristics of <strong>automated</strong> <strong>trading</strong><br />

<strong>systems</strong> <strong>using</strong> <strong>random</strong> <strong>walk</strong> <strong>securities</strong> in uptrend, oscillating,<br />

and downtrend markets. This approach can measure the<br />

approximate risks and returns. Our system can evaluate the<br />

algorithms written in technical analysis, no matter how<br />

complicated they are in the same scale. This approach should<br />

help in decisions making when creating and evaluating<br />

<strong>automated</strong> <strong>trading</strong> <strong>systems</strong>.<br />

12 References<br />

[1] Trade Science. Kaburobo, http://www.kaburobo.jp/.<br />

[2] Philippe Jorion. Value at Risk: The New Benchmark<br />

for Managing Financial Risk, Mcgraw-Hill, 2000.<br />

[3] GARCH Toolbox 2 User’s guide. MATLAB,<br />

http://www.mathworks.com/access/helpdesk/help/pdf_doc/g<br />

arch/garch.pdf.<br />

[4] Lebaron B Brock W, Lakonishok J. Simple technical<br />

<strong>trading</strong> rules and the stochastic properties of stock returns,<br />

Journal of finance, Vol.47, p.1731-1764, 1992.<br />

[5] Paresh Kumar Narayan, R. S. Mean reversion versus<br />

<strong>random</strong> <strong>walk</strong> in G7 stock prices evidence from multiple<br />

trend break unit root tests, Journal of international financial<br />

markets, institutions & money, Vol.17, p.152-166, 2007.<br />

[6] Lee, U. Do stock prices follow <strong>random</strong> <strong>walk</strong>?,<br />

International Review of Economics & Finance, Vol.1, p.<br />

315-327, 1992<br />

[7] Wei Liua, Xudong Huanga, Weian Zheng, Black-<br />

Scholes' model and Bollinger bands, Physica A: Statistical<br />

and Theoretical Physics, Vol.371, p.565-571, March 2006,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!