starvars: An R Package for Analysing Nonlinearities in Multivariate Time Series

Although linear autoregressive models are useful to practitioners in different fields, often a nonlinear specification would be more appropriate in time series analysis. In general, there are many alternative approaches to nonlinearity modelling, one consists in assuming multiple regimes. Among the possible specifications that account for regime changes in the multivariate framework, smooth transition models are the most general, since they nest both linear and threshold autoregressive models. This paper introduces the starvars package which estimates and predicts the Vector Logistic Smooth Transition model in a very general setting which also includes predetermined variables. In comparison to the existing R packages, starvars offers the estimation of the Vector Smooth Transition model both by maximum likelihood and nonlinear least squares. The package allows also to test for nonlinearity in a multivariate setting and detect the presence of common breaks. Furthermore, the package computes multi-step-ahead forecasts. Finally, an illustration with financial time series is provided to show its usage.


Introduction
Many economic and financial time series often behave differently during stress periods for the economic activity.For example, during the subprime mortgage financial crisis, the relationship between the financial sector and macroeconomic quantities changed justifying the use of a nonlinear model.The same is also true in the analysis of monetary policy, where positive and negative monetary policy shocks may have asymmetric effects, or in the investigation of the effectiveness of a fiscal policy, where some fiscal policy measures may depend on the phase of the business cycle, see for example Caggiano et al. (2015).When asymmetric effects are observed, the time series may follow different regimes.In order to understand the dynamics of such processes, Quandt (1958Quandt ( , 1960) ) firstly proposed a model where the coefficients of a linear model change in relation to the value of an observable stochastic variable.Afterwards, these models have been extended to time series analysis.Tong (1978) and Teräsvirta and Lim (1980) introduced the threshold autoregressive model, while Teräsvirta (1994) imagined that the transition between regimes could be smooth, which leads to the smooth transition autoregressive model (STAR) for univariate time series.
Since researchers are often interested in understanding the dynamics of time series in a multivariate framework, regime-switching models have also been extended to include multiple dependent variables.A vector nonlinear model was introduced by Tsay (1998), who defined a Threshold Vector Autoregressive (TVAR) model with a single threshold variable controlling the switching mechanism in each equation.The first vector model with a smooth transition was the smooth transition vector errorcorrection model (STVECM) introduced by Rothman, van Dijk, and Franses (2001).In this model, the same transition function controls the transition in each equation.Camacho (2004) proposed a bivariate logistic smooth transition model with the possibility to include exogenous regressors and specify a different transition variable for each equation.For a recent survey of vector TAR and STAR models, see Hubrich and Teräsvirta (2013).More recently, Teräsvirta and Yang (2014a) presented a modelling strategy for building a Vector Logistic Smooth Transition Regression (VLSTAR).This strategy includes linearity and misspecification tests for the conditional mean, and testing the constancy of the error covariance matrix.This article summarizes the procedure proposed in Teräsvirta and Yang (2014a) and illustrates the starvars package in R for estimating and testing of the VLSTAR model with a single transition variable.Several packages for the estimation of the univariate logistic autoregressive model (LSTAR) are already present in R. For example, Di Narzo, Aznarte, Stigler, and Tsung-wu (2020) in their tsDyn package provide functions to estimate and forecast both the STAR and the LSTAR models.Unfortunately, the tsDyn package, which focuses on nonlinear models in general, only allows for the estimation of a multivariate Threshold Vector Autoregressive (TVAR) model and does not allow for the inclusion of exogenous regressors.The RSTAR package, implemented by Balcilar (2016), estimates, forecasts, and analyses the smooth transition autoregressive model in the univariate case.Another possible way to model regime switches in a multivariate framework is through the MSBVAR by Brandt (2016), capable of estimating a Markov-switching autoregressive model.Still, this package does not permit to evaluate the relationship between the dependent variables and possible explanatory variables.
The here presented R package starvars (Bucci et al., 2022) is conceived for the nonlinear specification with a VLSTAR model of the relationship of multivariate time series exhibiting smooth nonlinear The R Journal Vol.14/1, March 2022 ISSN 2073-4859 relationships with both their lags and a set of explanatory variables.Even though this model has been mainly applied in financial setups, it could be used in all fields in which the nature of the dynamics of the dependent variables could be conceived somehow nonlinear and, specifically, following a logistic smooth transition model.The functionalities of the starvars package include: (i) modelling strategy, such as joint linearity testing of multivariate time series, or detecting the presence of co-breaks, (ii) estimation and (iii) prediction of the VLSTAR model, (iv) construction of realized covariances from high and low-frequency financial prices or returns.Two datasets (Realized and techprices) are included in the R package starvars.The former entails monthly observations for realized co-volatilities between the S&P 500, the Nikkei, the FTSE and the DAX indexes, the growth rate of the dividend yield and the earning price ratio, and the first difference of the inflation rate in the U.S., United Kingdom, Japan and Germany.The latter includes the data used in the example with the daily closing stock prices of Google, Microsoft and Amazon.
The outline of the paper is as follows.The following sections review the specification of the VLSTAR model, referring to Teräsvirta and Yang (2014a), and illustrate how to estimate and make predictions through the starvars package.We then present an empirical application to stock price data, while the last section concludes.

