findstysols {costat}R Documentation

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


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.


findstysols(Nsims = 100, Ncoefs = 3, tsx, tsy, sf=100, = FALSE,, verbose = FALSE, lctsfn=LCTS, prodcomb.fn=prodcomb,
        filter.number=1, family=c("DaubExPhase", "DaubLeAsymm"),
	my.maxit=500, spec.filter.number=1,"DaubExPhase","DaubLeAsymm"),
        optim.control=list(maxit=my.maxit, reltol=1e-6),
        irng=rnorm, lapplyfn=lapply, Bsims=200, ...)



Number of searches attempted


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 centrally located jump), "3" means one coarse, and two next coarse scale coefficients (corresponds to piecewise constant with 4 equally sized piece with jumps at 1/4, 1/2 and 3/4), "7" means one coarse, two next coarse, four next coarse, and so on.


One of the time series


The other time series, values at the same time locations as tsx


A scale factor to multiply both time series by (not really of much use)

If TRUE then the argument passed to LCTS via optim is made TRUE. This has the effect of plotting the results of every trial in the optimation (what actually is plotted is described in the help to LCTS

Not currently used in this function, reserved for future use


If TRUE then helpful messages get printed.


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.


The function that can produce the linear combination of the two time series and return the combination, and optionally vectors containing the combination functions.


Gets passed to lctsfn and prodcomb.fn


Gets passed to lctsfn and prodcomb.fn


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)


Wavelet filter number. This argument gets passed to the lctsfn and is used for the wavelet for all spectral smoothing.

Same as spec.filter.number but for the wavelet family.


Argument passed to the optim optimizer as its control argument. optim performs optimization. See help page for optim.


Random number generator used to generate coefficients for starting parameters for the linear combination of time series (actually wavelet coefficients of the combination functions)


Function to use to process lists. If this argument is mclapply then the multicore library function mclapply is used to parallel process the lists. If you don't have multicore then the lapply function can be used to process things sequentially.


The number of bootstrap simulations for the (single) test of stationarity BootTOS.


Other arguments, passed to the optim call.


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 α_t, β_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 = α_t x_t + β_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. If the lapplyfn is set to mclapply then this function from the multicore package is used to process the lists in parallel.

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 α_t, β_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.


An object of class csFSS which is a list with the following components.


A 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 α_t coefficients, the second Ncoefs numbers correspond to the β_t coefficients.


Same 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).


A vector of length Nsims. Reports the convergence code from optim for each optimization run. A value of 0 indicates successful convergence.


A vector of length Nsims. Contains the minimum variance achieved on each run.


A vector of length Nsims. Contains the p-values achieved on each run.


The tsx time series that was supplied to this function


The tsy time series that was supplied to this function


The name of the tsx object that was supplied


The name of the tsy object that was supplied


The filter number that was used


The wavelet family that was used


The filter number that was used

The wavelet family that was used


Guy Nason


Cardinali, A. and Nason, Guy P. (2013) Costationarity of Locally Stationary Time Series Using costat. Journal of Statistical Software, 55, Issue 1.

Cardinali, A. and Nason, G.P. (2010) Costationarity of locally stationary time series. J. Time Series Econometrics, 2, Issue 2, Article 1.

See Also

LCTS, BootTOS,plotBS, prodcomb, COEFbothscale, LCTSres, print.csFSS, summary.csFSS, plot.csFSS


# Find some stationary solutions with \code{Ncoefs=3}.
# Note: this is a toy example
tsx1 <- rnorm(32)	# A x time series
tsy1 <- rnorm(32)	# A y time series
# Find costationary solutions, but only from 2 random starts
# Typically, the length of tsx and tsy would be bigger (eg sret, fret are
# other examples you might use). Also, Nsims would be bigger, you need
# to use many random starts to ensure good coverage of the solution
# space, e.g. Nsims=100
# Note: the following examples are not run so as to adhere to CRAN
# requirements for package execution timings
## Not run: ans <- findstysols(Nsims=3, tsx=tsx1, tsy=tsy1)
# Print out a summary of the results
## Not run: ans
#Class 'csFSS' : Stationary Solutions Object from costat:
#       ~~~~~  : List with 13 components with names
#              startpar endpar convergence minvar pvals tsx tsy tsxname tsyname
#		filter.number family spec.filter.number 
#Name of X time series:  tsx1 
#Name of Y time series:  tsy1 
#Length of input series:  32 
#There are  3  sets of solutions
#Each solution vector is based on  3  coefficients
#Some solutions did not converge, check convergence component for more information.
#Zero indicates successful convergence, other values mean different things and
#you should consult the help page for `optim' to discover what they mean
#For size level:  0.05 
#	 0  solutions appear NOT to be stationary
#	 3  solutions appear to be stationary
#Range of p-values: ( 0.93 , 0.995 )
#Wavelet filter for combinations:  1   DaubExPhase 
#Wavelet filter for spectrum:  1   DaubExPhase 
# Ok. The printout above suggests that some solutions did not converge.
# Which ones?
## Not run: ans$convergence
# [1] 0 1 0 
# The second one did not converge, the others did. Good. The printout
# above also indicates that all the resultant solutions were stationary
# (this is not surprising for this example, as the inputs tsx1 and tsy1
# are stationary, and indeed iid).
# Let's see how the solutions compare. For example, let's plot the
# hierarchical cluster analysis of the final solutions (those that
# converged and are stationary)
## Not run: plot(ans, ALLplotscale=FALSE)
# My cluster shows that solution 1 and 3 are similar. Let's
# view solution 3.
## Not run: oldpar <- par(mfrow=c(2,2))
## Not run: plot(ans, solno=3)
## Not run: par(oldpar)

[Package costat version 2.4 Index]