Cycle Period Estimation Using Hilbert Transforms Steven C. Rogers, Member, EE-Pub Abstract The random walk model of the market suggests two major market modes: trend mode and cyclic mode. If the market were in the cyclic mode the trader would like to estimate the cycle period to improve his performance. One class of cycle period estimation uses the Hilbert operation to convert signals to real and imaginary components for further processing. These components can be used to estimate cycles. These approaches are developed and demonstrated on end-of-day data from an index.
Article Information Field of Study—DSP Keywords—financial-trending Hilbert-transform Cycle-period-estimation frequencybased-analysis
I. INTRODUCTION There is much interest in utilizing cycle period estimation in improving trading performance. However, there are obstacles to simplistic estimation of cycle periods including noisy data, multiple sinusoids, and data window issues. These problems have been the subject of research in signal processing and control applications for decades1-4. One approach for frequency estimation involves the Hilbert transform1-5. The Hilbert transform is a procedure that transforms ordinary price data to complex values (a number composed of a real and an imaginary part). The real component is called inphase and the imaginary is called quadrature. Once the inphase and the quadrature components are calculated there are several ways to estimate cycles, including: 1) phase accumulation, 2) homodyne discriminator, and 3) dual differentiator. These will be explained in the following section.
II. HILBERT TRANSFORM CYCLE ESTIMATION TECHNIQUES One useful approach toward cycle estimation is to use a Hilbert transform5,6 to generate an inphase (real-Re) component and a quadrature (imaginary-Im) component. With the inphase and quadrature components determined there are at least three ways to estimate cycles: 1) phase accumulation, 2) homodyne discriminator, and 3) dual differentiator. In the phase accumulationapproach the phase is taken at each sample as: phase = tan -1 (abs (Im/Re)). Then a delta phase is computed by taking the difference between the current and most recent phase. When the sum of delta phases reaches 360 degrees a complete cycle is achieved. One can estimate and smooth the cycle at each sample instant. The homodyne discriminatorapproach has us multiply the current measurement with the complex conjugate of the previous measurement as.
Thus, we get the signal squared and the angular frequency, which can be used to easily solve for the cycle period. The above equation shows the concept; the actual calculations are performed using the quadrature and inphase components determined from a Hilbert transform. The dual differentiatorapproach is as simple as the above. It is based on the fact that the angular frequency is the rate change of the phase
Thus, we have as the angular rate
III. IMPLEMENTATION In figure 1 the simulink block diagram is given for the phase accumulation method. The inputs of the 1st block are Price and Period. The outputs are Q1 (quadrature) and I1 (inphase). Each of the three methods begins with the calculation of the inphase and quadrature components of the signal by use of a Hilbert transform as shown in Figure 2.
Figure 1 Simulink Block Diagram of the Phase Accumulation Method The price data is first passed through a simple moving average filter for smoothing. It is weighted toward more recent data to reduce the amount of lag in the filter. Hilbert transform filters are shown in simulink blocks Hilbert1 and Hilbert in Figure 2. Although higher precision may be obtained by using a higher order filter, smaller filters cause fewer lags. The Hilbert transform coefficients were obtained by matching a desired frequency response (0 at 0 Hz and 1 near midrange).
Figure 2 InphaseQuadPhAccum Simulink block for creating inphase and quadrature Passing them through low-pass filters smooths the signals Q1 and I1. The change in phase is calculated in the Figure 1 block phaseCalc.
Figure 3 Period calc simulink block A simulink block diagram for the homodyne discriminator approach is in Figure 4.
Figure 4 Homodyne Discriminator simulink block diagram As in Figure 1 the 1st step is to calculate the inphase and quadrature components. The next step is an additional Hilbert transform to compute jQ and jI. These are manipulated in ReImCalc, shown in Figure 5, to obtain Re and Im, which are the real and imaginary signal components.
Figure 5 ReImCalc simulink block diagram where the real and imaginary components are calculated
The cycle period is then calculated in the block called SmoothPeriod given in Figure 6.
Figure 6 SmoothPeriod simulink block diagram The 3rd approach, dual differentiator, is given in Figure 7. It is very similar to the homodyne discriminator block diagram given in Figure 4, up to the point where jQ and jI are computed.
Figure 7 Dual Differentiator simulink block diagram At that point our manipulations become different. Compare Figure 5 (block ReImCalc in Figure 4) with Figure 8 (block I2Q2Calc in Figure 7).
Figure 8 I2Q2Calc simulink block diagram Finally, the period is calculated in Figure 9.
Figure 9 PeriodCalc simulink block diagram
IV. RESULTS To evaluate the three approaches they were tested under ideal conditions with known frequencies. Comparisons of the three approaches are shown in Figure 10. The input stimulus was a chirp input. The chirp signal frequency begins with a period of 8 cycles and ends with a period of 50 cycles. The frequency changes in a quadratic fashion between the limiting cycle periods during the simulation. They all track reasonably well, although the homodyne has the least start up transient response and converges more quickly. The homodyne method also appears to be the smoothest throughout the trajectory.
Figure 10 Cycle Estimation for Chirp Signal Input The following test was based on data from the Dow Jones Industrial Average (djia) for the past two years and is shown in Figure 11. It is instructive that the three methods give differing results, as they seem to focus on distinctive cycle period ranges. It is well known that the djia is composed of multiple cycles and the 3 approaches appear to be sensitive to different ranges of cycles. Further testing on various input data may point to the utility of the methods with respect to the user requirements. For example, a short-term day trader may find the homodyne approach more useful as it is more sensitive to shorter period cycles. A long-term trader may be more interested in the phase accumulation or dual differentiator methods.
Figure 11 DJIA cycle estimation results from the three methods
V. ABOUT THE AUTHOR Steven C. Rogers is with the Institute for Scientific Research, Fairmont, WV, USA 26554, srogers@isr.us
VI. REFERENCES [1] A.V. Oppenheim & R.W. Schafer, Discrete-Time Signal Processing (Englewood Cliffs, NJ: PrenticeHall, 1989), ISBN 0-13-216292-X [2] H. Baher, Analog & Digital Signal Processing (John Wiley & Sons, 1990), ISBN 0-471-92342-7. [3] R.E. Ziemer & W.H. Tranter, Principles of Communications, 4th Edition (John Wiley & Sons, 1995), ISBN 0-471-12496-6. [4] K. Shenoi, Digital Signal Processing in Telecommunications Processing (Englewood Cliffs, NJ: PrenticeHall, 1995), ISBN 0-13-096751-3. [5] J.F. Ehlers, Rocket Science for Traders (John Wiley & Sons, 2001), ISBN 0-471-405667-1 [6] Rogers, S., Comparison of Different Frequency Detector Algorithms For a Generic Adjustable Notch Filter, American Control Conference 2003, FM03-1