Sunteți pe pagina 1din 6

High Frequency Trading Strategy Using the Hilbert Transform

A. Kablan, and W.L. Ng


Centre for Computational Finance and Economic Agents (CCFEA)
University of Essex
Essex, UK

Abstract - The recent escalation in computing power and the knowledge of the phase at each sample, measuring its
database capacity in major financial exchanges has brought a bar-to-bar change yields the rate of change of phase, which
substantial increase in both data and information availability. can be used to determine the dominant cycle. Several
The ever faster development of computers, sensors, and methods exist on how to do this, as outlined by [6]. The main
information channels in financial IT has rendered trading data objective is to investigate how the periods of the dominant
easier to be collected than ever before. The present study cycle in a cycle mode can be quantified in order to create
examines how the Hilbert transform may be used for the amplitude compensation of the inphase and quadrature
detection of financial market cycles and market trends. In
components, and methods of smoothing and de-trending the
particular, this paper focuses on measuring cyclic patterns of
analytic signal. The aim is to analyse market data as a
high frequency data to enhance intraday trading. The
spectrum whose values are not limited to a specific set of
proposed approach exhibits several advantages over more
traditional trading methods, attributed to its consideration of values but can vary infmitely within a continuum. Market
complex variables. signals will be analysed, cycles will be detected, and cycle
transformation and filtration techniques will be used to create
Keyword; Hilbert transform; market cycles; high frequency trading strategies.
data.
II. MARKET CYCLE MEASUREMENT
I. INTRODUCTION Measuring market cycles has proved to be a hard task
The advance in computational power during the past due various factors. Some of these factors are: (a) the fact
decade has had a dramatic impact on both fmancial research that theoretical measurement involves simultaneously
and fmancial trading. However, due to the increase in solving a triple infmity parameter of values (frequency,
computational power, and the automatisation of fmancial amplitude, and phase) [6], (b) the signal-to-noise ratio of a
markets, an increasing number of exchanges have set up cycle is usually very low, and (c) standard engineering
intraday databases that record every single transaction as approaches such as fast Fourier transforms (FFTs) are not
well as its characteristics (such as price, volume etc). The appropriate for measuring market cycles as they cannot
availability of intraday (tick-by-tick) datasets have boosted simultaneously meet the stationarity constraints and produce
the development of a new area of fmancial research known results with reasonable resolution [8].
as high-frequency fmance, which in return has produced a Instead, [5] suggests the use of the maximum entropy
new form of trading: high-frequency trading. spectral analysis model (MESA) for measuring market
High Frequency Trading is the new trend in fmancial cycles. This model has been used to produce high resolution
engineering where prices are analysed in tick-by-tick fashion outputs from exceptionally short amount of data. A short
and buy, sell, or hold decisions are consecutively taken in data length increases the probability of having nearly
real-time. However, raw price data alone is not of much use stationary data which leads to having frequency and
for a trading system that is intended to implement and test amplitude that are quasi-constant over the length of data. To
trading strategies as they often contain market microstructure make the phase measurements, the cycle has to be described
noise. The aim of this paper is to investigate ways of in terms of a phasor instead of the conventional waveform.
analysing, processing, and exploiting such data from a digital One complete phasor (360°) rotation describes the cycle
signal processing perspective to produce valuable (Figure 1). The phasor can then be broken into two
information for the trading system. The basis of efficient components, the inphase and the quadrature components.
digital processing is the use of complex arithmetics for This leads to the ability of breaking the analytic waveform
computations, such as "divide and conquer". Most trading into the inphase and quadrature components. This is done
systems have been concentrating on using common analytic using the Hilbert Transform.
waveforms and have not taken in consideration of phasors There are various traditional methods to measure cycles
and complex variables [7]. In contrast, this paper shows how and periods, the most straight-forward method is to use the
to use cyclic measurement techniques such as the Hilbert phase accumulator approach, which uses the difference
transform to convert the common signal variables in analytic between any two phase angles from each sample difference
waveforms to complex variables that can be used as trading within a 360 degree circle defining the period [9]. This
signals. always uses a full cycle, and the measurement of a relatively
In particular, the paper concentrates on the detection of short-cycle period will have less lag than for a long-cycle
high frequency market cycles rather than market trends. With period. However, the averaging period varies with the cycle

