Steven S. Skiena
Dept. of Computer Science
SUNY Stony Brook
Certain phenomena of financial (and other) time series data is best revealed in the frequency domain, or equivalently represented by their spectra.
A duality transform is a one-to-one mathematical function that takes a mathematical object of type-1 and maps it to an equivalent type-2 mathematical object.
Sample duality relations are point-line duality in computational geometry, and Laplace transforms used solving differential equations.
Such transforms are useful if there are interesting algorithms and tools for manipulating data of type 2.
Perhaps the most useful duality transform known is the Fourier transform for representing time-series data as the sums of sine and cosine functions.
Its wide applicability is due to the existence of Fast Fourier Transform
algorithm or FFT which computes what seems like an inherently quadratic
function in time.
On the left, we construct a time series of points sampled from a sine function with added random noise.
On the right we take the Fourier transform of this series, plotting the coefficients of the resulting sine functions:
Note how very particular cross-hatching was removed by eliminating the appropriate transform coefficients.
If the two functions are similar in shape but one is shifted relative
to the other (such as
and
), the value of
will be large at this shift offset
.
As an application, suppose that we want to detect whether there are any funny periodicities (autocorrelations) in a time series or random number generator. When we take the Fourier transform of this series, any large spikes will correspond to potential periodicities.
We can represent a given polynomial
Given the coefficient representation, we can add or subtract two
polynomials in time by just adding or subtracting each pair
of corresponding terms.
Given the coefficient representation, we can evaluate a polynomial
in linear time using Horner's rule
It is not clear how to multiply two polynomials in coefficient representation
in less than .
However, it is easy add, subtract, and multiply pairs of polynomials in
point-value representation (assuming the same set of values is used
in both polynomials) by operating on the pair of points for each
value.
We can multiply coefficient polynomials by
(1) converting them to point-value representation,
(2) multiply these pointwise in , and
(3) interpolate these
points back to a polynomial.
Note that the product of two -degree polynomials has degree
.
Steps (1) and (3) can in fact be done on by using the DFT and inverse transform.
Lagrange's formula can solve the interpolation problem in , but it is too slow.
Although any polynomial of degree should have
roots/solutions,
they sometimes require complex numbers:
The roots of unity are the
solutions to the equation
These roots are defined by the powers
for
,
where
The identity linking the trigonometric functions to is
The discrete Fourier transform takes as input
complex numbers
,
, corresponding
to equally spaced points in a time series.
It outputs complex numbers
,
,
each describing a trigonometric function of the given frequency.
The discrete Fourier transform is defined by
However, the complexity of a naive implementation is .
The critical step in efficiently computing the DFT takes as input
a set of complex numbers
and outputs
the sequence of
complex numbers
In particular, to evaluate when
is even, let
It should be clear that
FFT algorithms are based on divide-and-conquer.
Essentially, the problem of computing the discrete Fourier transform on points
is reduced to computing two transforms on
points each and is
then applied recursively.
In general, this recurrence does not help us, since we have to spend linear time
to evaluate it at each of points.
The fact that our points are complex roots of unity provide the magic to speed things up.
The FFT algorithm assumes that is a power of two.
If this is not the case for your data,
you are better off padding your data
with zeros to create elements rather
than hunting for a more general code.
Some care is needed to determine where to best pad the zeros.
Historically, the FFT has been implemented in assembler or even hardware for performance optimization.
Highly optimized FFT implementation exist which tune themselves to your specific hardware configurations (e.g. cache size). Check out the FFTW (Fastest Fourier Transform in the West).
In recent years, wavelets have been proposed to replace Fourier transforms in filtering.