The Vector Logistic Smooth Transition Autoregressive Model
Assuming an n × 1 vector of dependent time series, y t , the multivariate smooth transition model introduced by Teräsvirta and Yang (2014a) can be written as follows where µ 0 and µ 1 are the n × 1 vectors of intercepts, Φ 0,j and Φ 1,j are square n × n matrices of parameters with lags j = 1, 2, . . ., p, A 0 and A 1 are n × k matrices of parameters, x t is the k × 1 vector of exogenous variables and ε t is the innovation.G t (s t ; γ, c) is a n × n diagonal matrix of transition function at time t, such that where γ i and c i are the scale and the threshold parameters for the i-th equation, for i = 1, . . ., n.
In the VLSTAR model, each element of G t is specified as a logistic function , by reformulating Equation (1) as in Teräsvirta and Yang (2014a) and extending for the presence of m regimes, Equation (1) becomes where Gt is a matrix of dimension n × mn, mn matrix and G 0 t = I n is an identity matrix indicating that no transitions are allowed before the first change of regime.This equation defines the VLSTAR model with m regimes and p lags for the dependent variables.

Joint linearity test
The VLSTAR specification procedure follows several steps.Firstly, the researcher should test whether the relationship between y t and z t can be linear.This is crucial, since several nonlinear models, like smooth transition and switching regression models, are not identified when the data-generating process is linear.With multivariate dependent variables, linearity can be tested equation by equation, using the Lagrange Multiplier (LM) test, as proposed by Luukkonen, Saikkonen, and Teräsvirta (1988), Teräsvirta (1994) and Teräsvirta, Tjøstheim, and Granger (2010), or it may be tested simultaneously, as introduced by Hubrich and Teräsvirta (2013) and Teräsvirta and Yang (2014b).
The LM type statistic can be computed, as further suggested by Teräsvirta and Yang (2014b), using a multi-step procedure: 1. estimation of the linear model, i.e. the restricted VLSTAR with γ = 0; 2. save a collection of the residuals (ε t ) from step 1 to create the residual matrix Ẽ of dimension T × n; 3. computation of the residual sum of squares matrix, Q = Ẽ′ Ẽ; 4. regression of Ẽ on X and where tr{•} is the trace of the matrix.
In the R package starvars, the joint linearity test can be performed by using the function VLSTARjoint, which takes the following arguments.
• y: a data.frameor matrix containing the T observations for the n time series whose linearity should be tested; • exo: an optional argument containing a data.frameor matrix of k explanatory variables; • st: a vector with the observations of the single transition variable (s t ), or a matrix with a set of potential transition variables; • st.choice: when the choice of the transition variable among a set of candidates should be based on the linearity test, this argument should be set equal to TRUE.In such a case, the variable in the matrix st which results in a higher LM statistics is the one chosen as the transition variable; • alpha: a decimal value comprised between 0 and 1 (α ∈ [0, 1]) representing the confidence level, set to 0.05 by default.
In this case, the residuals εt used in step 2 of the above-mentioned procedure are obtained through a VAR(p) estimation of the restricted model in step 1.This is done through the VAR function from R package vars, with an automatically selected number of lags, p.
VLSTARjoint(y, exo, st, st.choice = FALSE, alpha = 0.05) The function VLSTARjoint returns a list object with a class attribute "VLSTARjoint", for which print method exists, with three elements: the value(s) of the Lagrange Multiplier value (LM), the p-value(s) of the test and the critical value.
Furthermore, the specification of the VLSTAR model foresees the definition of the number of regimes to be used in the model (see Appendix A for further details).The function multiCUMSUM allows determining the number of common breaks and where they are located.multiCUMSUM(data, conf.level= 0.95, max.breaks = 7) The arguments necessary to detect the common breaks are: a matrix of T × n of time series, in the argument data; the confidence level in conf.level,set by default at 0.95; the number of maximum common breaks (between 1 and 7) to be identified, through max.breaks.The output is returned in a list with a class attribute "multiCUMSUM", which can be passed through the print function.The first element of the returned list object is a matrix with the test statistics Λ T and Ω T (see Equation ( 18) in Appendix A for details).The list further reports the index of the common breaks detected and the correspondent dates, as long as the critical values for both Λ T and Ω T .

