library(lmtest)
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.3.2
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(car)
## Warning: package 'car' was built under R version 4.3.2
## Loading required package: carData
library(forecast)
library(TTR)
library(Metrics)
## Warning: package 'Metrics' was built under R version 4.3.2
## 
## Attaching package: 'Metrics'
## The following object is masked from 'package:forecast':
## 
##     accuracy
library(tsutils)
## Warning: package 'tsutils' was built under R version 4.3.2
library(urca)
## Warning: package 'urca' was built under R version 4.3.3
library(forecast)
library(vars)
## Warning: package 'vars' was built under R version 4.3.3
## Loading required package: MASS
## Loading required package: strucchange
## Warning: package 'strucchange' was built under R version 4.3.3
## Loading required package: sandwich
#input
library(readxl)
## Warning: package 'readxl' was built under R version 4.3.2
ts_price<-read_excel("~/Kim(1)/Kim NEU/HK6 NEU/Phân tích chuỗi tg và dự báo/group.xlsx")
attach(ts_price)
save(ts_price, file = "group")

ts(ts_price,start=c(1,1),frequency=1)
## Time Series:
## Start = 1 
## End = 498 
## Frequency = 1 
##           BTP      CHP      DRL
##   1 13.006187 18.46135 54.04355
##   2 12.864815 18.46135 54.45927
##   3 12.723444 18.22003 54.45927
##   4 12.723444 18.17981 54.04355
##   5 13.218244 18.22003 54.29298
##   6 13.076873 17.85804 54.29298
##   7 12.511386 17.93848 55.29070
##   8 12.476043 17.89826 55.29070
##   9 12.476043 17.77760 54.87499
##  10 12.970844 17.53627 54.87499
##  11 12.228643 17.61671 54.04355
##  12 12.157957 17.69716 54.04355
##  13 12.157957 17.93848 54.04355
##  14 12.970844 18.01892 54.04355
##  15 12.334672 17.53627 54.04355
##  16 12.652758 17.77760 54.04355
##  17 12.476043 17.69716 54.04355
##  18 12.476043 17.69716 54.12669
##  19 13.041530 17.69716 56.95358
##  20 13.218244 17.69716 54.87499
##  21 13.041530 17.69716 54.45927
##  22 13.041530 17.53627 54.04355
##  23 13.041530 17.97870 54.20983
##  24 13.041530 17.93848 54.20983
##  25 13.006187 17.85804 54.87499
##  26 13.076873 17.85804 53.62783
##  27 13.359616 17.73738 56.53786
##  28 13.430301 18.09936 56.53786
##  29 13.430301 18.09936 56.53786
##  30 13.500987 17.89826 54.04355
##  31 13.430301 17.77760 54.04355
##  32 13.359616 17.81782 54.04355
##  33 13.076873 17.81782 54.87499
##  34 12.723444 17.81782 54.87499
##  35 12.758786 17.81782 54.87499
##  36 12.864815 17.85804 54.29298
##  37 12.935501 17.97870 54.45927
##  38 12.935501 17.81782 54.79184
##  39 12.794129 17.85804 54.70870
##  40 12.935501 17.93848 55.70642
##  41 13.006187 17.77760 55.70642
##  42 12.723444 17.81782 56.53786
##  43 12.652758 17.85804 54.04355
##  44 12.476043 17.85804 57.70188
##  45 12.794129 17.93848 55.70642
##  46 12.476043 17.93848 56.45472
##  47 12.511386 18.05914 56.45472
##  48 12.723444 18.01892 56.37158
##  49 12.511386 18.09936 56.37158
##  50 12.546729 18.09936 56.37158
##  51 12.970844 18.13958 57.36930
##  52 12.794129 18.22003 57.36930
##  53 13.006187 18.22003 57.36930
##  54 12.935501 18.26025 56.53786
##  55 12.794129 18.46135 56.45472
##  56 12.900158 18.30047 56.45472
##  57 12.794129 18.26025 56.37158
##  58 12.794129 18.50157 55.04127
##  59 12.794129 18.86356 55.04127
##  60 13.147558 19.22555 55.70642
##  61 13.041530 19.26577 56.53786
##  62 13.006187 19.18533 56.53786
##  63 13.041530 19.14510 56.53786
##  64 13.006187 19.10488 56.53786
##  65 13.041530 18.90378 55.78957
##  66 12.970844 18.62223 54.04355
##  67 12.970844 18.50157 56.53786
##  68 12.864815 18.90378 54.04355
##  69 13.253587 18.34069 57.28616
##  70 13.359616 18.17981 57.36930
##  71 12.864815 18.30047 57.36930
##  72 12.723444 18.30047 57.36930
##  73 13.076873 18.30047 56.53786
##  74 12.652758 18.17981 55.29070
##  75 12.652758 18.17981 56.53786
##  76 13.041530 18.17981 57.36930
##  77 12.794129 18.58201 57.28616
##  78 13.006187 18.66246 56.53786
##  79 12.652758 19.14510 55.70642
##  80 12.864815 19.10488 58.20074
##  81 13.041530 20.11040 58.17754
##  82 12.370015 20.11040 58.17754
##  83 12.370015 20.51261 58.43534
##  84 12.370015 20.91482 57.40413
##  85 12.087271 20.83438 57.57600
##  86 11.309728 20.32206 54.99797
##  87 11.345070 20.49283 54.99797
##  88 11.945900 20.49283 54.99797
##  89 11.945900 20.83438 57.49006
##  90 11.945900 20.74899 55.85731
##  91 11.804528 20.74899 55.94325
##  92 11.945900 20.49283 55.85731
##  93 11.592471 20.23667 56.71666
##  94 11.875214 20.36475 57.57600
##  95 12.688101 20.40744 57.57600
##  96 12.370015 20.27936 58.43534
##  97 12.299329 20.49283 58.43534
##  98 12.228643 21.51747 57.57600
##  99 12.228643 21.17593 57.57600
## 100 12.228643 21.17593 57.57600
## 101 12.511386 20.40744 57.57600
## 102 12.299329 20.66361 55.25577
## 103 12.652758 21.51747 55.25577
## 104 12.688101 21.60286 55.85731
## 105 12.511386 21.51747 55.85731
## 106 12.652758 20.87707 55.77138
## 107 12.688101 20.74899 55.42764
## 108 12.193300 20.74899 55.85731
## 109 12.582072 20.66361 55.68544
## 110 12.511386 21.26131 55.68544
## 111 12.334672 21.26131 55.85731
## 112 11.945900 21.34670 55.85731
## 113 11.945900 21.09054 55.85731
## 114 11.769185 20.15128 58.34941
## 115 11.804528 20.15128 56.71666
## 116 11.981243 20.49283 56.71666
## 117 11.981243 20.70630 56.71666
## 118 11.839871 20.49283 54.99797
## 119 11.804528 20.66361 51.30279
## 120 11.804528 20.06590 53.27928
## 121 11.910557 20.10859 51.56060
## 122 11.733842 20.10859 51.56060
## 123 11.733842 20.10859 54.48236
## 124 11.733842 20.10859 54.48236
## 125 11.875214 19.59627 54.39643
## 126 11.945900 19.25472 54.39643
## 127 11.981243 18.78510 55.85731
## 128 11.981243 19.38280 55.85731
## 129 11.663157 19.38280 55.85731
## 130 11.663157 19.55358 54.13863
## 131 11.698499 19.72435 54.56830
## 132 11.910557 19.76704 54.56830
## 133 11.981243 19.72435 54.56830
## 134 12.016586 19.89512 57.74787
## 135 11.981243 20.10859 57.74787
## 136 11.981243 20.06590 55.85731
## 137 11.663157 20.06590 57.57600
## 138 11.839871 20.15128 58.34941
## 139 11.839871 20.10859 56.20105
## 140 11.839871 20.23667 58.43534
## 141 11.733842 20.06590 58.43534
## 142 11.733842 20.15128 58.43534
## 143 11.804528 20.15128 55.85731
## 144 11.804528 20.15128 55.85731
## 145 12.016586 20.23667 55.85731
## 146 12.051928 20.32206 55.42764
## 147 11.804528 20.40744 58.26347
## 148 11.981243 20.62091 55.51358
## 149 11.945900 21.34670 55.08390
## 150 12.016586 21.17593 55.08390
## 151 11.945900 21.09054 57.57600
## 152 11.945900 21.26131 57.49006
## 153 11.945900 21.34670 58.00567
## 154 11.945900 21.09054 58.00567
## 155 12.016586 21.09054 57.57600
## 156 12.016586 20.91977 57.57600
## 157 12.016586 20.66361 58.09161
## 158 12.016586 20.91977 60.11295
## 159 12.016586 20.87707 57.30065
## 160 12.794129 20.74899 57.74007
## 161 12.758786 20.62091 57.56430
## 162 12.652758 20.62091 57.74007
## 163 12.405357 20.74899 59.93718
## 164 12.723444 20.66361 60.46448
## 165 12.794129 20.83438 60.64025
## 166 12.794129 20.83438 60.20083
## 167 12.440700 20.74899 59.32199
## 168 12.476043 20.74899 59.76141
## 169 12.511386 21.85902 60.64025
## 170 12.511386 22.58481 60.64025
## 171 12.511386 22.37134 58.17949
## 172 12.440700 22.20057 59.76141
## 173 12.440700 22.20057 63.89198
## 174 12.511386 22.88366 63.89198
## 175 12.617415 22.88366 61.95852
## 176 12.405357 22.88366 62.39794
## 177 12.582072 22.84097 62.39794
## 178 12.582072 22.71289 61.51910
## 179 12.652758 22.54211 61.51910
## 180 12.582072 22.49942 59.84929
## 181 12.582072 22.45673 59.84929
## 182 12.370015 21.68825 59.93718
## 183 12.370015 21.38939 61.07968
## 184 12.370015 21.38939 60.11295
## 185 12.299329 20.83438 61.51910
## 186 12.087271 20.87707 61.51910
## 187 12.087271 21.94441 61.51910
## 188 11.274385 21.47478 60.20083
## 189 12.054619 21.34670 60.20083
## 190 12.483748 21.38939 60.20083
## 191 12.093631 21.38939 60.20083
## 192 12.093631 21.38939 60.20083
## 193 11.937584 21.64555 60.20083
## 194 11.937584 21.43209 60.20083
## 195 11.898572 21.77363 60.72814
## 196 11.820549 21.77363 60.81602
## 197 11.391420 21.56017 60.55237
## 198 11.898572 21.43209 60.55237
## 199 11.898572 21.26131 60.55237
## 200 11.391420 20.74899 59.32199
## 201 11.235373 20.91977 58.88256
## 202 11.040314 21.13323 59.49776
## 203 11.235373 21.30401 59.14622
## 204 11.703514 21.34670 59.14622
## 205 11.157350 21.21862 59.14622
## 206 11.469443 21.68825 58.00372
## 207 11.313396 21.34670 58.88256
## 208 11.625490 21.30401 58.79468
## 209 11.235373 21.13323 58.79468
## 210 11.079326 20.87707 57.82795
## 211 11.664502 20.91977 57.82795
## 212 11.157350 20.79169 55.45507
## 213 11.157350 20.06590 57.91584
## 214 11.079326 20.06590 56.68545
## 215 10.923279 19.98051 58.00372
## 216 10.299092 19.29742 58.00372
## 217 10.689209 18.99856 58.88256
## 218 10.455139 18.78510 58.61891
## 219 11.157350 19.08395 59.58564
## 220 11.196361 19.12664 59.76141
## 221 10.689209 19.12664 59.49776
## 222 10.299092 19.08395 58.70680
## 223  9.674904 19.12664 60.02506
## 224  9.869963 19.46819 59.76141
## 225 10.299092 20.06590 60.64025
## 226 10.377115 19.80974 61.51910
## 227 10.299092 19.80974 61.51910
## 228 10.455139 19.98051 61.95852
## 229 10.377115 19.89512 62.31006
## 230 10.533162 20.23667 61.87064
## 231 10.533162 20.10859 61.95852
## 232 10.455139 20.60343 61.69487
## 233 10.494150 20.33352 61.60698
## 234 10.455139 20.46848 61.60698
## 235 10.260080 20.15358 61.34333
## 236 10.650197 20.33352 61.51910
## 237 10.767232 20.24355 62.34547
## 238 10.494150 20.28853 62.25365
## 239 10.494150 20.24355 61.06000
## 240 10.299092 20.10859 61.06000
## 241 10.299092 20.19856 59.77453
## 242 10.299092 20.10859 60.50908
## 243 10.650197 19.83868 59.68271
## 244 10.533162 20.15358 60.04998
## 245 10.533162 19.88366 59.86635
## 246 10.299092 20.06361 59.86635
## 247 10.767232 19.83868 59.86635
## 248 10.767232 20.15358 60.14180
## 249 10.923279 20.33352 60.04998
## 250 11.157350 20.51346 60.04998
## 251 10.923279 20.28853 59.68271
## 252 11.157350 20.24355 59.86635
## 253 11.157350 20.46848 60.32544
## 254 11.118338 20.51346 58.94815
## 255 11.118338 20.69340 59.22361
## 256 11.118338 20.73839 59.22361
## 257 11.118338 20.78338 59.22361
## 258 11.118338 20.60343 59.49907
## 259 10.923279 20.78338 59.86635
## 260 11.118338 20.87335 59.86635
## 261 11.001303 21.00830 59.49907
## 262 10.845256 21.23323 59.77453
## 263 10.767232 21.23323 61.06000
## 264 10.845256 21.41318 61.06000
## 265 10.923279 21.77306 60.60090
## 266 10.611186 21.81805 63.17185
## 267 10.728221 21.90802 59.86635
## 268 10.728221 21.59312 59.86635
## 269 10.728221 21.81805 60.60090
## 270 10.260080 21.41318 62.89639
## 271 10.728221 21.41318 61.97820
## 272 10.611186 21.41318 61.70274
## 273 10.611186 21.41318 60.69272
## 274 10.299092 21.27822 60.69272
## 275 10.221068 21.59312 60.69272
## 276 10.260080 21.68309 60.69272
## 277 10.533162 21.50315 62.43729
## 278 10.494150 21.50315 62.43729
## 279 10.494150 21.59312 62.43729
## 280 10.455139 21.86303 61.97820
## 281 10.299092 21.81805 61.97820
## 282 10.299092 20.96332 64.45732
## 283 10.143045 21.77306 63.35549
## 284  9.986998 21.72807 62.43729
## 285 10.299092 21.95300 61.97820
## 286 10.104033 21.68309 61.70274
## 287 10.143045 21.72807 61.24364
## 288 10.299092 21.95300 59.86635
## 289 10.026010 21.90802 61.97820
## 290 10.065022 21.90802 59.95817
## 291 10.143045 22.04297 59.95817
## 292 10.143045 22.17793 59.86635
## 293 10.260080 22.22292 59.86635
## 294 10.065022 22.04297 60.60090
## 295 10.143045 22.22292 60.60090
## 296 10.143045 22.31289 61.70274
## 297 10.104033 22.49283 58.85633
## 298 10.143045 22.49283 61.42728
## 299 10.065022 22.49283 61.42728
## 300 10.065022 22.44785 61.42728
## 301 10.143045 22.44785 61.42728
## 302  9.986998 22.40286 61.42728
## 303 10.065022 22.31289 58.94815
## 304 10.065022 22.31289 60.60090
## 305 10.065022 22.22292 60.50908
## 306 10.026010 22.08796 59.68271
## 307 10.065022 22.35787 59.68271
## 308 10.026010 22.22292 60.23362
## 309 10.221068 22.22292 60.32544
## 310 10.221068 21.99799 60.87636
## 311 10.221068 22.13295 59.03997
## 312 10.221068 22.40286 60.60090
## 313 10.299092 22.13295 61.06000
## 314 10.143045 22.26790 60.60090
## 315 10.065022 21.95300 60.14180
## 316 10.143045 22.13295 60.14180
## 317 10.143045 22.49283 60.14180
## 318 10.065022 22.67277 60.14180
## 319  9.986998 22.44785 60.14180
## 320 10.065022 22.44785 59.68271
## 321 10.104033 22.44785 59.68271
## 322 10.026010 22.40286 60.14180
## 323 10.026010 22.49283 59.86635
## 324 10.026010 22.31289 59.22361
## 325  9.986998 22.31289 59.13179
## 326 10.026010 22.31289 59.68271
## 327 10.104033 22.04297 59.68271
## 328 10.143045 21.95300 60.60090
## 329 10.416127 22.13295 60.60090
## 330 10.221068 22.22292 60.60090
## 331 10.221068 21.95300 59.22361
## 332 10.923279 21.95300 59.49907
## 333 10.689209 22.04297 58.76451
## 334 10.767232 22.13295 59.49907
## 335 10.923279 22.04297 59.49907
## 336 11.235373 22.04297 60.41726
## 337 11.235373 22.13295 60.04998
## 338 11.196361 21.90802 58.85633
## 339 11.079326 21.77306 60.14180
## 340 11.196361 21.81805 60.14180
## 341 11.586478 22.31289 59.29474
## 342 11.781537 22.22292 59.38886
## 343 11.625490 22.13295 60.23592
## 344 11.703514 22.26790 61.17711
## 345 11.937584 22.31289 60.23592
## 346 11.976595 22.67277 60.89475
## 347 11.859560 22.67277 60.98887
## 348 12.171654 22.67277 60.98887
## 349 12.093631 22.67277 60.23592
## 350 12.327701 22.67277 60.23592
## 351 12.366713 22.76275 60.23592
## 352 12.756830 22.76275 60.23592
## 353 12.483748 22.81118 60.14180
## 354 12.756830 22.66588 60.23592
## 355 12.873865 22.76275 57.41236
## 356 12.834853 22.66588 58.82414
## 357 12.834853 22.52059 59.29474
## 358 12.639795 22.47216 59.29474
## 359 12.639795 22.27843 59.29474
## 360 12.405724 22.23000 60.23592
## 361 12.210666 22.18157 60.23592
## 362 12.639795 22.08471 60.23592
## 363 12.639795 22.23000 60.70652
## 364 12.327701 22.27843 58.35355
## 365 12.093631 22.56902 60.23592
## 366 12.327701 22.76275 60.23592
## 367 12.327701 22.66588 60.23592
## 368 12.249677 22.81118 60.23592
## 369 12.249677 22.66588 61.17711
## 370 12.210666 22.56902 61.17711
## 371 12.327701 22.56902 61.64770
## 372 12.327701 22.47216 61.64770
## 373 12.327701 22.47216 61.55358
## 374 12.327701 22.37529 59.76533
## 375 12.327701 22.47216 60.33004
## 376 12.327701 22.37529 61.27123
## 377 12.093631 22.37529 61.36535
## 378 12.093631 22.27843 62.02418
## 379 12.483748 22.27843 62.21241
## 380 12.483748 22.66588 62.87124
## 381 12.483748 22.56902 62.87124
## 382 12.444736 22.56902 61.17711
## 383 12.327701 22.37529 61.27123
## 384 12.483748 22.47216 62.77713
## 385 12.483748 22.37529 61.93006
## 386 12.600783 22.32686 61.93006
## 387 12.405724 22.32686 62.11830
## 388 12.444736 22.42373 62.58889
## 389 12.093631 22.47216 62.58889
## 390 12.366713 22.52059 62.58889
## 391 12.366713 22.42373 62.02418
## 392 12.171654 22.42373 62.58889
## 393 12.366713 22.37529 62.58889
## 394 12.093631 22.27843 63.53008
## 395 12.249677 22.27843 63.05948
## 396 12.249677 22.27843 63.71831
## 397 12.210666 22.27843 63.05948
## 398 12.132642 22.23000 63.05948
## 399 12.093631 22.37529 63.05948
## 400 12.249677 22.37529 61.17711
## 401 12.171654 22.42373 62.11830
## 402 12.171654 22.76275 62.49477
## 403 12.327701 22.81118 62.40065
## 404 12.093631 22.81118 62.49477
## 405 11.898572 22.47216 62.58889
## 406 11.781537 22.71431 62.58889
## 407 11.703514 22.47216 63.07407
## 408 11.625490 22.61745 62.97704
## 409 12.093631 22.56902 62.39481
## 410 12.171654 22.37529 62.20074
## 411 12.171654 22.71431 63.07407
## 412 12.327701 22.42373 63.07407
## 413 12.639795 22.56902 63.07407
## 414 12.639795 22.56902 61.32741
## 415 13.029912 22.85961 62.29778
## 416 13.029912 22.85961 61.23037
## 417 12.873865 22.85961 63.07407
## 418 13.068923 22.76275 62.88000
## 419 13.029912 22.76275 62.29778
## 420 12.990900 22.66588 62.29778
## 421 12.639795 22.47216 62.10370
## 422 12.386999 22.47216 62.00667
## 423 12.429131 22.47216 61.90963
## 424 12.344866 22.56902 62.10370
## 425 12.176335 22.47216 62.10370
## 426 12.429131 22.71431 62.10370
## 427 12.639795 22.47216 62.00667
## 428 12.049938 22.47216 62.00667
## 429 12.007805 22.66588 62.58889
## 430 12.007805 22.47216 62.58889
## 431 11.797142 22.47216 62.00667
## 432 11.670744 22.56902 63.26815
## 433 11.670744 22.56902 63.07407
## 434 11.670744 22.61745 63.07407
## 435 11.375815 22.56902 62.58889
## 436 11.249417 22.56902 62.58889
## 437 11.544346 22.61745 63.07407
## 438 11.965672 22.71431 63.07407
## 439 11.965672 22.81118 62.58889
## 440 11.965672 22.81118 62.58889
## 441 11.965672 22.95647 62.58889
## 442 11.923540 22.95647 62.39481
## 443 11.881407 22.95647 63.07407
## 444 11.965672 23.00490 64.52963
## 445 11.965672 23.10176 63.07407
## 446 11.628611 23.19863 63.07407
## 447 11.628611 22.85961 63.85037
## 448 11.628611 22.85961 64.82074
## 449 11.417948 22.76275 63.94741
## 450 11.670744 23.24706 63.94741
## 451 11.375815 23.24706 63.94741
## 452 11.375815 23.15020 63.94741
## 453 11.375815 23.15020 63.17111
## 454 11.291550 23.24706 63.07407
## 455 11.291550 23.15020 63.07407
## 456 11.291550 22.85961 63.07407
## 457 11.291550 23.24706 63.07407
## 458 11.123019 22.85961 62.49185
## 459 11.123019 23.39235 63.07407
## 460 11.123019 23.05333 63.07407
## 461 11.123019 23.24706 62.88000
## 462 11.123019 23.24706 62.88000
## 463 11.038754 23.24706 63.26815
## 464 11.038754 23.24706 63.55926
## 465 10.996621 23.44078 66.37333
## 466 11.123019 23.44078 63.07407
## 467 11.123019 23.53765 64.04444
## 468 11.249417 23.44078 64.52963
## 469 11.038754 23.44078 63.07407
## 470 11.038754 23.44078 63.55926
## 471 10.954489 23.53765 63.85037
## 472 11.123019 23.53765 64.52963
## 473 11.123019 23.44078 64.52963
## 474 11.291550 23.34392 64.04444
## 475 11.291550 23.24706 64.04444
## 476 11.291550 23.39235 64.04444
## 477 12.049938 23.44078 64.14148
## 478 12.892590 23.73137 64.33556
## 479 13.777376 23.87667 64.33556
## 480 14.704294 23.97353 64.33556
## 481 15.083488 23.92510 64.33556
## 482 14.030172 23.87667 65.01481
## 483 13.061121 23.73137 65.01481
## 484 13.650978 23.82824 67.63481
## 485 13.356050 23.77980 64.52963
## 486 13.356050 23.77980 64.52963
## 487 13.356050 24.21569 64.82074
## 488 13.440315 24.40941 64.82074
## 489 13.861641 24.50627 65.50000
## 490 14.104676 24.70000 65.70000
## 491 14.017878 24.36098 66.00000
## 492 13.887681 24.79686 66.00000
## 493 13.714085 24.99059 65.70000
## 494 13.714085 24.70000 65.70000
## 495 13.627287 24.90000 65.40000
## 496 13.627287 24.85000 65.00000
## 497 13.800883 25.00000 65.00000
## 498 13.800883 25.30000 65.80000
CHP<-ts(CHP,start=c(1,1),frequency=1)
BTP<-ts(BTP,start=c(1,1),frequency=1)
DRL<-ts(DRL,start=c(1,1),frequency=1)
###DONG TICH HOP###
#Kiem dinh so moi quan he Voi tieu chi "trace"
summary(ca.jo(data.frame(CHP,BTP,DRL),type="trace")) # có 1 mqh đồng tích hợp
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 0.063346614 0.011882433 0.001043128
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 2 |  0.52  6.50  8.18 11.65
## r <= 1 |  6.45 15.66 17.95 23.52
## r = 0  | 38.91 28.71 31.52 37.22
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##            CHP.l2      BTP.l2     DRL.l2
## CHP.l2  1.0000000   1.0000000 1.00000000
## BTP.l2 -0.1810824 -10.7448583 0.85235183
## DRL.l2 -0.6566706   0.5192956 0.08164016
## 
## Weights W:
## (This is the loading matrix)
## 
##             CHP.l2        BTP.l2       DRL.l2
## CHP.d -0.038833987 -9.681981e-05 -0.002688246
## BTP.d  0.005985269  2.098272e-03 -0.001487528
## DRL.d  0.153768121 -2.525485e-03 -0.010250825
#Kiem dinh so moi quan he Voi tieu chi "eigen"
summary(ca.jo(data.frame(CHP,BTP,DRL),type="eigen")) # có 1
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: maximal eigenvalue statistic (lambda max) , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 0.063346614 0.011882433 0.001043128
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 2 |  0.52  6.50  8.18 11.65
## r <= 1 |  5.93 12.91 14.90 19.19
## r = 0  | 32.46 18.90 21.07 25.75
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##            CHP.l2      BTP.l2     DRL.l2
## CHP.l2  1.0000000   1.0000000 1.00000000
## BTP.l2 -0.1810824 -10.7448583 0.85235183
## DRL.l2 -0.6566706   0.5192956 0.08164016
## 
## Weights W:
## (This is the loading matrix)
## 
##             CHP.l2        BTP.l2       DRL.l2
## CHP.d -0.038833987 -9.681981e-05 -0.002688246
## BTP.d  0.005985269  2.098272e-03 -0.001487528
## DRL.d  0.153768121 -2.525485e-03 -0.010250825
#Kiem dinh tinh dung voi 3 chuoi sai phan
summary(ur.df(diff(CHP), type = "none")) # Bác bỏ H0: dừng
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression none 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.95781 -0.09333  0.00000  0.11010  1.10945 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## z.lag.1    -1.081531   0.066119 -16.357   <2e-16 ***
## z.diff.lag  0.006814   0.045085   0.151     0.88    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2405 on 493 degrees of freedom
## Multiple R-squared:  0.5368, Adjusted R-squared:  0.535 
## F-statistic: 285.7 on 2 and 493 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -16.3573 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
summary(ur.df(diff(BTP), type = "none")) # dừng
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression none 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.02740 -0.10489 -0.00324  0.08405  1.09084 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## z.lag.1    -1.18998    0.06591 -18.053   <2e-16 ***
## z.diff.lag  0.09896    0.04481   2.209   0.0277 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.245 on 493 degrees of freedom
## Multiple R-squared:  0.5461, Adjusted R-squared:  0.5443 
## F-statistic: 296.6 on 2 and 493 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -18.0533 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
summary(ur.df(diff(DRL), type = "none")) # dừng
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression none 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.3539 -0.3622  0.0019  0.4364  4.3855 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## z.lag.1    -1.52601    0.07289 -20.936  < 2e-16 ***
## z.diff.lag  0.14276    0.04460   3.201  0.00146 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9609 on 493 degrees of freedom
## Multiple R-squared:  0.6742, Adjusted R-squared:  0.6728 
## F-statistic:   510 on 2 and 493 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -20.9356 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
#Uoc luong phuong trinh va kiem dinh phan du
summary(lm(CHP~BTP+DRL))
## 
## Call:
## lm(formula = CHP ~ BTP + DRL)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.5250 -0.6096  0.1152  0.6619  3.3183 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -6.446857   1.117502  -5.769 1.41e-08 ***
## BTP          0.007549   0.045668   0.165    0.869    
## DRL          0.462023   0.014812  31.193  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.012 on 495 degrees of freedom
## Multiple R-squared:  0.6699, Adjusted R-squared:  0.6686 
## F-statistic: 502.3 on 2 and 495 DF,  p-value: < 2.2e-16
resid.CHP<- resid(lm(CHP~BTP+DRL))
summary(ur.df(resid.CHP, type="none")) # |-4.6304|>|Tqs|->phần dư dừng-> đồng tích hợp
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression none 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.05953 -0.21952  0.01328  0.24129  2.17728 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## z.lag.1    -0.10853    0.02363  -4.593 5.55e-06 ***
## z.diff.lag -0.24532    0.04369  -5.615 3.28e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5109 on 494 degrees of freedom
## Multiple R-squared:  0.1274, Adjusted R-squared:  0.1239 
## F-statistic: 36.07 on 2 and 494 DF,  p-value: 2.4e-15
## 
## 
## Value of test-statistic is: -4.5931 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
summary(lm(BTP~CHP+DRL))
## 
## Call:
## lm(formula = BTP ~ CHP + DRL)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.1239 -0.7013  0.1165  0.6951  3.5194 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 15.415339   0.900477  17.119   <2e-16 ***
## CHP          0.007312   0.044234   0.165   0.8688    
## DRL         -0.062581   0.024946  -2.509   0.0124 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9959 on 495 degrees of freedom
## Multiple R-squared:  0.03338,    Adjusted R-squared:  0.02947 
## F-statistic: 8.546 on 2 and 495 DF,  p-value: 0.0002245
resid.BTP<- resid(lm(BTP~CHP+DRL))
summary(ur.df(resid.BTP, type="none")) # đồng tích hợp tại alpha= 0.05
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression none 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.98800 -0.12852 -0.00487  0.11160  1.05681 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)  
## z.lag.1    -0.02566    0.01173  -2.188   0.0291 *
## z.diff.lag -0.08351    0.04505  -1.854   0.0644 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2554 on 494 degrees of freedom
## Multiple R-squared:  0.01913,    Adjusted R-squared:  0.01516 
## F-statistic: 4.816 on 2 and 494 DF,  p-value: 0.008479
## 
## 
## Value of test-statistic is: -2.1879 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
summary(lm(DRL~CHP+BTP))
## 
## Call:
## lm(formula = DRL ~ CHP + BTP)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -7.5751 -1.0553  0.1944  1.2592  4.8475 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 31.60253    1.45624  21.701   <2e-16 ***
## CHP          1.43457    0.04599  31.193   <2e-16 ***
## BTP         -0.20061    0.07997  -2.509   0.0124 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.783 on 495 degrees of freedom
## Multiple R-squared:  0.674,  Adjusted R-squared:  0.6727 
## F-statistic: 511.8 on 2 and 495 DF,  p-value: < 2.2e-16
resid.DRL<- resid(lm(DRL~CHP+BTP))
summary(ur.df(resid.DRL, type="none")) # dừng-> đồng tích hợp
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression none 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.8330 -0.4333  0.0250  0.4458  4.4081 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## z.lag.1    -0.14534    0.02706  -5.371 1.21e-07 ***
## z.diff.lag -0.24878    0.04356  -5.712 1.93e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.02 on 494 degrees of freedom
## Multiple R-squared:  0.1527, Adjusted R-squared:  0.1492 
## F-statistic:  44.5 on 2 and 494 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -5.3709 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
#Mo hinh hieu chinh sai so ECM
length(CHP)
## [1] 498
summary(lm(diff(CHP)~ diff(BTP)+ diff(DRL)+ resid.CHP[1:497])) 
## 
## Call:
## lm(formula = diff(CHP) ~ diff(BTP) + diff(DRL) + resid.CHP[1:497])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.86778 -0.10776 -0.00784  0.11702  1.07639 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       0.013612   0.010501   1.296 0.195494    
## diff(BTP)         0.143611   0.042686   3.364 0.000827 ***
## diff(DRL)        -0.008036   0.010482  -0.767 0.443673    
## resid.CHP[1:497] -0.043210   0.010656  -4.055 5.83e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.234 on 493 degrees of freedom
## Multiple R-squared:  0.05734,    Adjusted R-squared:  0.0516 
## F-statistic: 9.996 on 3 and 493 DF,  p-value: 2.093e-06
# hệ số gama= -0.043321, có ý nghĩa thống kê ở mức 1% -> nếu có mẫu cân bằng ở kỳ trước tăng 1 đơn vị-> kỳ sau cần giảm 0.043321 đơn vị để về cân bằng. 
# xem lại youtube

