I want to restrict my beta, How can I do that? Load necessary packages library(urca)…
- User
I want to restrict my beta, How can I do that?
Load necessary packages library(urca) library(vars) library(tseries) library(MASS) library(tidyverse)
Assuming log_data is already loaded in the environment Correct the order of variables Y <- log_data[, c("log_Spot", "log_Fut", "log_USO", "log_USL", "log_OIL")]
Step 1: Unit root tests (code remains the same) Step 2: Determine the optimal lag length using VARselect VARselect_result <- VARselect(Y, lag.max=15, type="const") print("Optimal lag length selection:") [1] "Optimal lag length selection:" print(VARselect_result$selection) AIC(n) HQ(n) SC(n) FPE(n) 15 9 5 15
Choose the number of lags based on SC p <- VARselect_result$selection["HQ(n)"]
K <- p - 1 # Lagged differences in Johansen test
Step 3: Johansen cointegration test with corrected settings johansen_test <- ca.jo(Y, type="trace", ecdet="const", K=K, spec="longrun") summary(johansen_test)
######################
Johansen-Procedure ######################
Test type: trace statistic , without linear trend and constant in cointegration
Eigenvalues (lambda): [1] 9.194013e-02 6.137328e-02 1.082481e-02 5.234867e-03 7.584923e-04 [6] 9.339895e-17
Values of teststatistic and critical values of test:
test 10pct 5pct 1pctr <= 4 | 2.29 7.52 9.24 12.97 r <= 3 | 18.16 17.85 19.96 24.60 r <= 2 | 51.06 32.00 34.91 41.07 r <= 1 | 242.53 49.65 53.12 60.16 r = 0 | 534.08 71.86 76.07 84.45
Eigenvectors, normalised to first column: (These are the cointegration relations)
log_Spot.l8 log_Fut.l8 log_USO.l8 log_USL.l8 log_OIL.l8log_Spot.l8 1.000000000 1.0000000 1.000000 1.0000000 1.000000 log_Fut.l8 -1.003644123 -1.5256307 -3.331999 1.4487665 -5.903652 log_USO.l8 -0.006998315 -0.9992708 8.252360 13.6547508 8.825436 log_USL.l8 -0.002521254 0.7607663 4.716197 -8.9283064 -1.004589 log_OIL.l8 0.008398995 0.6448770 -8.722794 -8.0800039 -5.309850 constant 0.008065544 0.7922468 5.954291 0.1266867 10.436638 constant log_Spot.l8 1.000000 log_Fut.l8 -1.197880 log_USO.l8 -2.604882 log_USL.l8 1.305870 log_OIL.l8 1.247534 constant 2.071152
Weights W: (This is the loading matrix)
log_Spot.l8 log_Fut.l8 log_USO.l8 log_USL.l8 log_OIL.l8log_Spot.d -0.061910397 0.004041937 -0.003984373 -0.0027565091 0.0003042509 log_Fut.d 0.338164478 0.016601908 -0.003969795 -0.0024759995 0.0002939173 log_USO.d -0.022184653 0.037273171 -0.004320462 -0.0016669625 0.0002652621 log_USL.d 0.001740984 0.018450168 -0.005337932 -0.0004077368 0.0002501097 log_OIL.d -0.060171749 0.039992249 -0.002479446 -0.0012813480 0.0003394962 constant log_Spot.d 6.558352e-15 log_Fut.d 2.942492e-14 log_USO.d 1.311205e-14 log_USL.d 1.067847e-14 log_OIL.d 8.429320e-15
Step 4: Estimate VECM and transform to VAR representation vecm_var <- vec2var(johansen_test, r=4) r = 4
- Assistant