Learn R Programming

costat (version 1.1-1)

findstysols: Given two time series find some time-varying linear combinations that are stationary.

Description

Find some time-varying linear combinations of two time series that are stationary. The complexity of the time-varying combinations is restricted by the Ncoefs argument.

Usage

findstysols(Nsims = 100, Ncoefs = 3, tsx, tsy, sf=100, plot.it = FALSE,
	print.it=FALSE, verbose = FALSE, lctsfn=LCTS, prodcomb.fn=prodcomb,
	filter.number=1, family="DaubExPhase", my.maxit=500)

Arguments

Nsims
Number of searches attempted
Ncoefs
Number of Haar wavelet coefficients to use. Must be >= 1. Should only increase in steps of powers of two. E.g. can only supply the values 1, 3, 7, 15, etc. So, "1" means only one coarse scale coefficient (corresponds to piecewise constant with one cen
tsx
One of the time series
tsy
The other time series, values at the same time locations as tsx
sf
A scale factor to multiply both time series by (not really of much use)
plot.it
If TRUE then the plot.it argument passed to LCTS via optim is made TRUE. This has the effect of plotting the results of every trial in the optimation (wha
print.it
Not currently used in this function, reserved for future use
verbose
If TRUE then helpful messages get printed.
lctsfn
The function to compute the `linear combination test of stationarity'. I.e. it is the function that combines the two series and returns the value of the test statistic on the combination.
prodcomb.fn
The function that can produce the linear combination of the two time series and return the combination, and optionally vectors containing the combination functions.
filter.number
Gets passed to lctsfn and prodcomb.fn
family
Gets passed to lctsfn and prodcomb.fn
my.maxit
Maximum number of iterations in the optimization. May need to be increased to, e.g. 1000 or 2000 for longer time series (e.g. T=2048)

Value

  • A list with the following components.
  • startparA matrix with Nsims rows and 2*Ncoefs columns containing the initial random coefficients of the linear combination functions, one row for each optimization run. The first Ncoefs numbers on each row correspond to the $\alpha_t$ coefficients, the second Ncoefs numbers correspond to the $\beta_t$ coefficients.
  • endparSame dimension as startpar except containing the final coefficients obtained after running the optimizer. If, for a particuar run, the optimizer converged and the p-value is less than 0.05 then one can say that this solution represents a valid time-varying linear combination where the combination is stationary (coefficient storage format as for startpar).
  • convergenceA vector of length Nsims. Reports the convergence code from optim for each optimization run. A value of 0 indicates successful convergence.
  • minvarA vector of length Nsims. Contains the minimum variance achieved on each run.
  • pvalsA vector of length Nsims. Contains the p-values achieved on each run.

Details

The function searches for time-varying linear combinations of two time series, tsa and tsy, such that the combination is stationary (according to the TOSts test statistic).

Each linear combination is parametrised by a coarse scale Haar wavelet decomposition (controlled by Ncoefs). Initially, the Haar wavelet coefficients (up to a fixed finite scale, controlled by Ncoefs) are randomly chosen. These coefficients are converted to functions $\alpha_t, \beta_t$ by the coeftofn function and then a linear combination with the time series is formed out of those and the time series, i.e. $Z_t = \alpha_t x_t + \beta_t y_t$ The non-stationarity of $Z_t$ is measured using the TOSts test statistic and this value is minimized over the coarse scale Haar wavelet coefficients.

This optimization procedure is repeated Nsims times.

This function can be called multiple times (e.g. on different processors in a multiprocessor environment. The result sets from different runs can be combined using the mergexy function.

The variance Ncoefs is very important, it controls the complexity of the linear combinations. If it is too big the linear combinations themselves can be extremely oscillatory and stationarity is easy to obtain. Small values of Ncoefs results in piecewise constant functions with fewer jumps.

The Ncoefs value must take the value of $2^k - 1$. If this is the case the $k$ is the number of scale levels present in the Haar representation of the combining function $\alpha_t, \beta_t$ (excluding the scaling function coefficient, just the wavelet coefficients from the coarsest scale).

The functions to compute the linear combination and also the test statistic on that combination, and just to compute the combination and return also (optionally) the combination vectors are supplied in lctsfn and prodcomb.fn. By default, these are just the LCTS and prodcomb functions. However, it is possible to recode these to look at operating on combinations that operate on portfolios. I.e. rather than look at linear combinations of log-returns (which if tsx and tsy were) one can look at linear combinations of actual series (ie portfolios) and then look for stationarity of log-returns of the portfolios. These functions will be made available in a later package.

References

`Costationarity and stationarity tests for stock index returns' by Cardinali and Nason.

See Also

LCTS, myTOS,plotBS, prodcomb, COEFscale, COEFbothscale, LCTSres

Examples

Run this code
#
# Find some stationary solutions with \code{Ncoefs=3}.
#
# (not run in R package installation as its compute intensive) 
#
tmp <- findstysols(Nsims=10, tsx=x2, tsy=y2)
#
# Here are my results from this call
#
tmp
#
#$startpar
#            [,1]        [,2]        [,3]       [,4]       [,5]       [,6]
#[1,] -2.2547452 -0.77196922 -0.52060764 -0.8593779  0.6733086  1.4768199
#[2,] -2.3211605 -0.04410615  0.15945799 -1.5154560 -1.5176482  0.1374697
#[3,] -0.7792824 -0.85653735  0.40063430  0.9371025  0.1987466 -0.9809195
#[4,] -0.3141137 -0.13877435 -0.39190827  1.4200912 -0.1809564  0.5827172
#[5,] -1.3527352  0.78055909 -0.63661402 -0.2365094 -0.3829789 -0.8137181
#[6,]  0.3049843 -0.70033280  0.01900144  0.4765084 -0.7540503 -2.0909379
#[7,]  1.0726596 -1.09382977  0.62279794  0.3470011  1.1275294  0.8646476
#[8,]  0.9281181 -0.16476371  1.01723416  0.6716444 -0.6169555  0.5984466
#[9,] -1.2719359 -0.08608032  0.50967856 -0.9645608  0.4374194  0.4465487
#[10,] -0.8540283  1.07240182  0.22499203 -0.7814163  0.5153788 -0.4387466
#
#[1,]     0.8654740
#[2,]    -4.0003431
#[3,]    -0.9556344
#[4,]     0.7849405
#[5,] -4016.6360353
#[6,]    -1.9475162
#[7,]     1.4951978
#[8,]     0.2847806
#[9,]     2.4693086
#[10,]   166.0928567
#
#$convergence
#[1]  0  0  1  1 10  0  1  1  0  1
#
#$minvar
#[1] 5.409046e-07 2.187609e-07 2.270164e-07 1.975476e-07 1.941969e-07
#[6] 1.650412e-07 2.410830e-07 2.103711e-07 2.064031e-07 2.122840e-07
#
#$pvals
#[1] 0.32 0.45 0.00 0.39 0.24 0.28 0.54 0.37 0.32 0.44
#
#
# From the $convergence list only 4 converged (solns 1, 2, 6 and 9)
#
# Of these 4, what are the associated p-values?
#
tmp$pvals[tmp$convergence==0]
#[1] 0.32 0.45 0.28 0.32
#
# So, all of these are > 0.05, so apparently each of these solutions are
# stationary.
#
# We can further examine these solutions with \code{\link{COEFbothscale}}
# and optionally \code{\link{COEFscale}}.
#
# E.g.
COEFbothscale(tmp)
#
# This extracts the solution vectors for those where the optimizer converged
# and where the solutions are deemed stationary. Then those are subjected
# to a hierarchical clustering and plotted. So, we can see which solutions
# are similar and which are different.
#
# The function \code{\link{LCTSres}} can produce pictures of the results
# for particular solutions. E.g. the linear combination vectors, the combined
# series and its estimated spectrum.

Run the code above in your browser using DataLab