VLSTAR Estimation
As widely discussed in Teräsvirta and Yang (2014a), a VLSTAR model can be estimated through a nonlinear Least Square (NLS) or a maximum likelihood (ML) model.
In both cases, the optimization algorithm may converge to some local minima, attributing to the definition of valid starting values of the estimated parameters a special relevance.If there is no clear indication of the initial values of γ and c, this can be done by implementing a grid search.Thus, a discrete grid in the parameter space is created to obtain the estimates of B conditionally on each point in the grid.The initial pairs of γ and c producing the smallest sum of squared residuals are chosen as initial values.A pair of these parameters for each equation is selected unless common parameters are assumed.Given their values, the model is linear in parameters.
The searching grid algorithm works as follows: 1. construction of the grid for γ and c, computing the vector of parameters for each point in the grid; 2. estimation of B in each equation through NLS and computation of the residual sum of squares, Q; 3. find the pairs of γ and c providing the smallest Q which will be the starting γ 0 and c 0 ; 4. estimation of parameters, B, via NLS or ML; 5. estimation of γ and c for each equation given the parameters found in step 4; 6. repeat steps 4 and 5 until convergence.
The starvars package allows the user to implement a searching grid algorithm to obtain the initial values of c and γ.Specifically, the practitioner may obtain initial values through the startingVLSTAR function among a set of potential values.For example, by providing n.combi= 50, 50 values of γ and c are combined in a grid of 2500 couples of values as in step 1 of the former procedure.The values of the grid for γ range from 0 to 100, while the values of c range from minimum to maximum of each dependent variable.
The startingVLSTAR function requires several arguments.A data.frame or a matrix of dimension T × n containing the dependent variables of the model, representing y.An optional argument, exo, contains possible explanatory variables and can be specified as a data.frameor a matrix with the same length of y and k columns.The lag-order p should be specified as an integer.The number of regimes in the model is set by the argument m, while the transition variable s t of length T is specified in the argument st.The number of cores used to make parallel computation is specified through the ncores argument, while the argument singlecgamma works as follows: • singlecgamma = TRUE: it is assumed a common pair of initial values for the entire model; • singlecgamma = FALSE: a pair of c and γ is obtained for each of the equations.

VLSTAR Estimation via NLS
The NLS estimator is defined as the solution to the following optimisation problem where θ is the set of parameters to be estimated.
In the aforementioned algorithm, the vectorization of the NLS estimates of B for step 4, given the values of γ and c, is equal to: The estimated errors covariance matrix is given by where Ê = (ε 1 , . . . ,εn ) ′ is a T × n matrix, and εt = y t − Gt B′ NLS z t is a column vector of residuals.This is used to obtain the first iterative ML estimation in the previous algorithm in step 4.