summary(lm(diff(BTP)~ diff(CHP)+ diff(DRL)+ resid.BTP[1:497]))
## 
## Call:
## lm(formula = diff(BTP) ~ diff(CHP) + diff(DRL) + resid.BTP[1:497])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.95581 -0.12105 -0.00936  0.08585  0.97456 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      -0.0009487  0.0109080  -0.087 0.930726    
## diff(CHP)         0.1535389  0.0454546   3.378 0.000788 ***
## diff(DRL)         0.0129063  0.0106351   1.214 0.225498    
## resid.BTP[1:497] -0.0278132  0.0110198  -2.524 0.011918 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2427 on 493 degrees of freedom
## Multiple R-squared:  0.03622,    Adjusted R-squared:  0.03035 
## F-statistic: 6.175 on 3 and 493 DF,  p-value: 0.0003991
summary(lm(diff(DRL)~ diff(CHP)+ diff(BTP)+ resid.DRL[1:497]))
## 
## Call:
## lm(formula = diff(DRL) ~ diff(CHP) + diff(BTP) + resid.DRL[1:497])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.2500 -0.3564  0.0088  0.4224  3.9243 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       0.02436    0.04453   0.547    0.585    
## diff(CHP)        -0.08940    0.19098  -0.468    0.640    
## diff(BTP)         0.20047    0.18258   1.098    0.273    
## resid.DRL[1:497] -0.15237    0.02550  -5.975 4.42e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9911 on 493 degrees of freedom
## Multiple R-squared:  0.07461,    Adjusted R-squared:  0.06898 
## F-statistic: 13.25 on 3 and 493 DF,  p-value: 2.481e-08

