Note that this command will run the ADF test with a constant and the lags selected by the AIC command, with maximum lag of 10. If you have problems interpreting the results just look at this questionthis question. If the series are I(1) just use the difference, which will be equal to the continuously compounded returns. If the test indicates that the series are I(2) and you are in doubt about that you can use other tests, e.g. Phillips-Perron test (PP.test
function in R). If all tests confirm that your series are I(2) (remember to use the log of the series before running the tests) then take the second difference, but note that your interpretation of the results will change, since now you are working with the difference of the continuously compounded returns. Prices of assets are usually I(1) since they are close to a random walk, which is a white noise when applying the first difference.
Note that this command will run the ADF test with a constant and the lags selected by the AIC command, with maximum lag of 10. If you have problems interpreting the results just look at this question. If the series are I(1) just use the difference, which will be equal to the continuously compounded returns. If the test indicates that the series are I(2) and you are in doubt about that you can use other tests, e.g. Phillips-Perron test (PP.test
function in R). If all tests confirm that your series are I(2) (remember to use the log of the series before running the tests) then take the second difference, but note that your interpretation of the results will change, since now you are working with the difference of the continuously compounded returns. Prices of assets are usually I(1) since they are close to a random walk, which is a white noise when applying the first difference.
Note that this command will run the ADF test with a constant and the lags selected by the AIC command, with maximum lag of 10. If you have problems interpreting the results just look at this question. If the series are I(1) just use the difference, which will be equal to the continuously compounded returns. If the test indicates that the series are I(2) and you are in doubt about that you can use other tests, e.g. Phillips-Perron test (PP.test
function in R). If all tests confirm that your series are I(2) (remember to use the log of the series before running the tests) then take the second difference, but note that your interpretation of the results will change, since now you are working with the difference of the continuously compounded returns. Prices of assets are usually I(1) since they are close to a random walk, which is a white noise when applying the first difference.
Now you shouldcan use unit root tests to check if your series are stationary. You've doneIf you are only interested in forecasting, as noted by @JacobH, you can run VAR in levels even when your series are non-stationary, but then your standard errors cannot be trusted, meaning that you can't make inference about the value of the coefficients. You've tested stationary using the ADF test, which is very commonly used in these applications, but note that you should specify if you want to run the test with i) no constant and no trend; ii) a constant and no trend; and iii) a constant and a trend. Usually price series have stochastic trends, so a linear trend will not be accurate. In this case you may choose the specification ii. In your code you used the ndiffs
function of the forecast package. I am not sure which of those three alternatives this function implements in order to calculate the number of differences (I couldn't find it in the documentation). To check your result you may want to use the ur.df
function in the "urca" package:
If all your series are I(1) or I(2), before running a VAR model you need, it is usually a good idea to make surecheck if there is no cointegration relationships between the series, specially if you want to avoid spurious regressionsmake impulse response analysis with the residuals. You can do that using the Johansenn test or the Engle-Granger (only for bivariate models). In R you can run the Johansen test with the ca.jo
function of the "urca" package. Note that this test also has different specifications. For price series I usually use the following code (where p
is the lag length of item 4, performed with the series in levels):
Now you should use unit root tests to check if your series are stationary. You've done that using the ADF test, which is very commonly used in these applications, but note that you should specify if you want to run the test with i) no constant and no trend; ii) a constant and no trend; and iii) a constant and a trend. Usually price series have stochastic trends, so a linear trend will not be accurate. In this case you may choose the specification ii. In your code you used the ndiffs
function of the forecast package. I am not sure which of those three alternatives this function implements in order to calculate the number of differences (I couldn't find it in the documentation). To check your result you may want to use the ur.df
function in the "urca" package:
If all your series are I(1) or I(2), before running a VAR model you need to make sure there is no cointegration relationships between the series to avoid spurious regressions. You can do that using the Johansenn test or the Engle-Granger (only for bivariate models). In R you can run the Johansen test with the ca.jo
function of the "urca" package. Note that this test also has different specifications. For price series I usually use the following code (where p
is the lag length of item 4, performed with the series in levels):
Now you can use unit root tests to check if your series are stationary. If you are only interested in forecasting, as noted by @JacobH, you can run VAR in levels even when your series are non-stationary, but then your standard errors cannot be trusted, meaning that you can't make inference about the value of the coefficients. You've tested stationary using the ADF test, which is very commonly used in these applications, but note that you should specify if you want to run the test with i) no constant and no trend; ii) a constant and no trend; and iii) a constant and a trend. Usually price series have stochastic trends, so a linear trend will not be accurate. In this case you may choose the specification ii. In your code you used the ndiffs
function of the forecast package. I am not sure which of those three alternatives this function implements in order to calculate the number of differences (I couldn't find it in the documentation). To check your result you may want to use the ur.df
function in the "urca" package:
If all your series are I(1) or I(2), before running a VAR model, it is usually a good idea to check if there is no cointegration relationships between the series, specially if you want to make impulse response analysis with the residuals. You can do that using the Johansenn test or the Engle-Granger (only for bivariate models). In R you can run the Johansen test with the ca.jo
function of the "urca" package. Note that this test also has different specifications. For price series I usually use the following code (where p
is the lag length of item 4, performed with the series in levels):
Now you should use unit root tests to check if your series are stationary. You've done that using the ADF test, which is very commonly used in these applications, but note that you should specify if you want to run the test with i) no constant and no trend; ii) a constant and no trend; and iii) a constant and a trend. Usually price series have stochastic trends, so a linear trend will not be accurate. In this case you may choose the specification ii. In your code you used the ndiffsndiffs
function of the forecast package. I am not sure which of those three alternatives this function implements in order to calculate the number of differences (I couldn't find it in the documentation). To check your result you may want to use the ur.dfur.df
function in the urca"urca" package:
Note that this command will run the ADF test with a constant and the lags selected by the AIC command, with maximum lag of 10. If you have problems interpreting the results just look at this question. If the series are I(1) just use the difference, which will be equal to the continuously compoundcompounded returns. If the test indicates that the series are I(2) and you are in doubt about that you can use other tests, e.g. Phillips-Perron test (PP.testPP.test
function in R). If all tests confirm that your series are I(2) (remember to use the log of the series before running the tests) then take the second difference, but note that your interpretation of the results will change, since now you are working with the difference of the continuously compoundcompounded returns. PricePrices of assets are usually I(1) since they are close to a random walk, which is a white noise when applying the first difference.
This can be done with commonly used criteriascriteria such as Akaike, Schwarz (BIC) and Hannan-Quinn. You've done that with the VARselectVARselect
function and that is right, but remember what is the criteriacriterion that you used to make your decision. Usually different criteriascriteria indicate different orders for the VAR.
If all your series are I(1) or I(2), before running a VAR model you need to make sure there is no cointegration relationships between the series to avoid spurious regressions. You can do that using the Johansenn test or the Engle-Granger (only for bivariate models). In R you can run the JohansennJohansen test with the ca.joca.jo
function of the urca"urca" package. Note that this test also has different specifications. For price series I'llI usually use the following code (where pp
is the lag length of item 4, performed with the series in levels):
jo_eigen <- ca.jo(x, type = "eigen", ecdet = "const", K = p) jo_trace <- ca.jo(x, type = "trace", ecdet = "const", K = p)
jo_eigen <- ca.jo(x, type = "eigen", ecdet = "const", K = p)
jo_trace <- ca.jo(x, type = "trace", ecdet = "const", K = p)
If your series are not cointegrated, you can easily estimate the model with the VARVAR
command, as done in your code. In case the series are cointegrated you need to consider the long run relationship by estimating a Vector Error Correction model with the following code (where kk
is the order of cointegration):
vecm <- cajorls(joeigen, r = k)
vecm <- cajorls(joeigen, r = k)
To test if your model is well specified you can run a test of serial correlation on the residuals. In your code you used a Portmanteau test with the serial.testserial.test
function. I've never used this function but I think it is okOK. There is also a multivariate version of the Ljung-Box test implemented in the package MTS which you can run with the function mqmq
.
After you are sure your model is well specified you can use the predictpredict
function as you did in your code. You can even plot impulse response functions to check how the variables respond to a particular shock using the irfirf
function.
Once you made your predictions you must evaluate them and compare against other models. Some methods to evaluate accuracy of forecasts can be found here, but to do that it is crucial that you divide your series in a traintraining and a test set, as explained in the link.
Now you should use unit root tests to check if your series are stationary. You've done that using the ADF test, which is very commonly used in these applications, but note that you should specify if you want to run the test with i) no constant and no trend; ii) a constant and no trend; and iii) a constant and a trend. Usually price series have stochastic trends, so a linear trend will not be accurate. In this case you may choose the specification ii. In your code you used the ndiffs function of the forecast package. I am not sure which of those three alternatives this function implements in order to calculate the number of differences (I couldn't find it in the documentation). To check your result you may want to use the ur.df function in the urca package:
Note that this command will run the ADF test with a constant and the lags selected by the AIC command, with maximum lag of 10. If you have problems interpreting the results just look at this question. If the series are I(1) just use the difference, which will be equal to the continuously compound returns. If the test indicates that the series are I(2) and you are in doubt about that you can use other tests, e.g. Phillips-Perron test (PP.test function in R). If all tests confirm that your series are I(2) (remember to use the log of the series before running the tests) then take the second difference, but note that your interpretation of the results will change, since now you are working with the difference of the continuously compound returns. Price of assets are usually I(1) since they are close to a random walk, which is a white noise when applying the first difference.
This can be done with commonly used criterias such as Akaike, Schwarz (BIC) and Hannan-Quinn. You've done that with the VARselect function and that is right, but remember what is the criteria that you used to make your decision. Usually different criterias indicate different orders for the VAR.
If all your series are I(1) or I(2), before running a VAR model you need to make sure there is no cointegration relationships between the series to avoid spurious regressions. You can do that using the Johansenn test or the Engle-Granger (only for bivariate models). In R you can run the Johansenn test with the ca.jo function of the urca package. Note that this test also has different specifications. For price series I'll usually use the following code (where p is the lag length of item 4, performed with the series in levels):
jo_eigen <- ca.jo(x, type = "eigen", ecdet = "const", K = p) jo_trace <- ca.jo(x, type = "trace", ecdet = "const", K = p)
If your series are not cointegrated, you can easily estimate the model with the VAR command, as done in your code. In case the series are cointegrated you need to consider the long run relationship by estimating a Vector Error Correction model with the following code (where k is the order of cointegration):
vecm <- cajorls(joeigen, r = k)
To test if your model is well specified you can run a test of serial correlation on the residuals. In your code you used a Portmanteau test with the serial.test function. I've never used this function but I think it is ok. There is also a multivariate version of the Ljung-Box test implemented in the package MTS which you can run with the function mq.
After you are sure your model is well specified you can use the predict function as you did in your code. You can even plot impulse response functions to check how the variables respond to a particular shock using the irf function.
Once you made your predictions you must evaluate them and compare against other models. Some methods to evaluate accuracy of forecasts can be found here, but to do that it is crucial that you divide your series in a train and a test set, as explained in the link.
Now you should use unit root tests to check if your series are stationary. You've done that using the ADF test, which is very commonly used in these applications, but note that you should specify if you want to run the test with i) no constant and no trend; ii) a constant and no trend; and iii) a constant and a trend. Usually price series have stochastic trends, so a linear trend will not be accurate. In this case you may choose the specification ii. In your code you used the ndiffs
function of the forecast package. I am not sure which of those three alternatives this function implements in order to calculate the number of differences (I couldn't find it in the documentation). To check your result you may want to use the ur.df
function in the "urca" package:
Note that this command will run the ADF test with a constant and the lags selected by the AIC command, with maximum lag of 10. If you have problems interpreting the results just look at this question. If the series are I(1) just use the difference, which will be equal to the continuously compounded returns. If the test indicates that the series are I(2) and you are in doubt about that you can use other tests, e.g. Phillips-Perron test (PP.test
function in R). If all tests confirm that your series are I(2) (remember to use the log of the series before running the tests) then take the second difference, but note that your interpretation of the results will change, since now you are working with the difference of the continuously compounded returns. Prices of assets are usually I(1) since they are close to a random walk, which is a white noise when applying the first difference.
This can be done with commonly used criteria such as Akaike, Schwarz (BIC) and Hannan-Quinn. You've done that with the VARselect
function and that is right, but remember what is the criterion that you used to make your decision. Usually different criteria indicate different orders for the VAR.
If all your series are I(1) or I(2), before running a VAR model you need to make sure there is no cointegration relationships between the series to avoid spurious regressions. You can do that using the Johansenn test or the Engle-Granger (only for bivariate models). In R you can run the Johansen test with the ca.jo
function of the "urca" package. Note that this test also has different specifications. For price series I usually use the following code (where p
is the lag length of item 4, performed with the series in levels):
jo_eigen <- ca.jo(x, type = "eigen", ecdet = "const", K = p)
jo_trace <- ca.jo(x, type = "trace", ecdet = "const", K = p)
If your series are not cointegrated, you can easily estimate the model with the VAR
command, as done in your code. In case the series are cointegrated you need to consider the long run relationship by estimating a Vector Error Correction model with the following code (where k
is the order of cointegration):
vecm <- cajorls(joeigen, r = k)
To test if your model is well specified you can run a test of serial correlation on the residuals. In your code you used a Portmanteau test with the serial.test
function. I've never used this function but I think it is OK. There is also a multivariate version of the Ljung-Box test implemented in the package MTS which you can run with the function mq
.
After you are sure your model is well specified you can use the predict
function as you did in your code. You can even plot impulse response functions to check how the variables respond to a particular shock using the irf
function.
Once you made your predictions you must evaluate them and compare against other models. Some methods to evaluate accuracy of forecasts can be found here, but to do that it is crucial that you divide your series in a training and a test set, as explained in the link.