<< . .

. 23
( : 30)

. . >>

tion (the chromosome it provided) was. This allows the genetic optimiz-
er component to update the population of chromosomes it maintains.
7. If the solution meets certain criteria, generate performance summaries
and other information, and save this data to a file for later perusal.
8. Repeat the above steps again and again until a sufficient number of
“generations” have passed.
As the above steps are repeated, the solutions, i.e., the “guesses” (actually, “off-
spring”), provided by the genetic optimizer, will get better and better, on average.
Because of the way the genetic process works, large numbers of distinct, yet effec-
tive, solutions will emerge during the evolutionary process. Most of the solutions
will have been recorded in a tile generated in the course of repeatedly performing
the first seven computational steps. In the “Code” section of this chapter, a dis-
cussion can be found of some of the C++ code that actually implements the
above steps, including the instantiation and computation of the rules.
Because of the nature of the rules, asymmetries are likely. Consequently,
long entry models are evolved and tested separately from short entry models.
Model performance is evaluated on the entire portfolio. The goal is to find a set of
rules that, when applied in the same way to every tradable, produce the best over-
all portfolio performance. The procedure being used here differs from the one in
our earlier investigation (Katz and McCormick, February 1997) where sets of
rules, specific to each of several markets, were evolved, an approach that was
much more subject to the effects of curve-fitting. As observed with several other
models that were originally tested on individual tradables, some performance may
be lost when requiring a common model across all markets without market-spe-
cific optimization or tuning. In the tests that follow, the standard C+ + software
platform, as well as the standard entry orders and exit strategy, are used.
EventPresent Cint *es. int m, int cb) (
static int
// Used by the Rules function to simplify coding
int i ;
forti=cb-m+l; ic=cb; i++)
CHAPTER 12 Genetic Algorithma:
,, instruct Simulator to employ standard exit strategy
tmp = exitatr[cbl ;
tS.StdeXitdSC'X', ptlim*tmp, mmstp*tmp, maxholdi ;

) /I process next bar

The Cf + code implements the rule templates and system trading strategy. The
function Rules implements the rule templates. Arguments vl, ˜2, ˜3, and v4
(which correspond to the four numbers that comprise any one of the three genes)
provide all the information required to instantiate a rule template. Argument vl is
used to select, via a “switch statement,” the required rule template from the 10 that
are available; arguments ˜2, ˜3, and ˜4, are used to till in the blanks (required
parameters, desired directions of comparison, etc.) to yield a fully defined rule.
The rule is then immediately evaluated for all bars, and the evaluations (1 for
TRUE, 0 for FALSE) are placed in ans, a floating-point vector used to return the
results to the caller.
The macro, BiasedPosScaZe(x,n), is used to map numbers ranging from 0 to
1,000 to a range of 0 to a, with more numbers mapping to smaller values than
larger ones. The macro is used to compute such things as lookbacks and moving-
average periods from ˜2, ˜3, or ˜4, the values of which are ultimately derived
from the genetic algorithm and scaled to range from 0 to 1,000. The macro is non-
linear (Biased) so that a finer-grained exploration occurs for smaller periods or
lookbacks than for larger ones. For example, suppose there is a moving average,
with a period that ranges from 2 to 100 bars. The intention is to search as much
between periods 2, 3, and 4 as between 30, 50, and 90; i.e., the scale should be
spread for small numbers. This is desired because, in terms of trading results, the
change from a 2.bar moving average to a 5-bar moving average is likely to be
much greater than the change from a 50-bar to a 60.bar moving average.
The macro, LinearScnle(x,a,b), performs a linear mapping of the range 0
1,000 to the range a b. The macro is usually used when calculating
thresholds or deviations. In the rule template code, all parameters are scaled
inside Rules, rather than inside the GA as is the usual practice. The GA has
been instructed to produce numbers between 0 and 1,000, except for chromo-
some elements 1, 5, and 9, which are the first numbers in each gene, and which
serve as rule template selectors. The reason for local scaling is that templates
for different kinds of rules require parameter and control values having differ-
ent ranges to be properly instantiated.
The process of evolving trading systems involves asking the genetic opti-
mizer to provide a “guess” as to a chromosome. The genetic optimizer then ran
domly picks two members of the population and mates them (as specified by the
crossover, mutation rate, and chunk-size properties). The resultant offspring is
then returned as a potential solution. When the GA component is told the fitness
of the solution it has just provided, it compares that fitness with that of the least-
fit member of the population it maintains. If the fitness of the offspring is greater
than the fitness of the least-fit member, the GA replaces the least-fit member with
the offspring solution. This process is repeated generation after generation, and is
handled by the shell code (not shown), which, in turn, makes repeated calls to
function Model to simulate the trading and evaluate the system™s fitness.
The code for function Model is almost identical to that used in earlier chap-
ters. Prior to the bar indexing loop in which trading orders are generated, the func-
tion R&s is invoked three times (once for each gene), with the results being
placed in time series rulel, ruZe2, and n&3. A 50.bar average true range is also
calculated, as it is necessary for the standard exit and for rule evaluation. Inside
the loop, the rule evaluations are checked for the current bar (ndel[cb], rule2[cb],
ruZe3[cb]), and if all evaluations are TRUE, a buy (or a sell, if the short side is
being examined) is generated. Entries are programmed in the standard manner for
each of the three orders tested. Only the in-sample data is used to in the evolu-
tionary process.
The output produced by the shell program permits the selection of desirable
solutions that may be traded on their own or as a group. The solutions may be eas-
ily translated into understandable rules to see if they make sense and to use as ele-
ments in other systems.