VLSTAR Estimation via ML
To estimate a VLSTAR model via ML, it must be assumed that ε t ∼ i.i.d.N(0, Ω).In this case, the model can be represented by the following multivariate conditional density function where I t is the information set at time t which contains all the exogenous variables x t and all the lags of y t .
In the first iteration of the algorithm presented in this section, Ω is estimated through Equation ( 9).Consequently, the ML estimator of θ is obtained by solving the optimization problem θML = arg max θ ℓ (y t |I t ; θ) .( 11)

Estimation in the starvars package
In the starvars package, the estimation of a VLSTAR model is handled with the function VLSTAR.
By fitting such a model via this function, a list object with a class attribute "VLSTAR" is obtained.This function requires the same arguments of the startingVLSTAR function, except for the number of combinations.In addition, a list of data.frame or matrix containing starting values of c and γ, for each of the m − 1 logistic functions as in Equation ( 5), must be passed through the argument starting.
The user can choose the method used to estimate the coefficients among the 'ML' and the 'NLS' through the specification of the argument method.The argument epsilon is used as a convergence check while the argument ncores denotes the number of cores used in the parallel optimization of the objective function.
VLSTAR(y, exo = NULL, p = 1, m = 2, st = NULL, constant = TRUE, starting = NULL, method = c('ML', 'NLS'), n.iter = 500, singlecgamma = TRUE, epsilon = 10^(-3), ncores = NULL) The summary method applied to an object derived from the VLSTAR function returns the sample size, along with the number of estimated parameters, the multivariate log-likelihood calculated as in Equation ( 10), and the estimated coefficients.We also provide other generic methods, such as plot, AIC, BIC and logLok.Similar to what is implemented in the R package vars, the plot function reports for each equation in the VLSTAR model the observed values of each time series, the fitted values and the residuals, as well as the autocorrelation and partial autocorrelation functions of the residuals.Since the logistic function plays a crucial role in VLSTAR models, the plot function shows also the plot of the logistic function for each dependent variable.

Forecasting a VLSTAR model
Time series prediction using nonlinear models has become widespread in the last few decades, even if the debate on the usefulness of such forecasts is still open (see Diebold and Nason, 1990;Kock and Teräsvirta, 2011).The forecasts of the nonlinear model, for more than one step ahead, can be generalised via numerical techniques.Given a nonlinear model where θ is a vector of parameters to be estimated, z t is a combination of lagged values of y t and exogenous variables x t , and ε t is a white noise with zero mean and constant variance σ 2 , the forecast of y t+h made at time t is equal to the conditional mean where I t is the information set at time t and ε t is independent of I t−1 .When h = 1, the forecast ŷt+1 = g(z t ) is obtained from Equation (13); if h ≥ 2, the prediction can only be calculated recursively using numerical techniques.
The nonlinearity in the VLSTAR model makes multi-period forecasting more complicated.In fact, forecasting two steps ahead is not straightforward, since we have The R Journal Vol.14/1, March 2022 ISSN 2073-4859 and consequently where Φ(v) is the cumulative distribution function for ε t+1 .It follows that to obtain the t + 2 forecast of y numerical integration would be necessary, while multiple integrations would be required for longer time horizons; see Lundbergh and Teräsvirta (2007).
The R package starvars can handle both one-step and multi-step-ahead forecasts of an object with a class attribute "VLSTAR".One-step-ahead forecasts can be easily extended to the multivariate framework by modifying Equation (4) as follows where B is the matrix of estimated parameters and , while Gt+1 is calculated using estimated values of γ and c.Multi-step-ahead forecasts are slightly trickier to be found and several alternatives can be used.As shown in Lundbergh and Teräsvirta (2007) for the univariate case, multi-step-ahead forecasts can be obtained in three ways: naively, by Monte Carlo simulation and by bootstrapping.The method predict in the starvars package allows the user to choose between these methods through the argument method.When the naive method is chosen, the y t+h forecasts are obtained as follows . If the transition variable is the lagged y t−s , with s < h, the prediction of the i-th element of y is used as a new transition variable, otherwise the new value of s t should be passed through the argument st.new.The index i is specified by the argument st.num, which denotes the column number of the dependent variable which should be used as a new transition variable.From Hubrich and Teräsvirta (2013), Kock and Teräsvirta (2011) and Teräsvirta et al. (2010), we know that these forecasts are biased.Thus, the practitioner may choose the Monte Carlo method.In this case, ε t+1 should be simulated using a properly defined error distribution.Let B1 = μ0 , Φ0,1 , . . .Φ0,p , Â0 and B2 = μ1 , Φ1,1 , . . ., Φ1,p , Â1 , the multivariate version of the Monte Carlo method for h steps ahead is given by Gt+h (s t+h ; γ, ĉ) B′ 2 z mc t+h where z mc t+h = 1, , ε mc t+h is a vector of errors sampled from a Multivariate Normal distribution with zero mean and covariance matrix Ω.In such a case, the interval forecasts are directly determined from the forecast density.Finally, the bootstrap method foresees that the multi-step-ahead forecasts are derived from , ε bo t+h is sampled from the T × n matrix of residuals.As in the case of the Monte Carlo method, the interval forecasts are derived from the forecast density.
predict(object, ..., n.ahead = 1, conf.lev = 0.95, st.new = NULL, st.num = NULL, newdata = NULL, method = c('naive', 'Monte Carlo', 'bootstrap')) The predict method returns a list with a class attribute "vlstarpred" and two elements: a list denoted with the name forecasts containing the predicted values and the interval forecasts for each of the steps ahead, and the matrix with the values of y.The print method is applicable to objects of this class and returns the forecasts with upper and lower interval forecasts.The plot method draws the time series plots with the interval forecasts in the out-of-sample period.