#————————————————————————

###VAR###
CHP.ln <- log(CHP[2:length(CHP)] / CHP[1:(length(CHP)-1)])*100
BTP.ln <- log(BTP[2:length(BTP)] / BTP[1:(length(BTP)-1)])*100
DRL.ln <- log(DRL[2:length(DRL)] / DRL[1:(length(DRL)-1)])*100
data1<-data.frame(CHP.ln,BTP.ln,DRL.ln)
View(data1)

#Xac dinh bac tre
VARselect(data1)
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      1      1      1      1 
## 
## $criteria
##                1         2         3         4         5         6         7
## AIC(n)  2.704264  2.704795  2.705903  2.724025  2.720101  2.747527  2.767799
## HQ(n)   2.744806  2.775743  2.807257  2.855785  2.882267  2.940099  2.990777
## SC(n)   2.807466  2.885398  2.963907  3.059430  3.132907  3.237734  3.335408
## FPE(n) 14.943335 14.951347 14.968087 15.242131 15.182935 15.605843 15.926487
##                8         9        10
## AIC(n)  2.760445  2.761248  2.763096
## HQ(n)   3.013829  3.045039  3.077293
## SC(n)   3.405455  3.483659  3.562909
## FPE(n) 15.811154 15.825602 15.857038
#MO HINH VAR(1)
var1<- VAR(data1, p=1,type="const")
summary(var1)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: CHP.ln, BTP.ln, DRL.ln 
## Deterministic variables: const 
## Sample size: 496 
## Log Likelihood: -2772.39 
## Roots of the characteristic polynomial:
## 0.3278 0.101 0.07722
## Call:
## VAR(y = data1, p = 1, type = "const")
## 
## 
## Estimation results for equation CHP.ln: 
## ======================================= 
## CHP.ln = CHP.ln.l1 + BTP.ln.l1 + DRL.ln.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)  
## CHP.ln.l1 -0.065543   0.045465  -1.442   0.1500  
## BTP.ln.l1  0.005912   0.025465   0.232   0.8165  
## DRL.ln.l1  0.060047   0.029509   2.035   0.0424 *
## const      0.065234   0.051629   1.264   0.2070  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 1.148 on 492 degrees of freedom
## Multiple R-Squared: 0.01357, Adjusted R-squared: 0.007551 
## F-statistic: 2.255 on 3 and 492 DF,  p-value: 0.08113 
## 
## 
## Estimation results for equation BTP.ln: 
## ======================================= 
## BTP.ln = CHP.ln.l1 + BTP.ln.l1 + DRL.ln.l1 + const 
## 
##           Estimate Std. Error t value Pr(>|t|)  
## CHP.ln.l1 -0.03059    0.08094  -0.378    0.706  
## BTP.ln.l1 -0.10266    0.04534  -2.264    0.024 *
## DRL.ln.l1  0.04765    0.05254   0.907    0.365  
## const      0.01548    0.09192   0.168    0.866  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 2.044 on 492 degrees of freedom
## Multiple R-Squared: 0.01277, Adjusted R-squared: 0.006748 
## F-statistic: 2.121 on 3 and 492 DF,  p-value: 0.09668 
## 
## 
## Estimation results for equation DRL.ln: 
## ======================================= 
## DRL.ln = CHP.ln.l1 + BTP.ln.l1 + DRL.ln.l1 + const 
## 
##           Estimate Std. Error t value Pr(>|t|)    
## CHP.ln.l1 -0.03229    0.06568  -0.492    0.623    
## BTP.ln.l1 -0.01174    0.03679  -0.319    0.750    
## DRL.ln.l1 -0.33788    0.04263  -7.926 1.53e-14 ***
## const      0.05283    0.07459   0.708    0.479    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 1.658 on 492 degrees of freedom
## Multiple R-Squared: 0.1141,  Adjusted R-squared: 0.1087 
## F-statistic: 21.13 on 3 and 492 DF,  p-value: 6.868e-13 
## 
## 
## 
## Covariance matrix of residuals:
##         CHP.ln BTP.ln  DRL.ln
## CHP.ln  1.3176 0.3361 -0.0880
## BTP.ln  0.3361 4.1762  0.1956
## DRL.ln -0.0880 0.1956  2.7500
## 
## Correlation matrix of residuals:
##          CHP.ln  BTP.ln   DRL.ln
## CHP.ln  1.00000 0.14326 -0.04623
## BTP.ln  0.14326 1.00000  0.05771
## DRL.ln -0.04623 0.05771  1.00000
#KD TTQ
serial.test(var1)
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object var1
## Chi-squared = 173.03, df = 135, p-value = 0.01512
#Du bao 10 phien
forecast1<- predict(var1)
forecast1
## $CHP.ln
##             fcst     lower    upper       CI
##  [1,] 0.06050383 -2.189234 2.310242 2.249738
##  [2,] 0.03753013 -2.226075 2.301136 2.263606
##  [3,] 0.07384394 -2.191134 2.338821 2.264978
##  [4,] 0.05988421 -2.205250 2.325018 2.265134
##  [5,] 0.06460234 -2.200549 2.329753 2.265151
##  [6,] 0.06304638 -2.202106 2.328199 2.265153
##  [7,] 0.06355700 -2.201596 2.328710 2.265153
##  [8,] 0.06338958 -2.201763 2.328543 2.265153
##  [9,] 0.06344447 -2.201709 2.328597 2.265153
## [10,] 0.06342647 -2.201727 2.328579 2.265153
## 
## $BTP.ln
##               fcst     lower    upper       CI
##  [1,]  0.037286196 -3.968037 4.042609 4.005323
##  [2,] -0.009206332 -4.039361 4.020949 4.030155
##  [3,]  0.024108833 -4.006905 4.055122 4.031014
##  [4,]  0.010232849 -4.020873 4.041339 4.031106
##  [5,]  0.015167383 -4.015949 4.046284 4.031116
##  [6,]  0.013504027 -4.017614 4.044622 4.031118
##  [7,]  0.014054453 -4.017063 4.045172 4.031118
##  [8,]  0.013873450 -4.017244 4.044991 4.031118
##  [9,]  0.013932847 -4.017185 4.045051 4.031118
## [10,]  0.013913369 -4.017204 4.045031 4.031118
## 
## $DRL.ln
##              fcst     lower    upper       CI
##  [1,] -0.39900189 -3.649238 2.851235 3.250236
##  [2,]  0.18525188 -3.246530 3.617034 3.431782
##  [3,] -0.01086941 -3.461979 3.440240 3.451110
##  [4,]  0.05383283 -3.399359 3.507025 3.453192
##  [5,]  0.03258475 -3.420832 3.486001 3.453416
##  [6,]  0.03955382 -3.413887 3.492994 3.453440
##  [7,]  0.03726887 -3.416174 3.490712 3.453443
##  [8,]  0.03801796 -3.415425 3.491461 3.453443
##  [9,]  0.03777239 -3.415671 3.491216 3.453443
## [10,]  0.03785289 -3.415591 3.491296 3.453443
plot(forecast1)