Six tests were performed. The evolutionary process was used to evolve optimal
entry rules for the long and short sides with each of the three entry orders: at open,
on stop, and on limit. In all cases, a maximum of 2,500 generations of genetic pro-
cessing was specified. The task of computing all the solutions and saving them to
tiles took only a few hours on a fast Pentium, which demonstrates the practicality
of this technique. For each test, the genetic process produced a tabular file (GFiles
1 through 6) consisting of lines corresponding to each of the generations; i.e., each
line represents a specific solution. Most of the early solutions were close to ran-
dom and not very good, but the quality of the solutions improved as generations
progressed; this is normal for a GA. Each line contains information regarding the
performance of the particular solution that corresponds to the line, as well as to the
complete chromosome, i.e., the set of parameters that represents the gene, which,
in turn, corresponds to the solution expressed in the line.
The best solutions for the long entry at open and for the short entry at open
were selected. These solutions were used to generate the six tests conducted
below. More specifically, the solution that provided the best long entry at open was
tested and its performance was evaluated in the usual way on both samples. The
same solution was also tested and evaluated with entry on stop and on limit. The
same procedure was followed for the short side: The best evolved solution for a

short entry at open was determined. It was then tested on both samples with each
of the other two order types, The optimal solution for each order type was not
selected separately from our genetic runs because doing so would not allow com-
parability across orders. For example, the optimal entry at open might involve a
breakout, while the optimal entry for a stop might involve countertrend momen-
tum-totally different models. By assuming that the entry-at-open model (in
which all trades generated by the model are taken) represents a good, overall
model, the normal course of evaluating that model with the other orders was fol-
lowed. Since the model is kept constant, this approach permits meaningful com-
parisons to be made across orders.

Solutions Evolved for Long Entries
Table 12-I furnishes some of the performance data for the top 20 solutions for
long entries at the open (GFile 1). Each line represents a different trading model.
The parameters are not shown, but the line or generation number (LINE), the
probability or statistical significance (PROB, the decimal point is omitted but
implied in the formatting of these numbers), the average dollars-per-trade
($TRD), the total number of trades taken (TRDS), the profit factor (PFAC™), the
annualized return-on-account (%ROA), and the net profit or loss (NET) in raw
numbers are provided.

The Top 20 Solutions Evolved for Long Entries at the Open
The performance of most of these models is nothing short of impressive. The
better models are statistically significant beyond the 0.00007 level, which means
these solutions have a very high probability of being real and holding up in the
future. Many of the returns were greater than 50% annualized. In some cases, they
reached much higher levels. While the limit order had many of the best solutions,
all orders had many good, if not great, solutions. As in OUT earlier study, the GA
succeeded admirably in finding many tradable models.

