Skip to contents

Introduction

Wavelet Quantile Correlation (WQC) is a powerful tool for examining scale-specific dependence between two time series at different points of the distribution (e.g., tails or median). By combining the maximal overlap discrete wavelet transform (MODWT) with quantile correlation measures, WQC uncovers how extreme and central co-movements vary across time scales. The wqc package implements WQC in three user-friendly functions:

  • quantile_correlation_analysis(x, y, quantiles, …): Computes quantile correlations with monte-carlo confidence intervals for a single X-Y pair.
  • apply_quantile_correlation(data, quantiles, …): Applies the above analysis across a single Y variable and multiple X variables, returning a consolidated data frame with pairwise results.
  • plot_quantile_heatmap( df,label_levels,palette,…) : plots the estimated quantile correlations in a heatmap form. The significant values will be bordered by a white line.

Theory

Quantile Correlation (QC)

Let XX and YY be two random variables. For a quantile level τ(0,1)\tau\in(0,1), define the influence function:

ϕτ(w)=τI(w<0), \phi_\tau(w) = \tau - I(w < 0),

where I()I(\cdot) is the indicator function. The quantile covariance of YY and XX at τ\tau is:

qcovτ(Y,X)=Cov(ϕτ(YQτ,Y),X𝔼[X]), \mathrm{qcov}_\tau(Y,X) = \mathrm{Cov}\bigl(\phi_\tau(Y - Q_{\tau,Y}),\,X - \mathbb{E}[X]\bigr),

with Qτ,YQ_{\tau,Y} the τ\tauth quantile of YY. The Quantile Correlation (QC) is then:

QCτ(X,Y)=qcovτ(Y,X)Var(ϕτ(YQτ,Y))Var(X). \mathrm{QC}_\tau(X,Y) = \frac{\mathrm{qcov}_\tau(Y,X)}{\sqrt{\mathrm{Var}(\phi_\tau(Y - Q_{\tau,Y}))\,\mathrm{Var}(X)}}.

Maximal Overlap Discrete Wavelet Transform (MODWT)

To capture scale-dependent dynamics, each series is decomposed into JJ levels of detail coefficients via MODWT (Percival & Walden, 2000):

  1. Filter: Convolve the series with low-pass (hjh_j) and high-pass (gjg_j) filters to obtain approximation aja_j and detail djd_j coefficients.
  2. Upsample: For level j+1j+1, upsample filters by inserting zeros and repeat filtering on aja_j.
  3. Collect: The resulting vectors d1,,dJd_1,\dots,d_J isolate fluctuations at dyadic scales (fine to coarse).

Wavelet Quantile Correlation (WQC)

For each level j=1,,Jj=1,\dots,J and quantile τ\tau:

  1. Decompose series XX and YY into detail coefficients dj[X]d_j[X] and dj[Y]d_j[Y].
  2. Compute QCτ(dj[X],dj[Y])\mathrm{QC}_\tau(d_j[X],d_j[Y]) using the formula above.
  3. Simulate nsimn_{\mathrm{sim}} Gaussian surrogates matching the empirical mean and variance of each dj[]d_j[\cdot] to obtain confidence intervals at the 2.5% and 97.5% percentiles.

The function quantile_correlation_analysis() automates these computations, returning a data frame:

Level Quantile Estimated_QC CI_Lower CI_Upper
1 0.05 0.12 0.05 0.18
JJ 0.95 -0.03 -0.08 0.01

Examples

1. Multi-Series Analysis with apply_quantile_correlation()

library(wqca)
set.seed(123)
# Reference series plus two targets
data <- data.frame(
  x = rnorm(512),
  y = 0.6 * rnorm(512) + 0.4 * rnorm(512),
  z = rnorm(512)
)
quantiles <- c(0.1, 0.5, 0.9)
# Compute WQC up to 3 levels with 300 bootstrap sims
res_df <- apply_quantile_correlation(data, quantiles, J = 3, n_sim = 300)
# View top rows
head(res_df)

2. Single-Pair Analysis with quantile_correlation_analysis()

library(wqca)
set.seed(456)
x <- rnorm(600)
y <- 0.8 * x + 0.2 * rnorm(600)
quantiles <- c(0.05, 0.5, 0.95)
# Analyze one pair at 4 levels with 200 sims
single_res <- quantile_correlation_analysis(x, y, quantiles, J = 4, n_sim = 200)
# Inspect results
single_res

3. Visualizing with a Heatmap with plot_quantile_heatmap()

Once you have your correlation results from quantile_correlation_analysis() , you can plot them at a glance:

# compute a small example
set.seed(100)
df <- quantile_correlation_analysis(
  x = rnorm(128), y = rnorm(128),
  quantiles = c(0.1, 0.5, 0.9),
  J = 4, n_sim = 50
)
plot_quantile_heatmap(df)

References

Kumar, A. S., & Padakandla, S. R. (2022). Testing the safe-haven properties of gold and bitcoin in the backdrop of COVID-19: A wavelet quantile correlation approach. Finance Research Letters, 47, 102707.

Percival, D. B., & Walden, A. T. (2000). Wavelet Methods for Time Series Analysis. Cambridge University Press.