466
period, meaning that the signal-to-noise ratio will also daCt)
change (it will be higher for shorter periods). Another way to wCt) = - ----;it .
measure the period is to use the homodyne discriminator,
where the signal of the current bar is multiplied with the The use of the instantaneous frequency in this way can
complex conjugate of the previous sample, yielding the therefore only be used to represent one component. As noted
instantaneous cycle period. The third way is derived from the by [4], there is no precise defmition of such a
first two, and is called the dual differentiator, where the 'monocomponent', and for lack of a precise defmition, the
period is a function of both the inphase and quadrature term 'narrow-band' was therefore adapted as a limitation of
components. A cycle measurement comparison by [5], the data in order to make the instantaneous frequency
including the use of real data, reveals that the homodyne concept make sense.
discriminator appears to be the more superior, although this The notion of the instantaneous frequency and Hilbert
is by no means definitive. transform in general, then becomes problematic. However,
In contrast to the above, we use Hilbert transformation the Hilbert transform, whilst being suitable for market cycle
method in measuring market cycles. This has several analysis, also appears to be useful in all these circumstances
advantages over more traditional methods. The Fourier too. [4] has introduced a new type of data analysis method
transform for example, simply measures the cycles from the called the Hilbert-Huang transform to deal precisely with
bar chart, and by finding the frequency response of a these problems. This has been attracting significant attention,
function of known characteristics in the time domain, and has been shown to be quite an impressive conceptual
produces the distribution of frequencies (or cycle lengths) innovation and implementation of the Hilbert transform (it
with their attendant power. has already found successful applications in fmancial trading
This study proposes a new methodology for the use of [8], [9], as well as in other fields, such as aeroelastic flight
the Hilbert transform on high frequency fmancial data by data analysis [ 1]).
first filtering the high frequency data using inphase and The Hilbert-Huang transform consists of two parts: (a)
quadrature components, then applying the rotation principle the empirical mode decomposition, and (b) a Hilbert spectral
to detect high and low cycle patterns in the price signal analysis. The dataset is decomposed into a fmite and number
which would eventually lead to placing buy and sell of intrinsic mode functions with equal numbers of zero­
positions. crossing and extrema, accompanied by symmetric envelopes
III. T HE ROLE OF THE HILBERT TRANSFORM defmed by local minima and maxima, respectively. The
advantage of the method is that it is applicable to nonlinear
The Hilbert transform has been shown to be useful for and nonstationary data, in much the same way as Ehlers
market cycle analysis by [4], [8], and [9], there are some filters [6]. For example, the intrinsic mode functions admit to
important limitations that can arise under certain conditions well-behaved Hilbert transforms and the decomposition is
that restrict its use. In particular, it was [4] who first adaptive and therefore highly efficient. The technique can
recognised the limitation of the Hilbert transform for also be used to examine the changeability of the market, as a
multiple frequency components, where the definition of an measure of the volatility, which is the most prevalent use of
instantaneous frequency became problematic. Consider that the Hilbert transform in the current financial literature.
the instantaneous frequency (j) can be derived from the
Hilbert transform polar representation IV. ApPLYING THE HILBERT TRANSFORM IN HIGH­
FREQUENCY TRADING
Phasor P
To practically use the concept of the Hilbert transform on
sine high frequency data, certain changes and modifications had
to be made to both the filter structure and to the data.
Truncating the Hilbert transform in order to reduce the lag
from filtering market data, we apply the approach presented
by [5] on high frequency data.
The Hilbert transform has been derived in the previous
sections of this paper. It was established that the Hilbert
transform shifts all positive frequencies by _90°, and all
negative frequencies by 90°. Hence the Hilbert transform can
be described in terms of angular frequency since the
frequency response of sampled systems is periodic. Figure 2
shows a description of the above in terms of angular
frequencies. In other words, the Hilbert transform produce� a
periodic signal which means that we can use the FOUrIer
Figure I. A sine wave can be obtained by the rotation of a phasor around series to determine the coefficients of the exponential series.
the center of a circle

467
the Hilbert Transform will be represented by Q. Forn 5,
Q can be written as

.---)
----1
=
(P(t)
5 +
pet 3- 1) + pet _ 2) _
pet 3) pet 3- 4) pet 5- 5))
_ _ _

Q
( 1 + j + �)
-2rr -rr o rr 2rr
The inphase component of the Hilbert transform will be
represented by (I). This component is relevant to the centre
of the filter and can be written simply as then-th detrended
-jt----'
price component. Hence forn 5, the inphase component
=

is written as

1 = P(5).

Figure 2. Periodic frequency response of a digital Hilbert Transform