#Ham phan ung
irf1<-irf(var1)
plot(irf1)

#Phan ra phuong sai
fevd(var1)
## $CHP.ln
##          CHP.ln       BTP.ln      DRL.ln
##  [1,] 1.0000000 0.0000000000 0.000000000
##  [2,] 0.9923587 0.0002546537 0.007386601
##  [3,] 0.9911679 0.0002814673 0.008550620
##  [4,] 0.9910311 0.0002839220 0.008684982
##  [5,] 0.9910162 0.0002841627 0.008699621
##  [6,] 0.9910146 0.0002841876 0.008701198
##  [7,] 0.9910144 0.0002841902 0.008701368
##  [8,] 0.9910144 0.0002841905 0.008701386
##  [9,] 0.9910144 0.0002841906 0.008701388
## [10,] 0.9910144 0.0002841906 0.008701388
## 
## $BTP.ln
##           CHP.ln    BTP.ln      DRL.ln
##  [1,] 0.02052460 0.9794754 0.000000000
##  [2,] 0.02139256 0.9771401 0.001467361
##  [3,] 0.02140158 0.9767950 0.001803387
##  [4,] 0.02140069 0.9767505 0.001848849
##  [5,] 0.02140058 0.9767453 0.001854120
##  [6,] 0.02140057 0.9767447 0.001854701
##  [7,] 0.02140057 0.9767447 0.001854764
##  [8,] 0.02140057 0.9767447 0.001854771
##  [9,] 0.02140057 0.9767447 0.001854771
## [10,] 0.02140057 0.9767447 0.001854771
## 
## $DRL.ln
##            CHP.ln      BTP.ln    DRL.ln
##  [1,] 0.002137385 0.004224907 0.9936377
##  [2,] 0.001986689 0.004970713 0.9930426
##  [3,] 0.001986509 0.005072924 0.9929406
##  [4,] 0.001987047 0.005084838 0.9929281
##  [5,] 0.001987123 0.005086152 0.9929267
##  [6,] 0.001987132 0.005086294 0.9929266
##  [7,] 0.001987132 0.005086309 0.9929266
##  [8,] 0.001987133 0.005086311 0.9929266
##  [9,] 0.001987133 0.005086311 0.9929266
## [10,] 0.001987133 0.005086311 0.9929266
plot(fevd(var1))