Skip to content

Repository files navigation

Wavelets

1 - Introduction

What is a wavelet ?

Small wave with a defined start and end. A signal can be reconstructed as the sum of small dilated and translated wavelets.



Fig.1 - Wavelets Examples


Why do we use wavelets ?

Break down a signal into 2 components of various scales and frequencies. Financial applications:

  • Denoising
  • Singularity prediction
  • Detection of frequency patterns
  • ...

2 - Building the Wavelets

Daubechie

The daubechie wavelet's are orthognal with a compact support. Their are the more commonly used for the discrete wavelet transformation.

Father Wavelet

\begin{align*}
       \Phi(x) = \sum_{i=0}^{2N-1} \alpha_i \Phi(2x-i)
  \end{align*}

Note: To construct the father wavelet we use a cascade algorithm


Mother Wavelet

\begin{align*}
       \Psi(x) = \sum_{i=0}^{2N-1} (-1)^i \alpha_{2N-1-i} \Phi(2x-i)
  \end{align*}

Derived Wavelets

\begin{align*}
       \phi_{j,k}(u_k) = 2^{j/2}\Phi(2^j u_t - k)
  \end{align*}

\begin{align*}
       \psi_{j,k}(u_k) = 2^{j/2}\Psi(2^j u_t - k)
  \end{align*}

Note: To reduce computing time one can take \begin{align*}
k \in [-2^j T;2^j T]
\end{align*}


Mexican Hat

Yet to be implemented ...


3 - Decomposition/Recomposition

Using a discrete Wavelet (Daubechie for example) one can easily decompose and recompose perfectly the signal by doing the following steps:



Fig.2 - Signal Decomposition/Recomposition


Discrete Wavelet Transform (dwt)

\begin{align*}
  cD_{j,k} = \sum_{t=1}^T z(u_t) \psi_{j,k}(u_t)
  \end{align*}

\begin{align*}
  cA_{j,k} = \sum_{t=1}^T z(u_t) \phi_{j,k}(u_t)
  \end{align*}

Inverse Discrete Wavelet Transform (idwt)

\begin{align*}
  yD_j(u_t) = \sum_{k}cD_{j,k} \psi_{j,k}(u_t)
  \end{align*}

\begin{align*}
  yA_j(u_t) = \sum_{k}cA_{j,k} \phi_{j,k}(u_t)
  \end{align*}

Signal Recomposition

\begin{align*}
  \hat z (u_t) = \sum_j yD_j (u_t) + yA_{j0} (u_t)
  \end{align*}

Examples


Fig.3 - Haar Decomposition/Recomposition



Fig.4 - Daubechie_4 Decomposition/Recomposition

Note: Run main_signal.py to plot thoses graphs


4 - Signal Denoising

To denoise a signal one simply needs to denoise the details coefficients:


Fig.5 - Signal Denoising


Thresholds

Their are multiples ways of computing the threshold to use. The most two famous are:

  • Universal threshold (default)
  • SURE threshold

Universal threshold

\begin{align*}
  \lambda_{universal} = \sqrt{2*log(N)}
  \end{align*}

SURE threshold

\begin{align*}
  \lambda_{SURE} = argmin_{0<\lambda<\lambda_{universal}}SURE(\lambda,x)
  \end{align*}

\begin{align*}
  SURE(\lambda,x) = s + \sum_{i=1}^s [min(\mid X_i\mid, \lambda)]^2-2card(i:\mid X_i\mid <\lambda)
  \end{align*}

Soft/Hard Thresholding

Two types of thresholding exists:

  • Soft - Every values above the treshold is shrinken by the threshold value (default)
  • Hard - Every values below the treshold is shrinken to 0


Fig.6 - Threshold Types


Example


Fig.7 - Daubechie_4 Denoising

Note: Run main_denoising.py to plot thoses graphs


5 - Density Estimation

One can take as an input signal a stock's returns and estimate it's Probability Distribution Function using the wavelet analysis. Once again, it exists multiples wavelet density estimators, we will see the two of them:

  • Linear estimator (easiest)
  • Donoho & Al estimator (thresholded)

Scaling Coefficients

\begin{align*}
  \hat{c}_{j,k} = \frac{1}{n} \sum_{i=1}^n \phi_{j,k}(X_i)
  \end{align*}

\begin{align*}
  \hat{d}_{j,k} = \frac{1}{n} \sum_{i=1}^n \psi_{j,k}(X_i)
  \end{align*}

Estimators

Linear

\begin{align*}
  \hat{f}(x) = \sum_k \hat{c}_{j,k} \phi_{j,k}(x)
  \end{align*}

Donoho & Al

\begin{align*}
  \hat{f} (x) = \sum_k \hat{c}_{j,k} \phi_{j,k} (x) + \sum_{j0}^{j1} \sum_k \tilde{d}_{j,k} \psi_{j,k}(x)
  \end{align*}

Note: \begin{align*}
\tilde{d}_{j,k} = \hat{d}_{j,k}  \; denoised
\end{align*}


Example


Fig.8 - Density Estimations

Note: Run main_density.py to plot thoses graphs

About

Signal analyses using Wavelets applied to financial stocks prices and returns

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages