Time-frequency Analysis in Finance

This page demonstrates the use of our time-frequency analysis add-on package for Mathematica. For an introduction to time-frequency analysis, read our tutorial.

Finance example

Due to the forces influencing financial markets, trends often follow pseudo-periodic patterns which are difficult to detect using conventional forms of analysis.

Load daily Dow-Jones Industrial Average (DJIA) data from 1930 to 2002:

djia = Reverse[Characters/@Rest @ ReadList["Financial/table.csv", String]/.Module[ ... 1900, 2000] + #& @ f[{y}], month[StringJoin[m]], f[{d}], 0, 0, 0}], f[{close}]} ]] ;

djia = {(#〚1〛 - FromDate[{0, 0, 0, 0, 0, 0}])/(365.25 24 60 60), #〚2〛} &/@djia ;

interp = Interpolation[Join[djia, {2djia〚 -1, 1〛 - #〚1〛, #〚2〛} &/@Rest @ Reverse @ djia]] ;

Plot[interp[t], {t, djia〚1, 1〛, djia〚 -1, 1〛}, AxesLabel {"t", "DJIA"}, PlotRangeAll] ;

[Graphics:HTMLFiles/tutorial_185.gif]

Let us concentrate on the last 2048 samples, which cover 1995-2002:

Plot[interp[t], {t, djia〚 -2048, 1〛, djia〚 -1, 1〛}, AxesLabel {"t", "DJIA"}, PlotRangeAll] ;

[Graphics:HTMLFiles/tutorial_187.gif]

As 2048=2^11 is an integer power of two, the Fourier function is particularly efficient and the TFR can be computed quickly:

djiatfr = Block[{n = 2048}, FunctionTFR[interp[t], {t, djia〚 -n, 1〛, 2djia ... lRange {-∞, djia〚 -1, 1〛}, SpectralRange {0, 40}]] ;//Timing

{58.4501 Second, Null}

{{ωmin, ωmax}, {tmin, tmax}} = {GetTFRωRange[djiatfr], GetTFRtRange[djiatfr]}

{{0.193306, 40.061}, {1994.39, 2002.52}}

Plot3D[Abs[djiatfr[t, ω]], {t, tmin, tmax}, {ω, 2, ωmax}, AxesLabel { ...                                                                                                f

[Graphics:HTMLFiles/tutorial_194.gif]

ContourPlot[Abs[djiatfr[t, ω]], {t, tmin, tmax}, {ω, π, ωmax}, FrameLabel {"t", "ω"}] ;

[Graphics:HTMLFiles/tutorial_196.gif]

Two interesting features can be seen in such wavelet transforms of financial time series.

Firstly, the presence of pseudo-periodic fluctuations is easily detected. Despite their oscillating frequencies, these signal components can be accurately quantified via the time-frequency representation.

Secondly, sudden changes often appear to be preceded by characteristic time-frequency components. Specifically, the instantaneous frequency can be seen to rise before a sudden drop occurs. However, it is not clear if the time-frequency characteristics which appear before sudden changes depend upon information which would not have been available at that time, i.e. this could not necessarily have been used to predict the future.