VLSTAR model compared to other linear and nonlinear models
The here applied VLSTAR model is one of the possible ways of modelling nonlinear relationships.Alternatively, nonlinearity in a multivariate framework can be modelled through a Threshold Vector Autoregression (TVAR) or Markov-switching Vector Autoregressive (MSVAR) model.The VLSTAR and the TVAR models are both based on the assumption that the variable that defines the regimeswitching is observable, while the MSVAR is mainly based on the assumption that regime-switches are defined by a latent Markov process.When the practitioner has enough information on the factors that drive the dynamics of the dependent variables, using VLSTAR or TVAR models may reduce the uncertainty related to the regimes and may produce more accurate predictions than an MSVAR model (see Hubrich and Teräsvirta, 2013).In other words, the VLSTAR is a model with a continuum of states where the change between a number of regimes is smooth, the TVAR is mostly conceived to analyse the dynamics of variables that switch abruptly between the regimes.The VLSTAR model can be seen as a general version of the TVAR that allows also for the regimes to change smoothly.Indeed, when γ → ∞ for each regime, the VLSTAR model becomes a TVAR model with well-defined changes of regimes.Conversely, when γ → 0, the model becomes a simple VAR model.
The starvars package further differs from the tsDyn and the MSBVAR by Brandt (2016) packages, which permit the estimation of the TVAR and MSVAR models, since it allows the use of exogenous variables in the estimation set.This is a useful tool since practitioners may control for potential explanatory variables different from lags of the dependent variable to obtain parameter estimates and dependent variables predictions.