Complex numbers have been used in electronics in order
to explain and express alternating signals. This uses a mix of
From [5], we know that the Fourier series of the Hilbert real and imaginary sets of numbers to view an alternating
transform can be written as: signal as rotating signal in the time domain. This becomes

L
00
more clearly when plotting a sine wave signal against a
H(z) n delayed version of itself which is a cosine wave signal which
= c nz .
creates a complete circle. This has inspired the approach of
n=-oo
using this technique with signals created by the high
If we let z = ejmT with T = 1, then the Fourier transform frequency market price.
becomes As discussed above, the Hilbert transform deals with the
concept of positive and negative frequencies. This can be
simply viewed as a rotating wheel that is moving around a
central point (Figure 3). However applying the same concept
to a non-linear entity such as the market price can make the
with task of measuring the cycle period rather difficult. Hence it

L Cnejmn
00

was found in this research that the Hilbert transform can be


H(ejm) =
used to estimate and measure the market cycle, by creating
n=-oo complex signals in the time domain. In the next section, we
will try to measure cycle rotations to identify high and low
The above equation describes the coefficients of the digital peaks indicating good buy and sell opportunities.
filter. [5] solves the integral equation for the filter
coefficients assuming the square wave has the same sin (x) I
x form as the pulse of the transfer response in the time
domain. Hence, we obtain
i 2
2 Sn
nn ( )
2
Cn = _

n n

forn*-O and Cn 0 forn = o. =

It is to be noted that the value ofn is relative to the centre


of the filter, which means that the centre coefficient is
always zero. Also the value of the squared sine is always
positive and produces a value of unity for odd values ofn.
This leads to the coefficients being equal to lin for odd
values ofn; they are positive for the most recent data half of
the filter and negative in the older data half of the filter. The
ideal Hilbert transformer extends coefficients from minus
infmity to plus infinity. The 21n factor can be ignored here
as we have a normalized amplitude response. Figure 3. Rotating wheel principle from a sine wave signal
The Hilbert transform can now be approximated by
truncating the extent. For example, we could truncate the
filter atn =5 or atn 7, etc. In this case, the detrended
=

price will be represented by P. The quadrature component of

468
Price Component
Begin 1 11

4+-1-11-1+-1-1·1-1+1- 01-1+1- 1-1+11


- 1-1+1- 4+>- 14 +
I II I I I I I 1 1J!
I I I II I II I 11 1
For i = l:end(data) -I +-1-11-1 +-1-1· t-t +- I- 4+>- 4 +
I II I I "

Input the price series to the system

'Tr l'Tr 'Tr I' T


Create the smooth price data I IIII I I I I 1 I I1
III II I I III
-',rr ,rr 'Tr 'Tr 'Tr 'Tr 'Tr , T

smooth(i) = (4*price(i) 102


+3*price(i-l) 0 20 40 60 80 100 120 140 160
+2*price(i-2)
Time
+ price(i-3))/lO;
x 10
.3 Qrndrature Component
Create the detrended price series 2 I III I II I I III

III

detrender(i) = (O.25*smooth(i)
+O.75*smooth(i-2)
-O.25*smooth(i-4)
-O.75*smooth(i-6));

Calculate the inphase and quadrature ����UJ�� _ ��� ��� __ ���_ ��� _ ��� J�l
1
components with n = 3 .2 LLL...L.LLLJ---'--.LL.LL.L.L.L.LJLLL.LLl--'--.l
o 20 40 80 100 120 140 160
Ql(i) (O.25*detrender(i)
Time
=

+O.75*detrender(i-2)
-O.25*detrender(i-4) inPhase Component
-O.75*detrender(i-6));

Il(i) = detrender(i-3);

Listing 1: Pseudo-code for creating the Hilbert transfonn

A. Data and Analysis: _ ...! .L L'_'....! .L L ,_I.J .L L ,_I...! .L L '_'...! .L L'_I .J .L L ,_ I....! .L L '_'..J .1
I I II I I II II

20 40 80 100 120 140 160


All simulations in this paper have been carried out on
foreign exchange (FOREX), high frequency, 5 minute, Timp
intraday data observed between 04/04/2004 and 04/04/2008. Figure 4. Quadrature and inPhase components exhibiting cyclical
The tested currency pairs are EURIUSO, GBP/uSO, behaviour from price data
AUO/USO, USO/CAO, and USO/JPY. To put the
framework mentioned above in practice, we process the high
163 Ililbcrt transform componcllIs
frequency price data as shown in the pseudo code in Listing X

1 above to produce the following :


