p1139 Wilson
p1139 Wilson
1139
traday data, unlike the previous interday results, indicated initialized strategies and typically produced average profits
that the GP did not generate positive excess returns when from -5 to 15%. Hirabayashi et al. [8] analyzed the hourly
factoring in transaction costs. In a very recent work that closing price of USD/JPY and EUR/JPY with data from
examines a number of approaches utilizing technical trading 2005-2008. Their GA system outperformed a neural net-
rules [12] , the authors claim that profitability of particular work, with a GA using leveraged trades performing better
types of trading rules (filter and moving average-based) dis- than a non-leveraged version. Profits using a GA with lever-
appeared during the 1990s, but their returns in [11] (up to aging ranged from less than 10% to over 70% at particular
1995) were genuine. points in the data series.
Dacorogna et al. [3] describe foreign exchange trading
strategies based on research of the well known FOREX trad-
ing firm OANDA using data from the beginning of 1987
3. LGP FOREX TRADING SYSTEM
to the end of 1995. In [3], the authors describe a tree- The algorithm applied to foreign exchange trading in this
based GP system that generated yearly out-of-sample re- work is linear genetic programming (LGP). LGP evolves in-
turns from 3.10% to 6.29% using intraday (hourly) forex dividuals composed of binary strings and associated regis-
data for DEM/USD, JPY/USD, and CHF/USD. Brabazon ters, in contrast to the tree-based individuals of traditional
and O’Neill [1] use a special type of genetic programming GP. The bits that make up on individual can be further di-
that evolves trading rules based on a formal grammar called vided into separate instructions. These instructions can be
Grammatical Evolution (GE). They describe the applica- executed sequentially, with the subresult of each instruction
tion of GE to forex data from an overlapping time period stored in one of the individual’s registers. Each instruction
(interday closing exchange rate from late 1992 to late 1997) performs an operation corresponding to a member of the
using US dollar to DEM, JPY, and GBP. The authors found function set that it references, and uses subresults in regis-
that they were able to generate returns of 0.1% to 5.0% over ters or external data as operands. Thus, each LGP individ-
their test period of 548 days depending on currency. Demp- ual represents a small machine-language type program that
ster and Jones [4] used a GA-based system that evaluated is evaluated by a fitness function upon termination, often
technical indicators every 15 minutes while trading at one by examining a final solution in one of the individual’s reg-
minute intervals. Different optimization variants in their isters. LGP is now considered an established hallmark form
system were tried, and the best strategy was found to re- of GP, and further details of general LGP implementation
turn 7% per annum on the GBP/USD rate from 1993 to can be found in [2].
1997. Linear genetic programming is used by its proponents for
A number of papers have since claimed successful appli- a number of reasons. Firstly, the internal registers used
cation of evolutionary computation to forex trading beyond in LGP individuals provide a way of storing sub-results and
1997. Schwaerzel and Bylander [15] use traditional GP to thus reduce the need to introduce new operators into a func-
analyze GBP/USD and JPY/USD daily rates from the start tion set for the purposes of solving a problem. Considerable
of 1990 to late 2005. Profits of 89% for GBP/USD and 80% flexibility is also provided by LGP, since each instruction in
for JPY/USD were achieved for the 10 year test period, but an LGP individual does not necessarily contribute to the fi-
the authors state that these returns are low for a such a nal result in the individual’s solution register. Due to this
long test period. Hryshko and Downs [9] applied a GA to trait of LGP individuals, redundant and detrimental code
the evolution of entry and exit trading rules, along with rein- can be present in the genome of an individual without af-
forcment learning, to the EUR/USD rate from June 2 to De- fecting the individual’s fitness. In contrast, each node in a
cember 31, 2002 with a five minute frequency. The authors tree-based GP individual contributes to the value found in
found that the system achieved profitability of 7% for the the root node as a solution.
first 2 months out of sample, and 6.5% in the 3.5 months out In this work, we apply a LGP implementation to four forex
of sample. Dempster et al. examined a GA and reinforce- time series in interday frequencies: CAD/USD, EUR/USD,
ment learning-based system in [5] for the foreign exchange GBP/USD, and JPY/USD. An inital period was reserved
market after 1997. They found that the system tended to to establish values of technical indicators, following which
over-fit solutions when examing data for GBP/USD from the GP fitness was evaluated on data corresponding to a
1994 to 1998. The profitability of the results varied con- moving window of 5 days. Individuals represented sets of
siderably based on slippage used. In a subsequent work, trading rules, based on functions in the function set (to be
Dempster et al. [6] implemented a system that attempts to described). For each window of 5 trading days m to n, each
correct their previous issues with overfitting. The system of m to n - 1 days were used for calculation of a trading
produced was a hybrid GA and reinforcement learning sys- decision, with m + 1 to n left for the evaluation of the
tem where the GA evolved a set of indicators provided to recommendation based on the preceding days. Data used
the reinforcement learning component of the algorithm. The for the determination of a trading decision were normalized
implementation was tested on GBP/USD, USD/CHF, and using two-phase preprocessing similar to treatment of stock
USD/JPY rates from 1994 to 1998 (same time frame as their data in [1]: All daily values were transformed by division
previous study in [5]) and produced profitable strategies of using a lagged moving average, and then normalized using
approximately 5% to 15% given higher slippage levels. linear scaling into the range [0, 1] using
Recently, Saks and Maringer [14] examined intraday bid-
ask tick data for the calendar year of 2006, with a sample ap- vt − ln
vscaled = (1)
proximately every minute for USD/EUR. Their implemen- hn − ln
tation took a novel approach involving evolution of trees
where vscaled is the normalized trading value, vt is the trans-
representing combinations of long and short exit and entry
formed trading value at time step t, hn is highest trans-
strategies. The authors’ algorithm outperformed randomly
formed value in the last n time steps, ln is the lowest trans-
1140
08/01/2008,0.9985 Training Window 4. FITNESS EVALUATION
09/01/2008,1.0083 The fitness of a GP individual for trading applications
10/01/2008,1.0139
11/01/2008,1.0198
is often simply how profitable the trading strategy repre-
14/01/2008,1.021 sented by the individual is over time, or some modification
15/01/2008,1.0167 Unknown Value on the measure of that direct profitability. This profitabil-
ity of the individual / trading rules is naturally determined
Figure 1: The LGP trains repeatedly on a window (at least indirectly) by the established technical indicators
of five values with four training cases (four boxes that are members of the function set (typically moving aver-
within the larger grey box). Unknown value is the age, momentum, and others). Another method of creating
price for which the “live” trading system receives a profitable individuals (trading rules) is to modify the fitness
recommendation from the LGP. measure directly. For instance, Saks and Maringer [14] tailor
the fitness function to risk tolerance of traders. Brabazon
and O’Neill [1] suggest considering fitness as direct profit
tempered by the maximum drawdown (maximum cumula-
formed value in the last n time steps, and n is the length of tive loss experienced since the start of the trading period in
the time lag chosen for the initial transformation. question) in order to protect a trading implementation from
In addition to an instruction set, each LGP individual “catastrophic loss.” In particular, return less the cost of max-
possesses four registers, a flag for storing the current value imum drawdown and return divided by maximum drawdown
of logical operators, and an output (trade) register for stor- adjusted by a ratio of winning trades to overall trades are
ing the value corresponding to a trade recommendation fol- suggested in [1] (with no associated results provided for the
lowing execution of the instruction set. If the value of the latter). We examine fitness evaluation using the unmodified
trade register is 0, no trade is conducted. If the value in value of assets held (both USD and alternate currency), di-
the trade register corresponds to a value in the range +/-[0, rect value minus maximum drawdown (Equation 2), and
1], that value is multiplied by a maximum dollar amount direct value simply divided by maximum drawdown (Equa-
to be bought or sold per trade ($100 was used based on a tion 3):
starting balance of $1000 with which to trade) to give some
portion of $100 to be traded. For each trade conducted, f itness = value − maximumdrawdown, (2)
there is a transaction cost of 0.025% and slippage of 0.01%,
as recommended in [1]. In addition, interest is charged for f itness = value/maximumdrawdown. (3)
USD dollars borrowed and interest is earned in the foreign
Equation 2 serves to provide a fitness measure that creates
currency while it is held.
more of an aversion to loss than raw profit evaluation, but
The best individual, consisting of the best trading rule
is not as conservative as 3. We also examined the scaling of
set, is used by a “live” trading algorithm. The live trading
both the value of assets and Equation 2 by a win ratio, as
system provides known information to the LGP for days m
originally suggested in [1]. The win ratio was the number of
to n. The LGP algorithm returns a recommendation for the
successful trades (gain or no loss of overall value) conducted
live trading system, which is used as the basis of its trade
over all trades considered by our moving window. However,
on the following day, n + 1. The net number of units of
due to the nature of our implementation, the win ratio sim-
foreign currency bought and sold by the best evolved in-
ply served to reinforce the same trading decisions made by
dividual (trading rules) given the recommendation of the
simple valuation of assets based on the cumulative trading
trade register over all the fitness cases (4 fitness cases per 5
evaluations at each segment of the moving window. In other
day window) is the buy or sell recommendation to the “live”
words, both simple valuation and simple valuation adjusted
trading system. The best LGP individual can thus recom-
by win ratio–for our particular implementation–generated
mend up to $400 worth of currency selling or buying per
near-identical results for the data series. The adjustment
actual trading day to the live system. With the next win-
of equation (Equation 3) by a win ratio yielded, with a
dow shift, the current currencies held by the “live” trading
high level of consistency, less profitable results across all
system are the new initial amounts for the GP individuals in
exchange rate series. In light of these considerations, we
the next tournament based on the rates in the new window
present results for fitness evaluation using simple valuation
of values. The transactions of the live trading system are
and Equations 2 and 3.
actually based on unknown data and determine the success
of the forex trader. The process is summarized in Figure 1.
The LGP function set includes standard mathematical op- 5. FOREX TRADING RESULTS
erators and logical operators. In addition, established tech- The worth of the assets held by the live trading system
nical analysis metrics such as moving average, momentum, are evaluated for each of 365 days of exchange rates, with
and channel breakout were used. Moving average is the the initial 16 values withheld for seeding of technical indi-
mean of the previous n share prices. The momentum is cators. The rates examined were CAD/USD, EUR/USD,
the ratio of a time-lagged price to the current price. Chan- GBP/USD, and JPY/USD from August 5, 2008 to August
nel breakout typically uses Bollinger bands around a n-day 5, 2009 using daily Bank of Canada [13] nominal noon ex-
moving average of the price at +/- 2 standard deviations of change rates. This time period was arbitrarily chosen but
the price movement over the last n days to alert the trader includes a period of global market correction to demonstrate
of significant movements in rates. Each LGP tournament robustness of the algorithm. Variation across trials was prac-
consisted of 1000 rounds. XOR mutation on individual in- tically non-existent or negligible, so a single arbitrary run is
structions was used with a probability of 0.5, and crossover shown. LGP implementations using the fitness types de-
occurred with a probability of 0.9. scribed in the previous section are evaluated in terms of
1141
opportunities not taken equals proportion of trading where
Table 1: Trading Activity Summary the maximum or minimum was invested). Each fitness type
CAD EUR GBP JPY did have slightly different trading strategies: In the largely
Trading Opportunities not Taken (%) downward trending GBP/USD market (see Figure 2) the
Raw Fitness 30.61 35.78 40.95 28.44 conservative fitness type holds a partially invested position
Moderate 28.88 32.33 35.78 28.87 on approximately 5.6% of days (proportion of trading op-
Conservative 37.93 28.88 38.79 28.87 portunities not taken less proportion of trading where the
Max/Min Invested (%) maximum or minimum was invested). In the initially up-
Raw Fitness 30.60 35.77 39.66 21.98 ward trending JPY/USD market (see Figure 2), the raw
Moderate 28.88 31.90 35.34 25.43 fitness implementation holds a partially invested position for
Conservative 35.34 26.29 33.19 24.57 6.5% of days. To summarize, the systems are very seldom
partially invested when not trading, but partial investment
can occur when fitness is conservative in a downward mar-
ket and when fitness is most agressive in an upward market.
performance trends over time, trading strategies, and final Overall, Table 1 indicates moderate levels of trading where
profit in the subsections that follow. implementations do not act on approximately 29% and 39%
of available trades. Figure 3 (following page) looks complex
5.1 Performance Trends at first glance but contains easily discernible information
Firstly, we examine the ability of the algorithm to trade about underlying trading strategies if the pattern of spikes
over time using the value of its currencies held. Starting indicating assets in and out of the market are examined. As
trading with $1000, the total worth (total value of both non- expected, the number of actions taken by the conservative
USD currency and USD currency) of the live trading system implementation is the lowest, followed by moderate and raw
in the base (USD) currency for the three fitness functions fitness in that order. This can be seen by simply examining
described in the previous section are provided in Figure 2. the number of spikes that each implementation causes from
The value of a total initial investment of funds in the non- a fully invested position (a position of approximately 100%
USD currency net interest differential is indicated as Buy non-USD investment). The conservative fitness type tends
and Hold (and is a direct reflection of the underlying rate), to take a trading action later than the other fitness types,
unmodified value of assets held is labeled Raw Fitness, and but it will do so with a larger amount of capital (as seen by
Equations 2 and 3 are denoted Moderate and Conservative, the general magnitude of spikes).
respectively, to reflect their approximate aversion to risk.
Is it evident from CAD/USD and GBP/USD in Figure 2 5.3 Profitability Analysis
that the conservative fitness measure achieves the greatest The relative performance of each algorithm based on the
profit when there are not extreme changes in value of the for- underlying trading strategy just examined is shown suc-
eign (non-USD) currency. In these cases, the other fitness cinctly in Figures 4 to 7, where the cumulative performance
measures slightly lag behind or outperform buy-and-hold. of all fitness types are compared to that of buy-and-hold over
When the rate volatility involves larger changes over shorter the entire trading period. Bottom, middle, and top of boxes
periods, as in EUR/USD (Figure 2), a moderate adjustment indicate lower quartile, median, and upper quartile values,
by maximum drawdown outperforms the other fitness mea- respectively. If notches of boxes do not overlap, medians of
sures that generally lag behind buy-and-hold throughout the the two sets of data differ at the 0.95 confidence interval.
time period. In the case of fairly consistent climb in value Points are outliers to whiskers of 1.5 times the interquartile
of the foreign currency in relation to USD, all fitness types range. The symbol ‘+’ denotes points from 1.5 to 3 times
work to catch up while anticipating possible indications of the interquartile range, and ‘o’ represents points outside 3
decline, leading to close or sub-par performance compared times the interquartile range.
to buy and hold (JPY/USD, Figure 2). From Figures 4 to 7, it is evident that the conservative fit-
ness outperformed (95% statistical significance) all other fit-
5.2 Trading Analysis ness types in three of the four currency pairs we considered.
All of these performance results are a direct reflection Also, when conservative fitness outperforms the other mea-
of the underlying trading activity of the implementations, sures, it does so by a considerable margin. It appears that
which we now examine. To examine the dynamic trading allowing an increased impact of maximum drawdown on the
strategy of the implementations, we track the percentage of fitness function (in particular, Conservative over Moderate
total worth of each implementation that is kept in the non- or Raw Fitness) is beneficial (with statistical significance)
USD currency at any given time over the time series. To for currency value data that show sustained loss against the
interpret these figures keep in mind that if the algorithm USD with some volatility (CAD/USD and GBP/USD). Fig-
anticipates an opportunity for profit, a higher percentage of ure 5 also shows that a moderate impact of maximum draw-
USD will be placed in the non-USD currency to be sold later down is more appropriate for large value swings in the ex-
at a profit. These results are shown below in Figure 3. The change rate for EUR/USD. Table 2 provides the proportion
actual percentage of trading opportunities not taken and of profitable buys, protective sells, and trades conducted
percentage of trading opportunities where the maximum or (out of all possible trading opportunities). Many works con-
minimum was invested in non-USD currency over the entire sider proportion of profitable trades as a measure of success
time period is summarized in Table 1. for an algorithm applied to market analysis. However, as
It is evident from Table 1 that all fitness types caused the noted in [1], this measure does not even provide insight into
LGP, in general, to typically stop trading only when it was actual profit generated. One reason for this is that many
completely in or out of the market (proportion of trading trades help overall profitability by selling to prevent further
1142
CAD/USD
1100
1000
950
900
EUR/USD
1040
Value of Currency Held in USD ($)
1020
1000
980
960
940
920
900
880
860 Buy and Hold
Raw Fitness
840 Moderate
Conservative
820
0 50 100 150 200
Day
GBP/USD
1050
Value of Currency Held in USD ($)
1000
950
900
850
800
JPY/USD
1250
Value of Currency Held in USD ($)
1200
1150
1100
1050
Figure 2: Mean total value of non-USD and USD currencies held given initial $1000 USD.
1143
CAD/USD
100
80
70
60
50
40
30
20
Raw Fitness
10 Moderate
Conservative
0
0 50 100 150 200
Day
EUR/USD
100
% of Currency Held in non-US Dollars
90
80
70
60
50
40
30
20
Raw Fitness
10 Moderate
Conservative
0
0 50 100 150 200
Day
GBP/USD
100
% of Currency Held in non-US Dollars
90
80
70
60
50
40
30
20
Raw Fitness
10 Moderate
Conservative
0
0 50 100 150 200
Day
JPY/USD
100
% of Currency Held in non-US Dollars
90
80
70
60
50
40
30
20
Raw Fitness
10 Moderate
Conservative
0
0 50 100 150 200
Day
1144
2
15
10
-4
5
-6
-8
0
-10
-12
-5 Raw Fitness Moderate Conservative
Raw Fitness Moderate Conservative
2
Conservative 97.44 97.67 96.15 89.66
0
Protective Sells (%)
Raw Fitness 90.14 92.19 95.24 94.87
-2 Moderate 97.44 92.54 95.65 95.89
Conservative 92.31 93.59 93.65 90.91
-4 Final Profit (%)
Raw Fitness 0.0020 -5.72 -9.13 4.27
-6 Moderate -0.77 2.64 13.14 5.65
Conservative 8.98 -6.59 -2.71 13.44
-8
Raw Fitness Moderate Conservative
Figure 5: Cumulative profit (%) greater than Buy losses. Thus, we use the alternative metrics of profitable buy
and Hold for EUR/USD. and protective sells as introduced in [16]. A profitable buy
is defined as a buy where the total value of currencies held
at a time prior to the next sell exceeds the total value at
10
the time of purchase (less slippage and interest differential).
Similarly, a protective sell prevents further losses and is de-
fined as a sell where the total value of currencies held at a
time prior to the next buy is less than the total value at the
Cumulative Profit (%)
1145
0.002% to 13.44%. Comparable studies of other foreign [6] M. A. H. Dempster and Y. S. Romahi. Intraday fx
exchange trading systems in the literature (using interday, trading: An evolutionary reinforcement learning
non-leveraged rates over periods ranging from a partial year approach. In IDEAL ’02: Proceedings of the Third
up to two years) yielded final profits of 1 to 6% [11], 0.1 to International Conference on Intelligent Data
5% [1], and 6.5% [9]. Our results are thus promising; how- Engineering and Automated Learning, pages 347–358,
ever, it should be noted that final profit depends heavily on London, UK, 2002. Springer-Verlag.
the trading period chosen (especially the arbitrary stopping [7] C. Faith. Way of the Turtle: The Secret Methods that
point) and is not completely comparable across studies. Turned Ordinary People into Legendary Traders.
McGraw-Hill, New York, 2007.
6. CONCLUSIONS [8] A. Hirabayashi, C. Aranha, and H. Iba. Optimization
We examined the application of a linear genetic program- of the trading rule in foreign exchange using genetic
ming (LGP) system to currency trading in the foreign ex- algorithm. In GECCO 2009 Conference Proceedings,
change market, examining the effect of modifications to the pages 1529–1536. ACM Press, July 2009.
fitness function to provide varying degrees of investing con- [9] A. Hryshko and T. Downs. System for foreign
servatism. For the implementation discussed here, which exchange trading using genetic algorithms and
evolves solutions for multiple prior trading days to decide reinforcement learning. Intern. J. Syst. Sci.,
on an action for the immediately proceeding day, an empha- 35(13-14):763–774, 2004.
sis on ratio of winning trades had little or no impact. The [10] C. J. Neely and P. A. Weller. Intraday technical
greatest emphasis on maximum drawdown generated higher trading in the foreign exchange market. Journal of
profits than raw fitness or moderate emphasis on maximum International Money and Finance, 22(2):223 – 237,
drawdown for most trend types. However, moderate fit- 2003.
ness seemed to perform better on the trend with large value [11] C. J. Neely, P. A. Weller, and R. Dittmar. Is technical
changes with high volatility. The overall final profits gener- analysis in the foreign exchange market profitable? A
ated on the time series were competitive with other similar genetic programming approach. The Journal of
studies. The LGP system, regardless of fitness type, gener- Financial and Quantitative Analysis, 32(4):405–426,
ated a very impressive proportion of profitable buys (85% to Dec. 1997.
100%) and protective sells (90 to 97%) with moderate levels [12] C. J. Neely, P. A. Weller, and R. Dittmar. The
of trading (29 to 39% of possible trading opportunities not adaptive market hypothesis: Evidence from the
taken). Future work will examine the success of LGP on foreign exchange market. The Journal of Financial
other types of currency volatility patterns. and Quantitative Analysis, 44(2):223–237, April 2009.
[13] Bank of Canada. http://www.bank-banque-canada.ca.
7. ACKNOWLEDGMENTS [14] P. Saks and D. Maringer. Evolutionary money
WB acknowledges funding from NSERC under the Discov- management. In EvoWorkshops ’09: Proceedings of
ery Grant Program RGPIN 283304-07 and from Canadian the EvoWorkshops 2009 on Applications of
Foundation for Innovation under CFI 204503. Evolutionary Computing, pages 162–171, Berlin,
Heidelberg, 2009. Springer-Verlag.
[15] R. Schwaerzel and T. Bylander. Predicting currency
8. REFERENCES exchange rates by genetic programming with
[1] A. Brabazon and M. O’Neill. Biologically Inspired trigonometric functions and high-order statistics. In
Algorithms for Financial Modeling. Springer Verlag, M. K. et al., editor, GECCO 2006: Proceedings of the
Berlin, 2006. 8th annual conference on Genetic and evolutionary
[2] M. Brameier and W. Banzhaf. Linear Genetic computation, volume 1, pages 955–956, Seattle,
Programming. Springer, New York, 2007. Washington, USA, 8-12 July 2006. ACM Press.
[3] M. Dacorogna, R. Genc.ay, U. Muller, R. Olsen, and [16] G. Wilson and W. Banzhaf. Prediction of interday
O. Picket. An Introduction to High-Frequency Finance. stock prices using developmental and linear genetic
Academic Press, San Diego, 2001. programming. In EvoWorkshops ’09: Proceedings of
[4] M. A. H. Dempster and C. M. Jones. A real-time the EvoWorkshops 2009 on Applications of
adaptive trading system using genetic programming. Evolutionary Computing, pages 172–181, Berlin,
Quantitative Finance, 1:397–413, 2000. Heidelberg, 2009. Springer-Verlag.
[5] M. A. H. Dempster, T. W. Payne, Y. Romahi, and
G. W. P. Thompson. Computational learning
techniques for intraday FX trading using popular
technical indicators. IEEE Transactions on Neural
Networks, 12(4):744–754, July 2001.
1146