Example
To illustrate how the R package starvars works in practical situations, we present an empirical application with multivariate time series of stock prices.Starting from the prices of n = 3 stocks of the tech companies, Amazon, Microsoft and Google, available in the dataset techprices, we model the monthly realized covariances assuming that their dynamics can be captured by a flexible specification like the VLSTAR model which nests the linear VAR.First, we construct the n(n + 1)/2 monthly series of realized covariances and their Cholesky factors which are modelled through VLSTAR.This solves the problem of obtaining positive semidefinite covariance matrices that can be used in finding optimal portfolios.Second, from the estimated VLSTAR, we can compute the forecasts of the monthly realized covariances, see Halbleib-Chiriac and Voev (2011); Bucci et al. (2019); Bucci (2020).In particular, asset returns co-volatilities tend to be higher when bad news is available.From Figure 1, it is clearly observable that co-volatilities explode during periods of market turmoil, like the subprime mortgage crisis in 2007 or the spread of the COronaVIrus Disease 19 (COVID-19) at the beginning of 2020.This explains why co-volatilities exhibit nonlinear behaviour.
The R Journal Vol.14/1, March 2022 ISSN 2073-4859 The techprices dataset used in this example includes the closing prices from January 1st 2005 to June 16th 2020, for a total of 3,890 observations per series.The dataset can be loaded in the workspace using > data("techprices", package = "starvars") where techprices is a 3, 890 × 3 xts object containing the daily prices.As a first step, we calculate the realized covariances of stock returns and their Cholesky factors.Since we have already daily prices, we can only build monthly, quarterly, or yearly realized covariances.To keep the sample of realized covariances quite large, we calculate monthly realized covariances and their Cholesky factors through the code (further discussed in Appendix B): > RCOV <-rcov(techprices, freq = "monthly", make.ret= TRUE, cholesky = TRUE) from which we obtain a list of two elements in the object RCOV.We are just interested in the Cholesky factors of the stock returns, thus we save the desired data.frame in the object techchol with a class "xts".
The R Journal Vol.14/1, March 2022 ISSN 2073-4859 The modelling strategy of a VLSTAR model starts with a test for the time series nonlinearities.As largely explained above, this can be done via the VLSTARjoint function.Since no information about which variable should be used as a transition variable is available, we let the linearity test choose among a set of potential variables which are equal to the first lag of the dependent variables.The LM statistics and the related p-value for a given value of alpha (set equal to 0.05 by default) and for the chosen transition variable can be obtained simply by running Joint linearity test (Third-order Taylor expansion) Transition variable chosen: y5 LM = 158.7 ; p-value = 2.0595e-21 Critical value for alpha = 40.646 The linearity test indicates the presence of nonlinearity in the data, and that the rejection of the null hypothesis is stronger when the lag of the fifth Cholesky factor, y5, is chosen as the transition variable.At this point, the practitioner should assess the presence of common breaks among the time series through the test presented in Appendix A. The test, for a maximum number of breaks equal to 3, is computed as follows.This function returns significant test statistics for all the breaks for Λ T and Ω T , which both identify a number of breaks equal to 2. To keep the model parsimonious, we decide to include a single break and m = 2 regimes in our example.

