<< . .

. 19
( : 30)

. . >>

the receiver is tuned, to excite the resonator. Other regions on the band have weak
signals present, and when still other frequencies are tuned in, strong, clear broad-
casts are heard; i.e., the filter™s center (or resonant frequency) corresponds to the
cyclic electrical activity generated by a strong station. What is heard at any spot
on the dial depends on whether the circuits in the radio are resonating with any-
thing, i.e., any signals coming in through the aerial that have the same frequency
as that to which the radio is tuned. If there are no signals at that frequency, then
the circuits are only randomly stimulated by noise. If the radio is tuned to a cer-
tain frequency and a strong signal comes in, the circuits resonate with a coherent
excitation. In this way, the radio serves as a resonating filter that may be tuned to
different frequencies by moving the dial across the band. When the filter receives
a signal that is approximately the same frequency as its resonant or center fre-
quency, it responds by producing sound (after demodulation). Traders try to look
for strong signals in the market, as others might look for strong signals using a
radio receiver, dialing through the different frequencies until a currently broad-
casting station-strong market cycle--comes in clearly.
To further explore the idea of resonance, consider a tuning fork, one with a
resonant frequency of 440 hertz (i.e., 440 cycles per second), that is in the same
room as an audio signal generator connected to a loud speaker. As the audio gen-
erator™s frequency is slowly increased from 401 hertz to 402 to 403, etc., the res-
onant frequency of the tuning fork is gradually approached. The nearer the audio
generator™s frequency gets to that of the tuning fork, the more the tuning fork
picks up the vibration from the speaker and begins to emit its tone, that is, to res-
onate with the audio generator™s output. When the exact center point of the fork™s
tuning (440 hertz) is reached, the fork oscillates in exact unison with the speak-
er™s cone; i.e., the correlation between the tuning fork and the speaker cone is per-
fect. As the frequency of the sound emitted from the speaker goes above (or
below) that of the tuning fork, the tuning fork still resonates, but it is slightly out
of synch with the speaker (phase shif occurs) and the resonance is weaker. As
driving frequencies go further away from the resonant frequency of the tuning
fork, less and less signal is picked up and responded to by the fork. If a large
number of tuning forks (resonators or filters) are each tuned to a slightly differ-
ent frequency, then there is the potential to pick up a multitude of frequencies or
signals, or, in the case of the markets, cycles. A particular filter will resonate very
strongly to tire cycle it is tuned to, while the other filters will not respond because
they are not tuned to the frequency of that cycle.
Cycles in the market may be construed in the same manner as described
above-as if they were audio tones that vary over time, sometimes stronger, some-
times weaker. Detecting market cycles may be attempted using a bank of filters
that overlap, but that are separate enough to enable one to be found that strongly
resonates with the cyclic activity dominant in the market at any given time. Some
of the filters will resonate with the current cyclic movement of the market, while
others will not because they are not tuned to the frequency/periodicity of current
market activity. When a filter passes a signal that is approximately the same fre-
quency as the one to which it is tuned, the filter will behave like the tuning fork,
i.e., have zero lag (no phase shift); its output will be in synchrony with the cycle
in the market. In addition, the filter output will be fairly close to a perfect sine
wave and, therefore, easy to use in making trading decisions. The filter bank used
in our earlier study contained Butterworth band-pass filters, the code of which was
rather complex, but was fully disclosed in the Easy Language of TradeStation.