Solutions Evolved for Short Entries
Table 12-2 provides a small proportion of GFtile 4, the file for evolved models
generated for short entries at the open. As in Test 1, the top 20 solutions, in terms
of statistical significance or risk-to-reward ratio, are presented. Again, it can be
seen that there were many good solutions. However, they were not as good as
those for the longs. The solutions were not as statistically significant as for the
longs, and the return-on-account numbers were somewhat smaller. A somewhat
more distressing difference is that, in most cases, the number of trades was very
small; the models appear to have been picking rare events. All else aside, the evo-
lutionary process was able to find numerous, profitable rule sets for the short


The Top 20 Solutions Generated for Short Entries at the Open
Test Results for the Standard Portfolio
The best solution shown in Table 12-1 (long trades) and the best solution from
Table 12-2 (short trades) were run with all three entry orders. Tests 1 through 3
represent the best evolved model for long entry at the open tested with entry at
open, on limit, and on stop (respectively). Tests 4 through 6 represent the best
evolved model for short entry over all three orders. Table 12-3 contains the per-
formance data for the best evolved entry-at-open models, both long and short, on
the optimization and verification samples using each of the three entry orders. In
the table, SAMP = whether the test was on the optimization sample (IN or OUT);
ROA% = the annualized return-on-account; ARRR = the annualized risk-to-
reward ratio: PROB = the associated probability or statistical significance; TRDS
= the number of trades taken across all commodities in the portfolio; WZN% = the
percentage of winning trades; $TRD = average profit/loss per trade; BARS = the


Performance of the Best Evolved Entry-at-Open Model on the
$Jeyzation and Verification Samples with Each of the Three Entry

Test 03 Short entry-at-open model, entry on stop
IN / 23.11 0.6oI 0.0311
OUT 1 -13.01 -0.251 0.W 131 30
average number of days a trade was held, NETL = the total net profit on long
trades, in thousands of dollars; and NETS = the total net profit on short trades, in
thousands of dollars.

Tests 1 through 3: Long-Entry-At-Open Model Tested with Entry at Open, on
Limit, and on Stop. As can be seen in Table 12-3, the entry model produced by
the evolutionary process was profitable across all three order types, both in-sam-
ple (as would be expected given the optimization power of GAS) and out-of-sam-
ple. In-sample, no return was less than 42% (annualized) for any order. The
dollars-per-trade figures were all greater than $14,000, and not one system had
less than 60% wins! Out-of-sample, there was more variation. With entry at open
and on limit, performance continued to be stellar, with the average trade above
$10,000 and the return on account above 60%. With a stop order, performance was
not quite as good: The return on account was only 11%, and the average trade
yielded $4,246. The only distressing aspect of the results is the small number of
trades taken. For example, in-sample, with entry at open, there were only 43 trades
taken over a lo-year span on a portfolio of 36 commodities. Out-of-sample, there
were only 17 trades over a 5-year period; the trading frequency was roughly con-
stant at approximately 4 trades per year.
The rules were apparently detecting unusual (but tradable) market events; the
model engaged in what might be termed “rare event trading,” which is not neces-
sarily a bad thing. An assortment of systems, each trading different rare events,
could yield excellent profits. When working with a system such as this, trading a
portfolio of systems, as well as a portfolio of commodities, would be suggested.
In the current situation, however, few trades would place the statistical reliability
of the findings in question. The entire problem can be dealt with by using a some-
what more complex way of handling larger combinations of rules.