> multiCUMSUM(techchol
Given that a nonlinear model would be necessary and that at least a single break is present in the multivariate time series, a VLSTAR model can be estimated.Before estimating the parameters, we implement the searching grid algorithm to find starting values of γ and c with 20 potential values each (400 combinations).Specifying singlecgamma = FALSE we are supposing that each equation has its own parameters.Once executed the code, a progress bar is shown to inform the user about the completion of the searching grid algorithm.
> starting <-startingVLSTAR(techchol[-1,], p = 1, m = 2, st = st[,5], + n.combi = 20, singlecgamma = FALSE, ncores = 4) We employ an NLS estimation, with the lag of the fifth Cholesky factor as s t , a single lag p = 1, two regimes m = 2, a number of maximum iterations equal to 30 and a number of cores for parallel computation equal to 4, and we use the starting values found in the previous step of the procedure saved in the starting object.Therefore, we show the code used to specify the VLSTAR model as well as the summary output, and the graphic for the equation of the first Cholesky factor, y1.Coefficients regime 1 The R Journal Vol.After the execution of the code, a counter with the number of the iteration in the estimation algorithm is shown until convergence or the maximum number of iterations is reached.Using a laptop with an Intel ® Core™i5-7200U 2.5GHz processor with 16 GB RAM, the searching grid algorithm takes around 40 seconds to find optimal values of γ and c, while convergence is achieved after 7 iterations taking around 500 seconds (with the package version 1.1.10).The estimation process could take from a few minutes to several hours depending on the complexity of the model.The number of parameters increases with the number of dependent variables, the number of exogenous variables, and the number of regimes, therefore affecting the optimization problem and the convergence time.For example, the estimation of the former example with m = 3 regimes takes about an hour and 30 minutes.
The  Time series models are usually implemented to make out-of-sample predictions.In our package, this is possible through the predict method that, applied to objects of class "VLSTAR", returns an object with a class "vlstarpred".When using the predict function, the argument method = 'bootstrap' specifies that the aforementioned "bootstrap" method has been used to make predictions, while the argument n.ahead = 2 denotes that two-step-ahead predictions are obtained.The outcome of the plot method of the out-of-sample forecasts for the first Cholesky factor is exhibited in Figure 3.The predictions of the Cholesky factors could be used to obtain a semidefinite positive predicted covariance matrix by simply inverting the Cholesky decomposition.

Conclusion
This article introduces the R package starvars for modelling, estimating, and forecasting a Vector Logistic Smooth Transition Autoregressive (VLSTAR) model.We present the model specification in a general way and illustrate the package usage.In particular, we perform an empirical application using financial data.
The package allows practitioners in many scientific areas to perform their applied research using VLSTAR models in a user-friendly environment.The build-in framework permits to analyse nonlinearity of time series and make multi-step-ahead predictions via different methods.Further, the practitioner may use the starvars package to obtain realized covariances at several frequencies and the Cholesky decomposition of the related realized covariance matrices.
It should be reminded that the estimation of the parameters in a VLSTAR model strongly depends on the initial values of the parameter of the logistic.We have observed that sometimes the algorithm underlying the automatic grid search may lead to unrealistic estimates of the logistic parameters and, consequently, to not consistent estimates of coefficients.Moreover, the computational time, when using more than two regimes, might be compromised by a large number of coefficients and a possible local minimum may be found by the maximization of the log-likelihood.Thus, the suggestion is to use a limited number of regimes to keep the model as parsimonious as possible.
The code of the package starvars may be improved by using a different transition variable for each equation or by allowing the estimates of a univariate model.However, in both cases, the estimation would be reduced to a univariate model for each equation and there are already packages able to do this.

Availability
The here presented package is written using S4 classes and provides methodology such as coef, plot, AIC, BIC, logLik, summary and print to analyze the results.The R package starvars is available from the Comprehensive R Archive Network (CRAN) at https://cran.r-project.org/package=starvars and on GitHub at https://github.com/andbucci/starvars.
The R Journal Vol.14/1, March 2022 ISSN 2073-4859 7 Appendix A: Testing for common breaks If the linearity hypothesis is rejected, the researcher should determine the number of regimes of the dependent variable.To this end, the procedure introduced by Bai andPerron (1998, 2003) may be implemented.In presence of multivariate time series, it may happen that sudden shocks, such as market crashes, financial crises, or interventions of policymakers, result in a structural break in the mean of the observed time series (see Bai et al., 1998).At the same time, the interest of the researcher may be directed to changes in the structure of the conditional correlations (see Barassi et al., 2020;Aue et al., 2009).To detect the presence of structural breaks in the co-movements of the n time series, Aue, Hörmann, Horváth, and Reimherr (2009) introduced a test on the structure of the covariances.Here, we attempt to summarize the procedure 1 .
Let (y t : t ∈ Z) be a sequence of n time series, with E[y t ] = µ and E[|y t | 2 ] < ∞, where | • | denotes the Euclidean norm in ℜ n , then the null hypothesis in a test for structural breaks in the co-volatilities process is given by H 0 : Cov(y 1 ) = . . .= Cov(y T ) where T is the number of observations.This means that the covariances are constant over the observed period.A common alternative hypothesis would be that there is at least one change in the covariance structure which corresponds to the presence of at least one common break.
Provided that E[y t ] = 0, the test statistic is based on the constancy of the expected values E[vech(y t y ′ t )] for t = 1, . . ., T under H 0 .As a consequence, from the estimates of E[vech(y t y ′ t )] on j observations (with j < T), a traditional cumulative sum (CUSUM) statistic can be constructed as For the critical values of these statistics, it should be referred to Aue, Hörmann, Horváth, and Reimherr (2009).
Once the null hypothesis can be rejected, the researcher should find the location of both the breakpoint and the breakpoint fraction θ whose estimation is given by θ This can be repeated for each partition of the entire sample to obtain the optimal number and location of common breaks.On the basis of what is found with the test on common breaks, the number of regimes of the VLSTAR model can be assessed and parameters estimation can be performed.

Appendix B: Realized covariances construction
Along with the specification of a VLSTAR model, the R package starvars allows the user to calculate a non-parametric measure of volatility in the multivariate framework, such as the realized volatility (see Andersen et al., 2001Andersen et al., , 2003;;Barndorff-Nielsen and Shephard, 2002, for the theoretical fundamentals).Given a vector of stock returns, r τ sampled at a given frequency, τ, the realized covariance matrix, 1 See the original paper by Aue, Hörmann, Horváth, and Reimherr (2009) for the technical details.
The R Journal Vol.14/1, March 2022 ISSN 2073-4859 RC t observed at a lower frequency t is simply given by where N t is the number of observations in the t-th period and t = 1, . . ., T.
The function rcov in the package starvars returns the lower triangular of RC t starting both from stock prices or returns, and to calculate it for different frequencies.
rcov(data, freq = c('daily', 'monthly', 'quarterly', 'yearly'), make.ret= TRUE, cholesky = FALSE) The function consists of several arguments.An object of class "xts" with the values of stock prices or returns on which the realized covariances should be calculated.The frequency of t, which could be daily, monthly, quarterly or yearly.The boolean argument make.retdenotes whether the data passed as input in the argument data should be converted to returns, if TRUE the returns are calculated.Finally, since a wide strand of the literature relies on the Cholesky factors of RC t to make inference or predictions (see Becker, Clements, and O'Neill, 2010;Halbleib-Chiriac and Voev, 2011;Bucci, Palomba, and Rossi, 2019;Bucci, 2020, for example), the function also allows the user to calculate the Cholesky factors, L t , such that RC t = L t L ′ t .This can be done by setting the argument cholesky equal to TRUE.If make.ret is set equal to TRUE, the output of the function rcov contains an element of class "xts" with the returns.
When cholesky = TRUE, the output of the rcov function is a list containing the T × n(n + 1)/2 xts object from the vectorization of the realized covariance matrices, given by vech(RC t ), and the T × n(n + 1)/2 of the vectorization of L t , given by vech(L t ), otherwise it includes only the series of realized covariances.

Figure 1 :
Figure 1: Plots of realized covariances of the stock returns.The panels report the realized variances (one stock symbol, i.e. first, third and last panel) and covariances (two symbols, i.e. second, third and fifth panel) between the considered stocks.'GOOG' is the stock symbol of Google, 'MSFT' is the stock symbol of Microsoft, and 'AMZN' is the stock symbol of Amazon.The time series show several peaks during periods of financial market stress such as the sub-prime mortgage crisis and the COVID-19 pandemic in 2021, which may underline a nonlinear behaviour of co-volatilities.

Figure 2 :
Figure 2: Plots of results from VLSTAR estimation for the Equation of y1.The first panel shows the observed time series (in black) versus the fitted time series (in dashed blue).The second panel shows the residuals and highlights the zero with a red horizontal line.The left side of the third panel reports the autocorrelation function of the residuals, while the right side reports the partial autocorrelation function of the residuals.The fourth panel is about the logistic function that regulates the regime switches.The residual time series of y1 seems to show poor autocorrelation, while the regime switches appear to be quite smooth.

Figure 3 :
Figure3: Out-of-sample predictions of time series y1.The plot shows the observed time series in-sample (in dashed black), the two-step ahead out-of-sample predictions (in dashed blue), and their 95% prediction interval (in dashed red).A vertical grey line denotes the end of the in-sample observations.The predictions of time series y1 highlight that the prediction interval is extremely tight and that predictions can be nonlinear.