Butterwo˜h Filters
Butterworth filters are not difftcult to understand. A low-pass Bunenvorthfilter is
like a moving average: It both attenuates higher-frequency (shorter-periodicity)
signals (or noise) and passes lower-frequency (higher-periodicity) signals unim-
peded; in other words, it smooths data. While an exponential moving average has
a stop-band cutoff of 6 decibels (db) per octave (halving of the output for every
halving of the signal™s period below the cutoff period), a 4-pole Butterworth filter
(the kind used in our May 1997 study) has a stop-band attenuation of 18 decibels
per octave (output drops by a factor of 8 for every halving of a signal™s period
below the cut-off period). The sharper attenuation of unwanted higher-frequency
(lower-periodicity) activity with tire Butterworth filter comes at a price: greater lag
and distorting phase shifts.
A high-pass Burrenvorthfilrer is like a moving-average difference oscillator
(e.g., X - MA(X), where X is the input signal): Both attenuate lower-frequency sig-
nals (e.g., trend), while passing higher-frequency signals unimpeded. The attenua-
tion in the stop-band is sharper for the 4-pole Butterworth filter (18 db per octave)
than for the moving-average oscillator (6 db per octave). Both the moving-average
oscillator and the Butterworth high-pass filter produce lead (rather than lag) at the
expense of increased noise (short-period activity) and distorting phase shifts.
If both high-pass and low-pass filters are combined by connecting the output
of the first to the input of the second, a band-pass fifilrer is obtained: Frequencies
that are higher or lower than the desired frequency are blocked. A signal with a
frequency (or periodicity) that falls in the center of the filter™s “pass-band” is
passed with little or no attenuation, and without lag. The phase shifts of the high-
pass (lead) and low-pass (lag) component filters cancel out; this is comparable to
the behavior of the tuning fork, as well as to the MACD, which is actually a rudi-
mentary band-pass filter built using moving averages. Also, like moving averages,
the stop-band attenuation of the MACD is not very sharp. The stop-band attenua-
tion of the Butterworth band-pass filter, on the other hand is very sharp. Because
only a small range of frequencies pass through such a filter, its output is very
smooth, close to a sine wave. Moreover, because the lag and lead cancel at the cen-
ter frequency, there is no lag. Smooth output and no lag? That sounds like the per-
fect oscillator! But there is a catch: Only the filter with a center frequency that
matches the current cyclic activity in the market can be used.
The output from an appropriately tuned filter should be in synchronization
with the cyclic activity in the market at a given time. Such output will be very
smooth, leading to solid trading decisions with few or no whipsaws, and should be
usable in the generation of trading signals. In fact, if a filter is chosen that is tuned
to a slightly higher frequency than the filter with the most resonance, there will be
a slight lead in the filter output, which will make it slightly predictive.
One problem with band-pass filters constructed using Butterworth high- and
low-pass components is the dramatically large phase shifts that occur as the period-
icity of the signal moves away from the center of the pass-band. Such phase shifts can
completely throw off any attempt at trade timing based on the output of the titter