Tests 4 through 6: Short-Entry-at-Open Model Tested on Entry at Open, on
Limit, and on Stop. In all cases, the performance of the best evolved short entry
at open model, when tested over the three order types, was poorer on the in-sample
data than the long model. Out-of-sample, the results deteriorated significantly and
losses occurred. Unlike the long model, this one did not hold up. It should be noted,
however, that if both the long and short models had been traded together on out-of-
sample data, the profits from the long side would have vastly outweighed the loss-
es from the short side; i.e., the complete system would have been profitable. The
pattern of longs trading better than shorts is a theme that has been recurrent
throughout the tests in this book. Perhaps the pattern is caused by the presence of
a few markets in the standard portfolio that have been in extreme bullish mode for
a long time. The way commodities markets respond to excess supply, as contrasted
to the way they respond to shortages, may also help explain the tendency.
Market-by-Market Test Results
Table 12-4 contains the market-by-market results for the best evolved entry-at-
open models, both long and short, tested on the optimization and verification
samples using each of the three entry orders. Given the small number of trades
taken, many of the empty cells in this table simply reflect the absence of trades.
The SYM column represents the market being studied. The center and rightmost
columns (CO(/NT) contain the number of profitable tests for a given market. The
numbers in the first row represent test identifiers: 01, 02, and 03 represent tests
with entry at open, on limit, and on stop, respectively, for the long side; 04, 05,
and 06 represent corresponding tests for the short side. The last row (COtrAV™)
contains the number of markets on which a given model was profitable. The data
in this table provides relatively detailed information about which markets are and
are not profitable when traded by each of the models: One dash (-) indicates a
moderate loss per trade, i.e., $2,000 to $4,000; two dashes (--) represent a large
loss per trade, i.e., $4,000 or more; one plus sign (+) means a moderate profit per
trade, i.e., $1,000 to $2,ooO; two pluses (+ +) indicate a large gain per trade, i.e.,
$2,000 or more; and a blank cell means that the loss was between $0 and $1,999
or the profit was between $0 and $1,000 per trade. (For information about the var-
ious markets and their symbols, see Table II-1 in the “Introduction” to Part II.)

Tests 1 through 3: Long-Emiy-at-Open Model Tested on Entry at Open, on Limit,
and on Stop. Table 12-4 indicates that, in-sample, the model was strongly profitable
for the NYFE (but not the S&P X0), the British Pound, the Deutschemark, the
Japanese Yen, Palladium, most of the Wheats, Kansas Wheat, Cocoa, and Lumber,
and Light Crude (if entry at open is omitted). Out-of-sample, the NYFE had no
trades, the British Pound and the Deutschemark continued to be strongly profitable
across all three order types, and many of the other markets in which strong in-sample
profitability was observed had no trades. Out-of-sample, some markets that had not
traded in-sample traded profitably (especially Unleaded Gasoline, Silver, and
Coffee), which indicates that the model continued to perform well, not merely in a
different time period, but on a different set of markets.

Testi 4 through 6: Short-Entry-at-Open Model Tested on Entry at Open, on Limit,
and on Stop. In-sample, the T-Bills, the Deutschema& the Swiss Franc, the
Canadian Dollar, Pork Bellies, Oats, Kansas Wheat, Orange Juice, and Lumber all
showed strong profits. The British Pound and Deutschemark held up out-of-sample.
The Swiss Franc was profitable out-of-sample, hut only with the limit order. It lost
when entry was at open or on stop. The other markets either did not trade out-of-sam-
ple or had losses. Out-of-sample, the NYFE traded strongly profitably across all three
order types, but did not trade profitably in-sample.
Figure 12-1 depicts portfolio equity growth for long trades taken with entry
at open. As is evident, there was a steady, stair-like growth in equity, the stair-like
Breakdown of Performance By Market and Test
Portfolio Equity Growth for Long Model with Entry at the Open

quality resulting from the small number of trades taken. The occasional, strongly
profitable trade caused a sudden step up in equity. The least-squares line fitted to
the equity curve reveals consistent growth in both samples, but slightly greater in
the early years.
The equity growth for the long model with entry on limit, which helps to
control transaction costs, is shown in Figure 12-2. Again, the stair-like growth
in equity is apparent. However, the equity growth was more even; i.e., there was
no slowing down of growth in recent year-in fact, the fitted line is almost
straight. Out-of-sample performance was almost identical to in-sample perfor-
Figure 12-3 shows portfolio equity growth for the best evolved short-entty-
at-open model, evaluated with entry actually at the open. Again, the stair-like
appearance is present. However, except for a strong spurt of growth between
August 1989 and June 1993, the curve is essentially flat. Overall, the equity was
seen rising, except for the flat regions.

Portfolio Equity Growth for Long Model with Entry on a Limit

The Rules for the Solutions Tested

for Long Entry.
Rules The chromosome that represented the best solution for
long entries at the open contained three genes. Each gene was composed of four
numbers and corresponded to a specific rule.
The numbers for Gene 1 were 4, 850,65, and 653, which specified an open-
interest decline rule (case 4), a look-back of 34, and a threshold of 0.042, respec-
tively. The last number (653) was not used or translated because the rule did not
require three blanks to be filled in, only two. If this information is taken and trans-
lated into plain language, the rule says that the open interest must decline at least
4.2% over the past 34 bars for the rule to evaluate as TRUE. In other words, the
open interest 34 bars ago (relative to the current bar) minus the open interest 1 bar
ago, divided by the open interest 34 bars ago, was greater than 0.042.
The numbers for Gene 2 were 1, 256, 530, and 709. The fust number (1)
specified a simple price comparison mle (case I). When the additional numbers
were translated to the correct lookbacks and thresholds, it is apparent that this rule
fires (evaluates as TRUE) when the close 3 days ago is greater than the close 14
days ago plus 3.46 times the average true range.
Porlfolio Equity Growth for Shot-l Model with Entry at the Open

The numbers for Gene 3 were 5, 940, 47, and 610. Rule template 5 (case 5),
which is the open-interest incline rule, was specified by the first number. Fully
instantiating this rule reveals that the rule evaluates as TRUE if the market™s open
interest has risen at least 5.6% in the past 44 days.
If the conditions for all three rules, specified by Genes 1 through 3, were met
on a given bar, a buy signal was generated.
It is interesting that two rules involved open interest, a variable not usually con-
sidered in many popular approaches to trading. It is also noteworthy that the two
open-interest rules, when put together, seem almost contradictory: The current open
interest had to be greater than the open interest 44 bars ago, but less than the open
interest 34 bars ago. The model appears to be somewhat trend-following in that a
recent closing price had to be greater than an older closing price before an entry was
taken. However, time was left for a small pull-back; i.e., the increase in price only had
to be observed 3 bars ago, not in the current bar. The set of rules is not one that would
be easy to discover in a normal manner, without the aid of a genetic algorithm.

Rules for Shorf Enfry. A similar analysis can be done for the shorts as for the
longs. The numbers corresponding to the chromosome that represented the best
solution for short entries at the open were 5, 890, 391, and 532 (Gene 1); 5,705,
760, and 956 (Gene 2); and 10, 163,999, and 196 (Gene 3). When the string of
three genes was translated, it was revealed that two rules deal with open interest
and one with the MACD oscillator. The first open-interest role states that the
open interest 1 bar ago must be at least 38% greater than the open interest 38
bars ago. The second open-interest rule states that the open interest 1 bar ago
must be at least 75% greater than the open interest 25 bars ago. The third rule
states that the slope of the MACD-with a shorter moving average length of 2
and a longer moving average length of 50-must be down, suggesting a current
downward trend. If the conditions for all three rules, specified by the three
genes, were met on a given bar, a sell signal was generated. Again, these rules
would not have been easily discovered when developing a trading model in a
more traditional manner.

As was the case in our earlier study, the use of a GA to select and instantiate rule
templates continued to work well as a means of developing a trading system, or,
at least, an entry model. Results were still impressive, despite such problems as
inadequate numbers of trades in many of the solutions generated. The approach is
certainly one that can serve as the basis for further development efforts. In this
exercise, only a small base of rule templates, involving such fairly simple elements
as price comparisons, moving averages, and indicators, were used. Undoubtedly,
much better results could be obtained by using a more sophisticated and complete
set of role templates as grist for the genetic mill.


. Long positions tend to perform better than short positions for the markets
in our standard portfolio and with the models that were tested. Therefore,
it is probably more worthwhile to place development efforts on a system
that emphasizes the long rather than short side.
. Genetic algorithms appear to be an effective means of discovering small
inefficiencies that are buried in a mountain of efficient market behaviors.
n When used correctly, and in such a manner as discussed above, overopti-
mization (curve-fitting) does not seem to be a serious problem, despite
the optimization power of genetic algorithms. Restrictions on the number
and complexity of the rules in any solution seems to be the key element
in controlling the curve-fitting demon.
. Evolution, as used herein, has the great benefit of producing explicit rules
that can be translated into plain language and understood. Unlike neural
network systems, the trading rules produced by GAS are not hidden in an
inscrutable black box.
. Using genetics in the manner described above has the benefit of produc-
ing a large number of distinct, yet profitable, solutions. It would be easy
evolve and then put together a portfolio of systems.


I n Part II, the focus was on the timing of trade entries. The extent to which various

<< . .

. 23
( : 30)

. . >>