Title: | Estimate Rolling Window Wavelet Correlation Between Two Time Series |
---|---|
Description: | Estimates and plots as a heat map the rolling window wavelet correlation (RWWC) coefficients statistically significant (within the 95% CI) between two regular (evenly spaced) time series. 'RolWinWavCor' also plots at the same graphic the time series under study. The 'RolWinWavCor' was designed for financial time series, but this software can be used with other kinds of data (e.g., climatic, ecological, geological, etc). The functions contained in 'RolWinWavCor' are highly flexible since these contains some parameters to personalize the time series under analysis and the heat maps of the rolling window wavelet correlation coefficients. Moreover, we have also included a data set (named EU_stock_markets) that contains nine European stock market indices to exemplify the use of the functions contained in 'RolWinWavCor'. Methods derived from Polanco-Martínez et al (2018) <doi:10.1016/j.physa.2017.08.065>). |
Authors: | Josué M. Polanco-Martínez [aut, cph, cre] |
Maintainer: | Josué M. Polanco-Martínez <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.4.0 |
Built: | 2024-10-27 02:47:39 UTC |
Source: | https://github.com/cran/RolWinWavCor |
'RolWinWavCor' estimates and plots as a heat map rolling window wavelet correlation (RWWC) coefficients statistically significant (within the 95% CI) between two regular (evenly spaced) time series. 'RolWinWavCor' is based on the method proposed by Polanco-Martínez et al. (2018), Physica A 490, 1211-1227 (<doi:10.1016/j.physa.2017.08.065>). The RWWC was designed for financial time series analysis, but other types of data (e.g., climatic, ecological, geological, etc.) can be analysed. 'RolWinWavCor' contains two functions: (1) estim_RWWC
that is used to estimate the rolling window wavelet correlation coefficients and their statistical significance, and (2) plot_estim_RWWC
that plots the time series under analysis and a heat map of the rolling window correlation coefficients that are statistically significant. The functions included in 'RolWinWavCor' are highly flexible since these contains some parameters to personalize the time series under study and the heat maps of the rolling window wavelet correlations. Moreover, we have also included a data set named EU_stock_markets
that contain nine EU stock market indices (closing prices) to exemplify the use of the functions contained in 'RolWinWavCor'.
Package: | RolWinWavCor |
Type: | Package |
Version: | 0.4 |
Date: | 2023-03-09 |
License: | GPL (>= 2) |
LazyLoad: | yes |
RolWinWavCor package contains two functions: (1) estim_RWWC
that estimates the rolling window wavelet correlation (WLMC) coefficients and their 95% confidence intervals (95% CI); (2) plot_estim_RWWC
that plots the time series under analysis and the rolling window correlation coefficients that are statistical significant (within the 95% CI) as a heat map, which are obtained via the function estim_RWWC
.
Dependencies: waveslim
Josué M. Polanco-Martínez (a.k.a. jomopo).
Excellence Unit GECOS, IME, Universidad de Salamanca, Salamanca, SPAIN.
BC3 - Basque Centre for Climate Change, Leioa, SPAIN.
Web1: https://scholar.google.es/citations?user=8djLIhcAAAAJ&hl=en.
Web2: https://www.researchgate.net/profile/Josue-Polanco-Martinez.
Email: [email protected]
Acknowledgement:
We acknowledge to the Excellence Unit GECOS (grant reference number CLU-2019-03), Universidad de Salamanca for its funding support.
Polanco-Martínez, J. M., Fernández-Macho, J., Neumann, M. B., & Faria, S. H. (2018). A pre-crisis vs. crisis analysis of peripheral EU stock markets by means of wavelet transform and a nonlinear causality test. Physica A: Statistical Mechanics and its Applications, 490, 1211-1227. <URL: doi:10.1016/j.physa.2017.08.065>.
The estim_RWWC
function estimates the rolling window wavelet correlation (RWWC) coefficients between two regular or evenly spaced time series. This function is based on the work of Polanco-Martínez et al. (2018). However, we use the functions modwt
and wave.correlation
from the R package 'waveslim' (Whitcher et al. 2000, Whitcher 2022) to decompose via MODWT the two time series under study and to estimate the wavelet correlation between these two time series.
estim_RWWC(inputdata, Wname="la8", J, W, Align="center", Scale=TRUE)
estim_RWWC(inputdata, Wname="la8", J, W, Align="center", Scale=TRUE)
inputdata |
A matrix of three columns: the first one is the time (regular or evenly spaced) and the other two columns are the variables under study. |
Wname |
Name of the wavelet filter used in the wavelet transform (MODWT) decomposition. There are several wavelet filters to be used, but we use by default the Daubechies orthonormal compactly supported wavelet of length L=8, that is, “ |
J |
The maximum level of the MODWT decomposition. It is recommended to use |
W |
The window-length or size of the window used when the rolling window wavelet correlation coefficients are estimated. The optimal window-length is a key question when the RWWC is estimated and the answer is closely related with the time-scales of the phenomenon under study. It is advisable to use one window-length around the target time-scale, not too short and not too long, and always test several window-lengths to analyse its sensibility (Polanco-Martínez et al. (2018)). |
Align |
This is used to align the rolling object. There are three options: |
Scale |
Scale (by default is “TRUE”; “FALSE” otherwise) is used to “normalize” or “standardize” the variables under analysis. It is advisable to ”normalize/standardize” the time series under study to have them in the same scales. |
The estim_RWWC
function estimates the rolling window wavelet correlation coefficients and their statistical significance between two time series sampled on identical time points for a given window-length. The estim_RWWC
function is based on the work of Polanco-Martínez et al. (2018), but this function uses the functions modwt
and wave.correlation
from the R package 'waveslim' package (Whitcher et al. 2000, Whitcher et al. 2022) to decompose via MODWT the two time series under analysis and to compute the wavelet correlation coefficients between these two series.
Outputs: A multidimensional matrix containing three columns: the rolling window wavelet correlation coefficients and their respective 95% confidence interval in the second (lower bound) and third (upper bound) columns.
Josué M. Polanco-Martínez (a.k.a. jomopo).
Excellence Unit GECOS, IME, Universidad de Salamanca, Salamanca, SPAIN.
BC3 - Basque Centre for Climate Change, Leioa, SPAIN.
Web1: https://scholar.google.es/citations?user=8djLIhcAAAAJ&hl=en.
Web2: https://www.researchgate.net/profile/Josue-Polanco-Martinez.
Email: [email protected]
Acknowledgement:
We acknowledge to the Excellence Unit GECOS (grant reference number CLU-2019-03), Universidad de Salamanca for its funding support.
Polanco-Martínez, J. M., Fernández-Macho, J., Neumann, M. B., & Faria, S. H. (2018). A pre-crisis vs. crisis analysis of peripheral EU stock markets by means of wavelet transform and a nonlinear causality test. Physica A: Statistical Mechanics and its Applications, 490, 1211-1227. <URL: doi:10.1016/j.physa.2017.08.065>.
Fernández-Macho, J. (2018). Time-localized wavelet multiple regression and correlation. Physica A: Statistical Mechanics and its Applications, 492, 1226-1238. <URL: doi:10.1016/j.physa.2017.11.050>.
Whitcher, B., Guttorp, P., & Percival, D. B. (2000). Wavelet analysis of covariance with application to atmospheric time series. Journal of Geophysical Research: Atmospheres, 105(D11), 14941-14962. <URL: doi:10.1029/2000JD900110>.
Gencay, R., F. Selcuk and B. Whitcher (2001) An Introduction to Wavelets and Other Filtering Methods in Finance and Economics, Academic Press.
Whitcher, B. (2022). waveslim: Basic Wavelet Routines for One-, Two-, and Three-Dimensional Signal Processing. <URL: https://cran.r-project.org/package=waveslim>, R package version 1.8.4.
# We reproduce Figure 2 presented in Polanco-Martínez et al. (2018). datPIGS <- EU_stock_markets sindatePIGS <- datPIGS[-1] # To remove dates sindatePIGS <- sindatePIGS[c(1:5, 8)] lrdatPIGS <- apply(log(sindatePIGS), 2, diff) lrDATES <- as.Date(datPIGS[,1][-1]) tsdatPIGS <- ts(lrdatPIGS, start=1, freq=1) Nnam <- dim(tsdatPIGS)[2] lrdatPIGS <- lrdatPIGS[,1:Nnam] inputdata <- tsdatPIGS[,c(2,5)] Wname <- "la8" J <- 4 W <- 241 Align <- "center" rwwc <- estim_RWWC(inputdata, Wname, J, W, Align=Align)
# We reproduce Figure 2 presented in Polanco-Martínez et al. (2018). datPIGS <- EU_stock_markets sindatePIGS <- datPIGS[-1] # To remove dates sindatePIGS <- sindatePIGS[c(1:5, 8)] lrdatPIGS <- apply(log(sindatePIGS), 2, diff) lrDATES <- as.Date(datPIGS[,1][-1]) tsdatPIGS <- ts(lrdatPIGS, start=1, freq=1) Nnam <- dim(tsdatPIGS)[2] lrdatPIGS <- lrdatPIGS[,1:Nnam] inputdata <- tsdatPIGS[,c(2,5)] Wname <- "la8" J <- 4 W <- 241 Align <- "center" rwwc <- estim_RWWC(inputdata, Wname, J, W, Align=Align)
The data set EU_stock_markets
contains nine European stock market indices (closing prices): PSI20 (Portugal), MIB30 (Italy), ISEQ (Ireland), ASE20 (Greece), IBEX35 (Spain), DAX30 (Germany), CAC40 (France) and SPEurope350 (Eurozone). The first column are the dates and these have the format YYYY-MM-DD. All data sets come from Yahoo Finance (except for the PSI20 and SPEurope350 stock market indices, which were taken from BolsaPT and OnVista Group) and encompass the interval from January 2, 2004 to December 31, 2011 (2086 elements or data points). This data set was used in Polanco-Martínez et al. (2018) and this work should be consulted for more information about this financial data set.
data(EU_stock_markets)
data(EU_stock_markets)
Data set is in ASCII format containing 10 columns and 2086 rows (elements or data points), columns are separated by spaces.
Polanco-Martínez, J. M., Fernández-Macho, J., Neumann, M. B., & Faria, S. H. (2018). A pre-crisis vs. crisis analysis of peripheral EU stock markets by means of wavelet transform and a nonlinear causality test. Physica A: Statistical Mechanics and its Applications, 490, 1211-1227. <URL: doi:10.1016/j.physa.2017.08.065>.
The plot_estim_RWWC
function plots the rolling window wavelet correlation (RWWC) coefficients that are statistically significant between two regular time series as a heat map and also plots the time series under study. The function is based on the work of Polanco-Martínez et al. (2018). plot_estim_RWWC
is fed by the function estim_RWWC
that is contained in our R package 'RolWinWavCor'.
plot_estim_RWWC(inputdata, DATES="null", wavcorinput, Wname, J, W, Align="center", vartsX="X", vartsY="Y", coltsX="black", coltsY="blue", CEXAXIS=1, CEXLAB=1)
plot_estim_RWWC(inputdata, DATES="null", wavcorinput, Wname, J, W, Align="center", vartsX="X", vartsY="Y", coltsX="black", coltsY="blue", CEXAXIS=1, CEXLAB=1)
inputdata |
A matrix of three columns: the first one is the time (regular or evenly spaced) and the other two columns are the variables under study. This data set is the same used in the function |
DATES |
This optional parameter contains the times of the time series under study. If this parameter is not provided it is computed using the |
wavcorinput |
This parameter contains the output of the function |
Wname |
Name of the wavelet filter used in the wavelet transform (MODWT) decomposition and must be the same that was used with the function |
J |
The maximum level of the MODWT decomposition and must be the same used with the function |
W |
The window-length or size of the window used when the rolling window wavelet correlation coefficients are estimated and this must have the same value that was used in |
Align |
This is used to align the rolling object and must be the same as used in the function |
vartsX , vartsY
|
Names of the first (e.g. “X”) and the second (e.g. “Y”) variable under study. |
coltsX , coltsY
|
The colors used to plot the first and second variable. By default the colors are black and blue for the first and second variable, respectively. |
CEXAXIS |
This parameter is used to plot the size of the X and Y axes. Its default value is 1. |
CEXLAB |
This parameter is used to plot the size of the X-axis and Y-axis labels. Its default value is 1. |
The plot_estim_RWWC
function plots the time series under analysis and the rolling window wavelet correlation coefficients that are statistically significant (within the 95% CI) as a heat map. This function is also based on the work of Polanco-Martínez et al. (2018).
Output: a multi-plot displayed via screen containing the time series under scrutiny and a heat map of the rolling window wavelet correlation coefficients that are statistically significant.
Josué M. Polanco-Martínez (a.k.a. jomopo).
Excellence Unit GECOS, IME, Universidad de Salamanca, Salamanca, SPAIN.
BC3 - Basque Centre for Climate Change, Leioa, SPAIN.
Web1: https://scholar.google.es/citations?user=8djLIhcAAAAJ&hl=en.
Web2: https://www.researchgate.net/profile/Josue-Polanco-Martinez.
Email: [email protected]
Acknowledgement:
We acknowledge to the Excellence Unit GECOS (grant reference number CLU-2019-03), Universidad de Salamanca for its funding support.
Polanco-Martínez, J. M., Fernández-Macho, J., Neumann, M. B., & Faria, S. H. (2018). A pre-crisis vs. crisis analysis of peripheral EU stock markets by means of wavelet transform and a nonlinear causality test. Physica A: Statistical Mechanics and its Applications, 490, 1211-1227. <URL: doi:10.1016/j.physa.2017.08.065>.
# We reproduce Figure 2 presented in Polanco-Martínez et al. (2018). datPIGS <- EU_stock_markets sindatePIGS <- datPIGS[-1] sindatePIGS <- sindatePIGS[c(1:5, 8)] lrdatPIGS <- apply(log(sindatePIGS), 2, diff) lrDATES <- as.Date(datPIGS[,1][-1]) tsdatPIGS <- ts(lrdatPIGS, start=1, freq=1) Nnam <- dim(tsdatPIGS)[2] lrdatPIGS <- lrdatPIGS[,1:Nnam] inputdata <- tsdatPIGS[,c(2,5)] Wname <- "la8" J <- 4 W <- 241 Align <- "center" rwwc <- estim_RWWC(inputdata, Wname, J, W, Align=Align) wavcor.output <- rwwc DATES <- lrDATES plot_estim_RWWC(inputdata, DATES=DATES, wavcor.output, Wname, J, W, Align=Align, CEXAXIS=1.2)
# We reproduce Figure 2 presented in Polanco-Martínez et al. (2018). datPIGS <- EU_stock_markets sindatePIGS <- datPIGS[-1] sindatePIGS <- sindatePIGS[c(1:5, 8)] lrdatPIGS <- apply(log(sindatePIGS), 2, diff) lrDATES <- as.Date(datPIGS[,1][-1]) tsdatPIGS <- ts(lrdatPIGS, start=1, freq=1) Nnam <- dim(tsdatPIGS)[2] lrdatPIGS <- lrdatPIGS[,1:Nnam] inputdata <- tsdatPIGS[,c(2,5)] Wname <- "la8" J <- 4 W <- 241 Align <- "center" rwwc <- estim_RWWC(inputdata, Wname, J, W, Align=Align) wavcor.output <- rwwc DATES <- lrDATES plot_estim_RWWC(inputdata, DATES=DATES, wavcor.output, Wname, J, W, Align=Align, CEXAXIS=1.2)