Wavelet-Based Filters
Butterworth filters are not necessarily the optimal filters to use when applying a
filter bank methodology to the study of market cycles. The drawbacks to using
Butterworth filters include the fact that they do not necessarily have the response
speed desired when trading markets and making quick, timely decisions. Problems
with measuring the instantaneous amplitude of a particular cycle are another con-
sideration. And as noted earlier, the phase response of Butterworth filters is less
than ideal. Wavelets, on the other hand, provide an elegant alternative.
The theory of filter banks has recently become much more sophisticated
with the introduction of wavelet theory. On a practical level, wavelet theory
enables the construction of fairly elegant digital filters that have a number of
desirable properties. The filters used in the tests below are loosely based upon the
Moreler wavelet. The Morelet wavelet behaves very much like a localized Fourier
transform. It captures information about cyclic activity at a specific time, with as
rapid a decrease as possible in the influence (on the result) of data points that have
increasing distance from the time being examined. Unlike Butterworth filters,
Morelet wavelets are maximally localized in time for a given level of selectivity or
sharpness. This is a very desirable feature when only the most current information
should influence estimates of potentially tradable cycles. The filters constructed
for the tests below also have the benefit of a much better phase response, highly
important when attempting to obtain accurate market timing in the context of vary
ing cycles. The advanced filters under discussion can easily be used in banks,
employing a methodology similar to the one used in our May 1997 study.
The kind of wavelet-based filters used in the tests below are designed to
behave like quadrature mirrorfilters; i.e., there are two outputs for each filter: an
in-phase output and an in-quadrature output. The in-phase output coincides pre-
cisely with any signal in the market with a frequency that lies at the center of the
pass-band of the filter. The in-quadrature output is precisely 90 degrees out-of-
phase, having zero crossings when the in-phase output is at a peak or trough, and
having peaks and troughs when the in-phase output is crossing zero. In a mathe-
matical sense, the outputs can be said to be orthogonal. Using these filters, the
instantaneous amplitude of the cyclic activity (at the frequency the filter is tuned
to) can be computed by simply taking the square of the in-phase output, adding it
to the square of the in-quadrature output, and taking the square root of the sum.
There is no need to look back for peaks and valleys in the filtered output, and to
measure their amplitude, to determine the strength of a cycle. There is also no need
to use any other unusual technique, such as obtaining a correlation between the fil-
ter output and prices over approximately the length of one cycle of bars, as we did
in 1997. Instead, if a strong cycle is detected by one of the filters in the bank, the
pair of filter outputs can generate a trading signal at any desired point in the phase
of the detected cycle.
Figure 10-l shows a single filter responding to a cycle of fixed amplitude
(origina signal), with a frequency that is being swept from low to high (left to
right on graph). The center of the filter was set to a period of 12. The second line
down from the top (in-phasefilter output) illustrates the in-phase output from the
filter as it responds to the input signal. It is evident that as the periodicity of the
original signal approaches the center of the filter™s pass-band, the amplitude of the
in-phase output climbs, reaching a maximum at the center of the pass-band. As the
periodicity of the original signal becomes longer than the center of the pass-band,
the amplitude of the in-phase output declines. Near the center of the pass-band, the
in-phase output from the filter is almost perfectly aligned with the original input
signal. Except for the alignment, the in-quadraturefilter output (third line) shows
the same kind of amplitude variation in response to the changing periodicity of the
driving signal. Near the center of the filter pass-band, the in-quadrature output is
almost exactly 90 degrees out-of-phase with the in-phase output, Finally, the
fourth line depicts instantaneous power, as estimated from the filter outputs. This
represents the strength or amplitude of cyclic activity in the signal near the center
of the filter pass-band. The curve for instantaneous power is exceedingly smooth,
reaches a peak when the signal has a periodicity matching the tuning of the filter,
and declines thereafter. In the chart, the center of the pass-band appears to occur
at a period of 13, rather than 12, the period to which the filter was set. The reason
for the slight distortion is that the periodicity of the original signal was being
rapidly swept from low to high. Since the filter needs to look back several cycles,
the spectral estimate is distorted. Nevertheless, it seems apparent that trades based
on the filtered output would be highly profitable. The scaling of the y-axis is irrel-
evant; it was done in the manner presented to make the signals appear clearly, at
separate locations, on the chart.
Figure 10-2 depicts the frequency (or periodicity) and phase response of the
filter. In this case, the filter is set to have a center, or pass-band, periodicity of 20.
The relative power curve shows the strength of the output from the filter as the sig-
nal frequency is varied, but held constant in power. The filter passes the signal to
a maximum extent when it has a frequency at the center of the pass-band, and as
the frequency moves away from the center frequency of the filter, the output of the
filter smoothly and rapidly declines. There are no side lobes in the response curve,
and the output power drops to zero as the periodicity goes down or up. The filter
has absolutely no response to a steady trend or a fixed offset-a highly desirable
property for traders, since there is then no need to fuss with de-trending, or any
other preprocessing of the input signal, before applying the filter. The phase
response also shows many desirable characteristics. For the most part, the phase
response is well within +90 degrees within the pass-band of the filter. At the cen-
ter of the pass-band, there is no phase shift; i.e., the in-phase filter output is exact-
ly in synchronization with the input series-a trader timing his trades would
achieve perfect entries. As with the power, the phase response is smooth and
extremely well behaved. Any engineer or physicist seeing this chart should appre-
ciate the quality of these filters. When a similar chart was generated for the
Butterworth band-pass filters (used in our 1997 study), the results were much less
pleasing, especially with regard to the filter™s phase response and offset character-
istics. Severe phase shifts developed very rapidly as the periodicity of the signal
moved even slightly away from the center periodicity of the filter. In real-life cir
cumstances, with imprecisely timed cycles, the phase response of those filters
would likely play total havoc with any effort to achieve good trade timing.
Figure IO-3 shows the impulse response for both outputs from the wavelet
filter pair: the in-quadrature output and the in-phase output. These curves look
almost as though they were exponentially decaying sines or cosines. The decay,
however, is not quite exponential, and there are slight, though imperceptible,
adjustments in the relative amplitudes of the peaks to eliminate sensitivity to off-
set or trend.

Frequency (Period) and Phase Response of a Quadrature Mirror Wavelet Filter Pair





? o.ooo




I sob
In addition to the data provided in the charts, a number of other tests were
conducted using “plasmodes.” A plasmode is a set of data constructed to have the
characteristics that are assumed to exist in the real data. The intention is to test the
ability of some algorithm or analytic technique to properly extract, detect, or ana-
lyze those characteristics. A good cycle-based trading system should be able to do
a good job trading a synthetic data series containing lots of noise and occasional
embedded cycles. If it cannot, there could be no expectation of it trading well in
any real market. The kind of filters used in the tests below perform very well in
tests involving plasmodes.

One way to generate cycle entries is to set up a series of filters, each for a different
frequency or periodicity (e.g., going down a certain percentage per filter throughout
some range or spectrum that will be analyzed). If one of these filters shows strong
resonance, while the others show little or no activity, there is presumably a strong
cycle in the market. An entry is generated by looking at the pair of filter outputs and
buying at the next bar, if the cycle phase is such that a cyclic bottom will occur on
that bar, or selling at the next bar, if a cycle top is evident or would be expected on
that bar, Since the strongest-responding filter should produce no undesirable lag or
phase error, such cyclic entries should provide exceedingly timely signals if the mar-
ket is evidencing cyclic behavior. Attempting to buy cycle bottoms and sell cycle
tops is one of the traditional ways in which cycle information has been used to trade
the markets. Cycle information derived from filter banks, or by other means, can also
enhance other kinds of systems or adapt indicators to current market conditions. An
example of how information regarding the signal-to-noise ratio and periodicity of
the dominant cycle (if there is any) may be used within another system, or to adapt
an indicator to current market conditions, can be found in Ruggiero (1997).

A cycle-based entry of the kind studied below (which attempts to buy bottoms and
sell tops) has several strong characteristics: a high percentage of winning trades,
low levels of slippage, and the ability to capture as much of each move as possi-
ble. This is the kind of trading that is a trader™s dream. The assumption being made
is that there are well-behaved cycles in the market that can be detected and, more
importantly. extrapolated by this kind of technology. It has been said that the mar-
kets evidence cyclic activity up to 70% of the time. Even if clear cycles that lead
to successful trades only occur some smaller percentage of the time, because of
the nature of the model, the losses can be kept small on the failed trades by the use
of tight stops. The main disadvantage of a cycle-based entry is that the market may
have become efftcient relative to such trading methodologies, thanks to the prolif-
eration of fairly powerful cycle analysis techniques, e.g., maximum entropy. The
trading away of well-behaved cycles may hamper all cycle detection approaches.
Since cycle entries of the kind just discussed are countertrend in nature, if the
cycles show no follow-through, but the trends do, the trader can get wiped out
unless good money management practices (tight stops) are employed. Whether or
not a sophisticated cycle analysis works, at least as implemented here, is the ques-
tion to be answered by the tests that follow.

In all tests of cycle-based entry models, the standard portfolio of 36 commodities
is used. The number of contracts in any market at any time to buy or sell on entry
was chosen to approximate the dollar volatility of two S&P 500 contracts at the
end of 1998. Exits are the standard ones in which a money management stop clos-
es out any trade that moves more than one volatility unit into the red, a profit tar-
get limit closes out trades that push more that four volatility units into the profit
zone, and a market-at-close order ends any trade that has not yet been closed out
by the stop-loss or profit target after 10 days has elapsed. Entry rules are specified
in the discussion of the model code and the individual tests. All tests are performed
using the standard C-Trader toolkit. Here is the code implementing the wavelet fil-
ter entry model along with the standard exit strategy:
The code above implements the model being tested. The first significant
block of code specifically relevant to a cyclic trading model initializes the indi-
vidual filters that make up the filter bank. This code is set up to run only on the
fistpass, or when a parameter specifically affecting the computations involved in
initializing the filter bank (e.g., the width parameter) has changed; if no relevant
parameter has changed, there is no point in reinitializing the filters every time the
Model function is called.
The next block of code applies each of the filters in the bank to the input sig-
nal. In this block, two arrays are allocated to hold the filter bank outputs. The first
array contains the in-phase outputs (inphase), and the second contains the in-quad-
rature outputs (inquad). The inputs to the filters are the raw closing prices. Because
the filters ;rre mathematiically optimal, and designed to eliminate offsets and trends,
there is no need to preprocess the closing prices before applying them, as might be
necessary when using less sophisticated analysis techniques. Each row in the arrays
represents the output of a single filter with a specified center frequency or periodic-
ity. Each column represents a bar. The frequencies (or periodicities) at which the fil-
ters are centered are all spaced evenly on a logarithmic scale; i.e., the ratio between
the center frequency of a given filter and the next has a fixed value. The selectivity
or bandwidth (width) is the only adjustable parameter in the computation of the fil-
ter banks, the correct value of which may be sought by optimization.
The usual bar-stepping loop is then entered and the actual trading signals
generated. First, a good, pure cycle to trade is identified, which involves deter-
mining the power at the periodicity that has the strongest resonance with current
market activity (peakpower). The cycle periodicity at which the peak power occurs
is also assessed. If the periodicity is not at one of the end points of the range of
periodicities being examined (in this case the range is 3 bars to 30 bars), one of
the conditions for a potentially good cycle is met. A check is then made to see
what the maximum power (peaknoise) is at periodicities at least 2 filters away
from the periodicity at which peak power occurs If peakpower is more than 1.5
times thepeaknoise (a signal-to-noise ratio of 1.5 or greater), the second condition
for a good cycle is met. The phase angle of that cycle is then determined (easy to
do given the pair of filter outputs), making adjustments for the slice that occurs at
180 degrees in the plane of polar coordinates. The code then checks whether the
phase is such that a cycle bottom or a cycle top is present. A small displacement
term (disp) is incorporated in the phase assessments. It acts like the displacements
in previous models, except that here it is in terms of phase angle, rather than bars.
There is a direct translation between phase angle and number of bars; specifical-
ly, the period of the cycle is multiplied by the phase angle (in degrees), and the
sum is then divided by 360, which is the number of bars represented by the phase
angle. If the displaced phase is such that a bottom can be expected a certain num-
ber of degrees before or after the present bar, a buy is posted. If the phase angle is
such that a top can be expected, a sell signal is issued. The limit and stop prices
are then calculated, as usual. Finally, the necessary trading orders are posted.
Many other blocks of code present in the above listing have not been dis-
cussed. These were used for debugging and testing. Comments embedded in the
code should make their purpose fairly clear.