0.•

• a filtered smoother price data by applying a simple 0.•

moving average, 0.4


.e
-e3-:
-- <1 '

0.2


a detrended set of the smooth data,
the quadrature component from the detrended price and � 0 j. .. .... . .... .... ..jj.. ...
. ... . . . . . . . . ... . .... . .... . .. /f

• the inphase component from the detrended price.

It has has been noted that the quadrature and inphase = ::


.(J.6
� �/2-!�-.')
-E-;--' ..s .fI8
�9

i
l

components exhibit a cyclical behaviour once they are .(J.B ..,.5 -- ... e
of!7

implemented on price data as shown in Listing 1. This can


produce smoother cycles to which could be applied to the
rotation principle described above. Figure 4 shows the .(J.8 -0.6 -0.4 .Q.2

Quadrature
0.2 0.4 0.6 0.8

cyclical behaviour of the quadrature and inphase components


relative to the price data. Figure 5 implements the rotation Figure 5. The rotation principle using the quadrature and inPhase
components
principle on the quadrature and inphase components.

469
x 10
� ff�bert transfonn components B. Simulation Results:
Implementing the strategy illustrated in Figure 7, and
5 il6 � ---I> Quarter 1
Quarter 2 j""""'"
running it for a long data set on various currencies would

�::.::::...... .............k....................�..
5
indicate the feasibility of such approach. Hence we have
o ............... .... . decided to experiment on various currencies to observe the

=
its
\�t�( behavior of the system with different volatilities and market
conditions. To assess the system, a rolling window approach
"- has been used to parse the original data set (from 04/04/2004
c
it9
·10
to 04/04/2008) for six months, and then the starting point
will be shifted by two months for the next simulation, and so
€O
Quarter 4 on until the end of the data set. Using this approach we have
·15
Quarter 3 20 simulations for each currency. This enables us to
statistically asses and to identify different scenarios
·1 .0.5 0.5 1.5 according to different starting points.
Quadrature �
x 10

1.0305
EUR/USD from 0110612004 to 30/1112004
O.12 r---,----,---,.---,
1.03
0.1
1.0295
'"
u 0.08
- t- --
"-1.029
0.06

1.0295
.. -

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
lime
, T
Figure 6. The application of the Hilbert transform in a trading strategy. .0.02 �
,
- - -- -,- -
, r T
.0.04 --� �
A considerable amount of simulations have been carried - -
,
-
, T
out. Plotting the quadrature against the inphase components .0.06
0
will produce a rotating signal (Figure 6). We divide the MonlilS
circular rotation area into 4 quarters, and plot the quadrature
and inphase components into the rotation canvas. It has been Figure 7. Performance of the Hilbert system against a buy and hold
observed throughout all 100 simulations that whenever the strategy on the EURIUSD currency for the period between June 2004 till
signal crosses Quarter 1, the price is likely to rise afterwards,
EUR/USD from 01103/2008 to 27/08/2008
until it exits from Quarter 1 to any other quarter. O.14 r---,----,---,--,
1
____ ...1 __ l. _____ _____ L
Furthermore, whenever the signal crosses into Quarter 3, the _ I

price is likely to fall until it exits Quarter 3 into any other


-- ,
,--- - - - ,
Quarter. It has been found in this study that this signal has ...1 ___
T
0.1 ___

indicative properties that can be used to identify high and - - - -t - -I --


low cycle positions on high frequency price signals. This can O.OB
be used in a high frequency trading strategy to place the buy
and sell orders according to the cycle highs and lows. In 0.06

other words, whenever the rotating signal crosses the Quarter


0.04
1 we place a buy position, which is closed when the signal
exits the quarter. A sell position is also placed whenever
Quarter 3 is crossed and closed when the signal is out of the L
quarter. Opening buy positions are labelled in green, and -t - - - -1- - - t- "I
-- r--
opening sell positions are labelled in blue. The black labelled -- ,1---- ,
"1--

positions are the respective closing positions of either the 'O·02 0!c----.;.---+----:-
buy or sell position. Using this principle, the next section Months

indicates how simulations have been carried on longer time


December 2004.
frames to test the above strategy for consistency in
performance.
Figure 8. Performance of the Hilbert system against a buy and hold
strategy on the EURIUSD currency for the period between March 2008 till
Sept 2008.

470
TABLE I. SAMPLE OF A TRADING LOG OF THE HILBERT SYSTEM
Table II shows the average performance of adopting the
Hilbert transform for the various currencies that the
Sell Sell Time Time Buy Buy Time Time simulation has been performed on. It illustrates that the
open close of sell of sell open close of of Hilbert system outperforms a traditional buy and hold
price price open close price price buy buy strategy and shows a high level of accuracy in the decision
open close
making of the system. The return of investment (ROI) is
0.91550 0.91615 635 750 consistently above the buy and hold strategy, and the
0.91640 0.91630 820 825 investment with such a system does not exhibit a riskier
0.91615 0.91625 835 850 behaviour in general because both the Sharpe and Sortino
ratios are positive in most cases.
0.91610 0.91615 905 920

0.91595 0.91590 940 955

0.91540 0.91495 1005 1025 V. CONCLUSION


0.91500 0.91490 1035 1045 The introduction of advanced mathematical techniques
0.90990 0.90980 1130 1205 and digital signal processing has revolutionised the art of
financial trading, providing new tools to the trader, not only
to view the market in a different light, but also to analyse it
0.91075 0.91090 1220 1235
differently. Within this context, the concept of the Hilbert
transform has been proposed to measure and investigate
Table I illustrates the mechanism of trading using the market cycle analysis. The main conclusions are that the
rotation principle, where the system would be either buying Hilbert transform allows for the formulation of some unique
or selling each time the signal is in the specific quarter. The market indicators and accomplishes this task in a
system is either on buy mode or on sell mode. Figures 7 and computationally more efficient manner. The practical use of
8 are sample illustrations of the performance of the above the Hilbert transform appears to require severe truncation in
Hilbert strategy in against a traditional buy and hold strategy order to produce an acceptable lag for trading and this
for a long term horizon of 6 months. necessitates several corrections to compensate, which must
be kept in mind when trading.
TABLE II. AVERAGE PERFORMANCE OF THE HILBERT STRATEGY VS
A Buy AND HOLD STRATEGY
REFERENCES
Profit Sharpe Sortino
ROI
Factor Ratio Ratio [I] Brenner, M. J., and Prazenica, C. (2006). Aeroelastic flight data
analysis with the Hilbert-Huang Algorithm. California: National
EUR-USD Aeronautics and Space Administration. (Report No. NASNTM-
2006-213655).
Buy and Hold 1. 1 0.09 -0.07 -0.05 [2] Ooukaa, E., and Hadjileontiadis, L. J. (2005). Time-frequency
analysis of the free vibration response of a beam with a breathing
Hilbert Strategy 1.7 0. 15 0.29 0.3 1 crack. NOT & E International. Vol. 38, pp 3-10.

AUD-USD [3] Holmes, P., Lumley, J. L., and Berkooz, G. (1996). Turbulence,
coherent structures, dynamical systems and structures. Cambridge
Buy and Hold 0.9 0. 1 1 0.03 0.0 1 University Press. Cambridge.
[4] Huang, N.E., Shen, Z., Long, S.R., WU, M.C., Shih, H.H., Zheng, Q.,
Hilbert Strategy 1.0 0.09 0. 13 0. 12 Yen, N.C., Tung, C.C., and Liu, H.H. (1998). The empirical mode
decomposition and the Hilbert spectrum for nonlinear and non­
GBP-USD stationary time series analysis. Proc. R. Soc. London A. Vol. 454, pp
903-995.
Buy and Hold 1.3 0. 1 1 0.04 0.05
[5] Ehlers, J. F. (2004). Cybernetic Analysis for Stocks and Futures. John
Hilbert Strategy 1.5 0. 14 0. 12 0.08 Wiley and Sons. New York.
[6] Ehlers, J. F. (2001). Rocket science for traders: digital signal
UDs-eHF processing . John Wiley and Sons. New York.

Buy and Hold 0.8 0.07 -0.02 -0.04 [7] Park, C. H, and S. H. Irwin. (2007). What Do We Know about the
Profitability of Technical Analysis? Journal of Economic Surveys.
Hilbert Strategy 0.9 0. 15 0. 13 0.07 Vol. 21, pp 786-826.
[8] Wu, M. C. (2007) Phase statistics approach to physiological and
USD-JPY financial time series. AAPPS Bulletin. Vol. 17, pp 21-26.
[9] Wu, M. C. (2007) Phase statistics approach to time series analysis. J
Buy and Hold 0.4 0.0 1 -0. 14 -0. 17 Korean Phys Soc .Vol. 50, pp 304--312.
Hilbert Strategy 0.6 0.05 -0.02 -0.04

471

S-ar putea să vă placă și