# fit.pci: Fits the partial cointegration model to a collection of time... In partialCI: Partial Cointegration

## Description

Fits the partial cointegration model to a collection of time series

## Usage

 ```1 2 3 4 5``` ```fit.pci(Y, X, pci_opt_method = c("jp", "twostep"), par_model = c("par", "ar1", "rw"), lambda = 0, robust = FALSE, nu = 5) ```

## Arguments

 `Y` The time series that is to be modeled. A plain or `zoo` vector of length `n`. `X` A (possibly `zoo`) matrix of dimensions `n` x `k`. If `k=1`, then this may be a plain or `zoo` vector. `pci_opt_method` Specifies the method that will be used for finding the best fitting model. One of the following: "jp" The joint-penalty method (see below) "twostep" The two-step method (see below) Default: `jp` `par_model` The model used for the residual series. One of the following: "par" The residuals are assumed to follow a partially autoregressive model. "ar1" The residuals are assumed to be autoregressive of order one. "rw" The residuals are assumed to follow a random walk. Default: `par` `lambda` The penalty parameter to be used in the joint-penalty (`jp`) estimation method. Default: 0. `robust` If `TRUE`, then the residuals are assumed to follow a t-distribution with `nu` degrees of freedom. Default: `FALSE`. `nu` The degrees-of-freedom parameter to be used in robust estimation. Default: 5.

## Details

The partial cointegration model is given by the equations:

Y[t] = beta * X[t,1] + beta * X[t,2] + ... + beta[k] * X[t,k] + M[t] + R[t]

M[t] = rho * M[t-1] + epsilon_M[t]

R[t] = R[t-1] + epsilon_R[t]

-1 < rho < 1

epsilon_M[t] ~ N(0, sigma_M^2)

epsilon_R[t] ~ N(0, sigma_R^2)

Given the input series `Y` and `X`, this function searches for the parameter values `beta`, `rho` that give the best fit of this model when using a Kalman filter.

If `pci_opt_method` is `twostep`, then a two-step procedure is used. In the first step, a linear regression is performed of `X` on `Y` to determine the parameter `beta`. From this regression, a series of residuals is determined. In the second step, a model is fit to the residual series. If `par_model` is `par`, then a partially autoregressive model is fit to the residual series. If `par_model` is `ar1`, then an autoregressive model is fit to the residual series. If `par_model` is `rw` then a random walk model is fit to the residual series. Note that if `pci_opt_method` is `twostep` and `par_model` is `ar1`, then this reduces to the Engle-Granger two-step procedure.

If `pci_opt_method` is `jp`, then the joint-penalty procedure is used. In this method, the parameter`beta` are estimated jointly with the parameter `rho` using a gradient-search optimization function. In addition, a penalty value of lambda * sigma_R^2 is added to the Kalman filter likelihood score when searching for the optimum solution. By choosing a positive value for `lambda`, you can drive the solution towards a value that places greater emphasis on the mean-reverting component.

Because the joint-penalty method uses gradient search, the final parameter values found are dependent upon the starting point. There is no guarantee that a global optimum will be found. However, the joint-penalty method chooses several different starting points, so as to increase the chance of finding a global optimum. One of the chosen starting points consists of the parameters found through the two-step procedure. Because of this, the joint-penalty method is guaranteed to find parameter values which give a likelihood score at least as good as those found using the two-step procedure. Sometimes the improvement over the two-step procedure is substantial.

## Value

An object of class `pci.fit` containing the fit that was found. The following components may be of interest

 `beta` The vector of weights `beta.se` The standard errors of the components of `beta` `rho` The estimated coefficient of mean reversion `rho.se` The standard error of `rho` `negloglik` The negative of the log likelihood `pvmr` The proportion of variance attributable to mean reversion

## Author(s)

Matthew Clegg matthewcleggphd@gmail.com

Christopher Krauss christopher.krauss@fau.de

Jonas Rende jonas.rende@fau.de

## References

Clegg, Matthew, 2015. Modeling Time Series with Both Permanent and Transient Components using the Partially Autoregressive Model. Available at SSRN: http://ssrn.com/abstract=2556957

Clegg, Matthew and Krauss, Christopher, 2018. Pairs trading with partial cointegration. Quantitative Finance, 18(1), 121 - 138.

`egcm` Engle-Granger cointegration model
`partialAR` Partially autoregressive models
 ```1 2 3 4 5 6 7``` ```##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. YX <- rpci(n=1000, beta=c(2,3,4), sigma_C=c(1,1,1), rho=0.9,sigma_M=0.1, sigma_R=0.2) fit.pci(YX[,1], YX[,2:ncol(YX)]) ```