Only one model was tested. Tests were performed for entry at the open (Test I),
entry on a limit (Test 2), and entry on a stop (Test 3). The rules were simple: Buy
predicted cycle bottoms and sell predicted cycle tops. Exits took place when a
cycle signal reversed an existing position or when the standard strategy closed out
the trade, whichever came first. This simple trading model was first evaluated on
a noisy sine wave that was swept from a period of about 4 bars to a period of about
20 bars to verify behavior of the model implementation. On this data, buy and sell
signals appeared with clockwork precision at cycle tops and bottoms. The timing
of the signals indicates that when real cycles are present, the model is able to
detect and trade them with precision.
Table 10-l contains the best in-sample parameters, as well as the perfor-
mance of the portfolio on both the in-sample and verification sample data. 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: WIN% = the
percentage of winning trades; $TRD = the average profit/loss per trade; BARS =
the 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. Two parameters were optimized. The first (PI) represents the
bandwidth for each filter in the filter bank. The second parameter (P2) represents
the phase displacement in degrees. In all cases, the parameters were optimized on
the in-sample data by stepping the bandwidth from 0.05 to 0.2 in increments of
0.05, and by stepping the phase angle displacement from -20 degrees to +20
degrees in increments of 10 degrees. Only the best solutions are shown.
It is interesting that, overall, the cycle model performed rather poorly. This
model was not as bad, on a dollars-per-trade basis, as many of the other systems test-
ed, but it was nowhere near as good as the best. In-sample, the loss per trade was
$1,329 with entry at open, $1,037 with entry on limit, and $1,245 with entry on stop.
The limit order had the highest percentage of wins and the smallest average loss per

Portfolio Performance with Best In-Sample Parameters on Both In-
Sample and Out-of-Sample Data
trade. The long side was slightly profitable with entry at open, was somewhat more
profitable with entry on limit, and lost with entry on stop. The behavior out-of-sam
ple, with entry at open and on limit, was a lot worse than the behavior of the model
in-sample. The loss per trade grew to $3,741 for entry at open and to $3,551 for
entry on limit. The percentage of winning trades also declined, to 34%. The per-
formance of the cycle model on the verification sample was among the worst
observed of the various models tested. The deterioration cannot be attributed to
optimization: Several other parameter sets were examined, and regardless of
which was chosen, the cycle model still performed much worse out-of-sample.
With entry on stop, the out-of-sample performance did not deteriorate. In this case,
the loss ($944) was not too different from the in-sample loss. Although the stop
order appears to have prevented the deterioration of the model that was seen with
the other orders, in more recent times the system is a loser.
The decline of system performance in recent years was unusually severe, as
observed from the results of the other models tested. One possible reason may be
the recent proliferation of sophisticated cycle trading tools. Another explanation
might be that major trading firms are conducting research using sophisticated
techniques, including wavelets of the kind studied here. These factors may have
contributed to making the markets relatively efficient to basic cycle trading.
Table 10-2 shows the in-sample and out-of-sample behavior of the cycle
model broken down by market and entry order (test). The SYM column represents
the market being studied. The center and rightmost columns (COUhrr, contain the
number of profitable tests for a given market. The numbers in the first row repre-
sent test identifiers: 01, 02, and 03 represent entry at open, on limit, and on stop,
respectively. The last row (COUNT) 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,000; two plus-
es (++) indicate a large gain per trade, i.e., $2,000 or more; and a blank cell

<< . .

. 19
( : 30)

. . >>