# Wczytanie danych
# Indeksy_M <- read_excel("C:/Users/Mateusz/Desktop/Semestr III/Ekonometria Finansowa/Projekt/Dane_indeksy.xlsx", sheet = "monthly")
Indeksy_D <- read_excel("C:/Users/Mateusz/Desktop/Semestr III/Ekonometria Finansowa/Projekt/Dane_indeksy.xlsx", sheet = "daily")

# Finalnie pracujemy na zlogarytmowanych danych dziennych

dax=Indeksy_D$LN_DAX
wig=Indeksy_D$LN_WIG
bux=Indeksy_D$LN_BUX
px=Indeksy_D$LN_PX

Punkt 1 - wizualizacja

t=1:3242

par(mfrow = c(2,2))
plot.ts(dax,type="l", col="red", main="LN DAX ")
abline(lm(dax~t))
plot.ts(wig, type="l", col="blue", main="LN WIG")
abline(lm(wig~t))
plot.ts(bux, type="l", col="purple", main="LN BUX")
abline(lm(bux~t))
plot.ts(px, type="l", col="green", main="LN PX")
abline(lm(px~t))

Punkt 2 - testowanie stacjonarności

summary(lm(dax~t)) # trend istotny
## 
## Call:
## lm(formula = dax ~ t)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.43916 -0.05841  0.00153  0.07440  0.26558 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 8.931e+00  3.575e-03  2497.9   <2e-16 ***
## t           2.600e-04  1.910e-06   136.1   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1018 on 3240 degrees of freedom
## Multiple R-squared:  0.8512, Adjusted R-squared:  0.8512 
## F-statistic: 1.854e+04 on 1 and 3240 DF,  p-value: < 2.2e-16
summary(lm(wig~t)) # trend istotny
## 
## Call:
## lm(formula = wig ~ t)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.48345 -0.06941  0.03154  0.08508  0.25620 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  7.750e+00  4.377e-03 1770.51   <2e-16 ***
## t           -4.729e-05  2.338e-06  -20.23   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1246 on 3240 degrees of freedom
## Multiple R-squared:  0.1121, Adjusted R-squared:  0.1118 
## F-statistic: 409.1 on 1 and 3240 DF,  p-value: < 2.2e-16
summary(lm(bux~t)) # trend istotny
## 
## Call:
## lm(formula = bux ~ t)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.35853 -0.10588  0.02086  0.10916  0.27775 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 9.687e+00  4.802e-03  2017.2   <2e-16 ***
## t           4.403e-04  2.565e-06   171.6   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1367 on 3240 degrees of freedom
## Multiple R-squared:  0.9009, Adjusted R-squared:  0.9009 
## F-statistic: 2.946e+04 on 1 and 3240 DF,  p-value: < 2.2e-16
summary(lm(px~t)) # trend istotny
## 
## Call:
## lm(formula = px ~ t)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.50408 -0.05735  0.00913  0.06933  0.23464 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 6.762e+00  3.779e-03 1789.44   <2e-16 ***
## t           1.371e-04  2.018e-06   67.95   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1076 on 3240 degrees of freedom
## Multiple R-squared:  0.5876, Adjusted R-squared:  0.5875 
## F-statistic:  4617 on 1 and 3240 DF,  p-value: < 2.2e-16
# ponieważ trendy są istotne, uwzględniamy je w teście
# sprawdzane jest 12 lagów, ale finalnie przyjęte jest mniej

adf_dax = ur.df(dax, type = c("trend"), lags = 12, selectlags ="BIC" )
adf_wig= ur.df(wig, type = c("trend"), lags = 12, selectlags ="BIC" )
adf_bux = ur.df(bux, type = c("trend"), lags = 12, selectlags ="BIC" )
adf_px = ur.df(px, type = c("trend"), lags = 12, selectlags ="BIC" )

summary(adf_dax)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression trend 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.132890 -0.009003  0.000142  0.009041  0.095004 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  7.442e-02  1.987e-02   3.746 0.000183 ***
## z.lag.1     -8.269e-03  2.223e-03  -3.720 0.000203 ***
## tt           2.029e-06  6.215e-07   3.265 0.001107 ** 
## z.diff.lag  -6.845e-02  1.755e-02  -3.899 9.85e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01267 on 3225 degrees of freedom
## Multiple R-squared:  0.009514,   Adjusted R-squared:  0.008592 
## F-statistic: 10.33 on 3 and 3225 DF,  p-value: 9.218e-07
## 
## 
## Value of test-statistic is: -3.7198 5.6036 7.0148 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau3 -3.96 -3.41 -3.12
## phi2  6.09  4.68  4.03
## phi3  8.27  6.25  5.34
summary(adf_wig)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression trend 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.154185 -0.009466  0.000279  0.009701  0.075061 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  4.321e-02  1.487e-02   2.906  0.00369 **
## z.lag.1     -5.585e-03  1.917e-03  -2.913  0.00361 **
## tt          -2.177e-07  2.721e-07  -0.800  0.42371   
## z.diff.lag  -3.843e-02  1.760e-02  -2.184  0.02906 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01357 on 3225 degrees of freedom
## Multiple R-squared:  0.004333,   Adjusted R-squared:  0.003406 
## F-statistic: 4.678 on 3 and 3225 DF,  p-value: 0.002898
## 
## 
## Value of test-statistic is: -2.9127 2.8403 4.2604 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau3 -3.96 -3.41 -3.12
## phi2  6.09  4.68  4.03
## phi3  8.27  6.25  5.34
summary(adf_bux)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression trend 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.132330 -0.009860 -0.000257  0.009277  0.055891 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  3.744e-02  1.571e-02   2.382   0.0173 *
## z.lag.1     -3.835e-03  1.621e-03  -2.365   0.0181 *
## tt           1.822e-06  7.527e-07   2.420   0.0156 *
## z.diff.lag  -2.992e-02  1.760e-02  -1.700   0.0892 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01259 on 3225 degrees of freedom
## Multiple R-squared:  0.002841,   Adjusted R-squared:  0.001914 
## F-statistic: 3.063 on 3 and 3225 DF,  p-value: 0.02702
## 
## 
## Value of test-statistic is: -2.3652 3.6727 2.9524 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau3 -3.96 -3.41 -3.12
## phi2  6.09  4.68  4.03
## phi3  8.27  6.25  5.34
summary(adf_px)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression trend 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.092978 -0.001876 -0.000142  0.008795  0.074929 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.569e-02  1.141e-02   2.251 0.024441 *  
## z.lag.1     -3.807e-03  1.687e-03  -2.256 0.024125 *  
## tt           6.745e-07  3.021e-07   2.232 0.025652 *  
## z.diff.lag1 -5.821e-02  1.761e-02  -3.307 0.000954 ***
## z.diff.lag2  5.057e-02  1.760e-02   2.873 0.004089 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01029 on 3224 degrees of freedom
## Multiple R-squared:  0.008142,   Adjusted R-squared:  0.006911 
## F-statistic: 6.616 on 4 and 3224 DF,  p-value: 2.67e-05
## 
## 
## Value of test-statistic is: -2.2562 2.3233 2.853 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau3 -3.96 -3.41 -3.12
## phi2  6.09  4.68  4.03
## phi3  8.27  6.25  5.34
# w każdym przypadku występuje niestacjonarność dla 1pct i 5pct

Punkt 3 - rożnicowanie WIG w celu weliminowania niestacjonarności

t=1:3241
#rożnice
d_wig = diff(wig)
d_dax = diff(dax)
d_bux = diff(bux)
d_px = diff(px)

summary(lm(d_wig~t)) # trend nieistotny
## 
## Call:
## lm(formula = d_wig ~ t)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.150019 -0.009989 -0.000001  0.009978  0.079966 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4.305e-05  4.775e-04  -0.090    0.928
## t            3.037e-08  2.551e-07   0.119    0.905
## 
## Residual standard error: 0.01359 on 3239 degrees of freedom
## Multiple R-squared:  4.375e-06,  Adjusted R-squared:  -0.0003044 
## F-statistic: 0.01417 on 1 and 3239 DF,  p-value: 0.9053
summary(lm(d_dax~t)) # trend nieistotny
## 
## Call:
## lm(formula = d_dax ~ t)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.130301 -0.010228 -0.000333  0.009573  0.099700 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept)  5.353e-04  4.490e-04   1.192    0.233
## t           -1.113e-07  2.399e-07  -0.464    0.643
## 
## Residual standard error: 0.01278 on 3239 degrees of freedom
## Multiple R-squared:  6.647e-05,  Adjusted R-squared:  -0.0002423 
## F-statistic: 0.2153 on 1 and 3239 DF,  p-value: 0.6427
summary(lm(d_bux~t)) # trend nieistotny
## 
## Call:
## lm(formula = d_bux ~ t)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.130535 -0.010307 -0.000440  0.009446  0.059465 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.245e-04  4.441e-04   0.506    0.613
## t           1.527e-07  2.373e-07   0.644    0.520
## 
## Residual standard error: 0.01264 on 3239 degrees of freedom
## Multiple R-squared:  0.0001279,  Adjusted R-squared:  -0.0001808 
## F-statistic: 0.4144 on 1 and 3239 DF,  p-value: 0.5198
summary(lm(d_px~t)) # trend nieistotny
## 
## Call:
## lm(formula = d_px ~ t)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.090264 -0.000447 -0.000184  0.009614  0.079735 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -6.665e-05  3.631e-04  -0.184    0.854
## t            1.610e-07  1.940e-07   0.830    0.407
## 
## Residual standard error: 0.01033 on 3239 degrees of freedom
## Multiple R-squared:  0.0002126,  Adjusted R-squared:  -9.603e-05 
## F-statistic: 0.6889 on 1 and 3239 DF,  p-value: 0.4066
# tym razem bez trendu
summary(ur.df(d_wig, type = c("none"), lags = 12, selectlags ="BIC" ))
## 
## ############################################### 
## # 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.152668 -0.009690  0.000000  0.009702  0.074927 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## z.lag.1    -1.05737    0.02541 -41.614   <2e-16 ***
## z.diff.lag  0.01548    0.01762   0.879     0.38    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01358 on 3226 degrees of freedom
## Multiple R-squared:  0.5207, Adjusted R-squared:  0.5204 
## F-statistic:  1752 on 2 and 3226 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -41.6144 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
summary(ur.df(d_dax, type = c("none"), lags = 12, selectlags ="BIC" ))
## 
## ############################################### 
## # 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.130531 -0.009113  0.000000  0.009469  0.097918 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## z.lag.1    -1.05314    0.02577 -40.874   <2e-16 ***
## z.diff.lag -0.01699    0.01760  -0.965    0.334    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01269 on 3226 degrees of freedom
## Multiple R-squared:  0.5359, Adjusted R-squared:  0.5356 
## F-statistic:  1862 on 2 and 3226 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -40.8736 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
summary(ur.df(d_bux, type = c("none"), lags = 12, selectlags ="BIC" ))
## 
## ############################################### 
## # 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.131231 -0.009669  0.000061  0.009761  0.056728 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## z.lag.1    -1.05700    0.02524 -41.880   <2e-16 ***
## z.diff.lag  0.02698    0.01758   1.535    0.125    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0126 on 3226 degrees of freedom
## Multiple R-squared:  0.5154, Adjusted R-squared:  0.5151 
## F-statistic:  1715 on 2 and 3226 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -41.8799 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
summary(ur.df(d_px, type = c("none"), lags = 12, selectlags ="BIC" ))
## 
## ############################################### 
## # 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.091791 -0.001533  0.000000  0.008915  0.076961 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## z.lag.1    -1.01086    0.02564 -39.428  < 2e-16 ***
## z.diff.lag -0.04884    0.01758  -2.777  0.00551 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01029 on 3226 degrees of freedom
## Multiple R-squared:  0.5326, Adjusted R-squared:  0.5323 
## F-statistic:  1838 on 2 and 3226 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -39.4277 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
# ZMIENNA UZNAna ZA STACJONARNÄ„!

# Subset zmiennych do modelu
dane <- data.frame(d_dax,d_wig,d_bux,d_px)
# Potwierdzenie testem ACF

par(mfrow = c(2,2))
acf(d_wig)
acf(d_dax)
acf(d_bux)
acf(d_px)

Punkt 4 - sprawdzenie odpowiedniej lizcby opóźniej w modelu VAR

#testowanie długości opóźnień w modelu VAR
subset_for_VAR = ts(dane) # ts - oznaczenie jako szereg czasowy
VARselect(subset_for_VAR, lag.max = 12, type = "const")
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##     12      1      1     12 
## 
## $criteria
##                    1             2             3             4             5
## AIC(n) -3.522701e+01 -3.522920e+01 -3.523069e+01 -3.522586e+01 -3.522641e+01
## HQ(n)  -3.521352e+01 -3.520491e+01 -3.519560e+01 -3.517998e+01 -3.516973e+01
## SC(n)  -3.518936e+01 -3.516141e+01 -3.513278e+01 -3.509782e+01 -3.506825e+01
## FPE(n)  5.024605e-16  5.013655e-16  5.006187e-16  5.030403e-16  5.027628e-16
##                    6             7             8             9            10
## AIC(n) -3.523366e+01 -3.523924e+01 -3.524077e+01 -3.528430e+01 -3.528797e+01
## HQ(n)  -3.516618e+01 -3.516097e+01 -3.515170e+01 -3.518444e+01 -3.517732e+01
## SC(n)  -3.504536e+01 -3.502083e+01 -3.499223e+01 -3.500563e+01 -3.497918e+01
## FPE(n)  4.991351e-16  4.963539e-16  4.955977e-16  4.744879e-16  4.727480e-16
##                   11            12
## AIC(n) -3.530591e+01 -3.530853e+01
## HQ(n)  -3.518446e+01 -3.517628e+01
## SC(n)  -3.496699e+01 -3.493948e+01
## FPE(n)  4.643433e-16  4.631330e-16
# kryteria AIC i FPE dają wartości skrajne, natomiast są mało odporne
# dobrym kryterium jest HQ i SC, dlatego przyjmujemy w tym wypadku 1 opóźnienie zgodnie z kryteriami HQ i SC

Punkt 5 - szacujemy model VAR dla p=1

var <- VAR(subset_for_VAR, p = 1, type = "const")
summary(var)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: d_dax, d_wig, d_bux, d_px 
## Deterministic variables: const 
## Sample size: 3240 
## Log Likelihood: 38672.299 
## Roots of the characteristic polynomial:
## 0.07002 0.05951 0.05951 0.01943
## Call:
## VAR(y = subset_for_VAR, p = 1, type = "const")
## 
## 
## Estimation results for equation d_dax: 
## ====================================== 
## d_dax = d_dax.l1 + d_wig.l1 + d_bux.l1 + d_px.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## d_dax.l1 -0.0676290  0.0175324  -3.857 0.000117 ***
## d_wig.l1 -0.0041183  0.0164835  -0.250 0.802726    
## d_bux.l1 -0.0474981  0.0177141  -2.681 0.007369 ** 
## d_px.l1  -0.0269856  0.0216713  -1.245 0.213139    
## const     0.0004097  0.0002241   1.828 0.067575 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.01274 on 3235 degrees of freedom
## Multiple R-Squared: 0.007241,    Adjusted R-squared: 0.006013 
## F-statistic: 5.899 on 4 and 3235 DF,  p-value: 9.981e-05 
## 
## 
## Estimation results for equation d_wig: 
## ====================================== 
## d_wig = d_dax.l1 + d_wig.l1 + d_bux.l1 + d_px.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)  
## d_dax.l1 -5.288e-03  1.869e-02  -0.283   0.7773  
## d_wig.l1 -4.081e-02  1.757e-02  -2.323   0.0203 *
## d_bux.l1 -5.393e-03  1.888e-02  -0.286   0.7752  
## d_px.l1   2.791e-02  2.310e-02   1.208   0.2271  
## const     2.209e-06  2.389e-04   0.009   0.9926  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.01358 on 3235 degrees of freedom
## Multiple R-Squared: 0.002202,    Adjusted R-squared: 0.0009684 
## F-statistic: 1.785 on 4 and 3235 DF,  p-value: 0.129 
## 
## 
## Estimation results for equation d_bux: 
## ====================================== 
## d_bux = d_dax.l1 + d_wig.l1 + d_bux.l1 + d_px.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)  
## d_dax.l1  0.0050171  0.0173874   0.289   0.7729  
## d_wig.l1  0.0272471  0.0163472   1.667   0.0957 .
## d_bux.l1 -0.0299107  0.0175676  -1.703   0.0887 .
## d_px.l1   0.0082757  0.0214920   0.385   0.7002  
## const     0.0004860  0.0002222   2.187   0.0288 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.01263 on 3235 degrees of freedom
## Multiple R-Squared: 0.001853,    Adjusted R-squared: 0.0006193 
## F-statistic: 1.502 on 4 and 3235 DF,  p-value: 0.1989 
## 
## 
## Estimation results for equation d_px: 
## ===================================== 
## d_px = d_dax.l1 + d_wig.l1 + d_bux.l1 + d_px.l1 + const 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## d_dax.l1 -0.0004156  0.0142028  -0.029  0.97666    
## d_wig.l1  0.0015805  0.0133532   0.118  0.90579    
## d_bux.l1  0.0138319  0.0143500   0.964  0.33517    
## d_px.l1  -0.0629598  0.0175557  -3.586  0.00034 ***
## const     0.0002003  0.0001815   1.103  0.26993    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.01032 on 3235 degrees of freedom
## Multiple R-Squared: 0.004268,    Adjusted R-squared: 0.003036 
## F-statistic: 3.466 on 4 and 3235 DF,  p-value: 0.007824 
## 
## 
## 
## Covariance matrix of residuals:
##            d_dax      d_wig      d_bux       d_px
## d_dax  1.623e-04  4.355e-06  1.585e-06 -4.454e-06
## d_wig  4.355e-06  1.844e-04 -2.743e-06 -1.700e-06
## d_bux  1.585e-06 -2.743e-06  1.596e-04 -6.915e-07
## d_px  -4.454e-06 -1.700e-06 -6.915e-07  1.065e-04
## 
## Correlation matrix of residuals:
##           d_dax    d_wig     d_bux      d_px
## d_dax  1.000000  0.02518  0.009852 -0.033885
## d_wig  0.025175  1.00000 -0.015988 -0.012133
## d_bux  0.009852 -0.01599  1.000000 -0.005304
## d_px  -0.033885 -0.01213 -0.005304  1.000000

Punkt 6 - wizualizacja efektów estymacji

windows(width=12, height=8) # dla systemu Windows
plot(var)

Punkt 7 - badanie stabilności modelu VAR

par(mar = c(2.5, 2.5, 1.2, 1.2), cex = 0.6)
var_stab = stability(var, type = "OLS-CUSUM")
plot(var_stab)

# badanie normalności rozkładu reszt

var_norm = normality.test(var, multivariate.only = TRUE)
var_norm
## $JB
## 
##  JB-Test (multivariate)
## 
## data:  Residuals of VAR object var
## Chi-squared = 34149, df = 8, p-value < 2.2e-16
## 
## 
## $Skewness
## 
##  Skewness only (multivariate)
## 
## data:  Residuals of VAR object var
## Chi-squared = 1067.3, df = 4, p-value < 2.2e-16
## 
## 
## $Kurtosis
## 
##  Kurtosis only (multivariate)
## 
## data:  Residuals of VAR object var
## Chi-squared = 33082, df = 4, p-value < 2.2e-16
# Reszty nie mają rozkładu normalnego (p-value <0)

badanie autokorelacji składnika losowego

var_BG <- serial.test(var, lags.pt = 4, type = "BG")
var_BG
## 
##  Breusch-Godfrey LM test
## 
## data:  Residuals of VAR object var
## Chi-squared = 154.15, df = 80, p-value = 1.266e-06
# Reszty wykazujÄ… na brak autokorelacji
# Koło jednostkowe
roots(var)
## [1] 0.07001534 0.05951115 0.05951115 0.01943226
par(mfrow = c(1, 1))
root.comp = Im(roots(var, modulus=FALSE ))
root.real = Re(roots(var, modulus=FALSE ))
x = seq(-1, 1, length=1000)
y1 = sqrt(1-x^2)
y2 = -sqrt(1-x^2)
plot(c(x, x), c(y1, y2), xlab='Real part', ylab='Imaginary part', type='l', main='Unit Circle', ylim=c(-1, 1), xlim=c (-1, 1))
abline(h=0)
abline(v=0)
points(root.comp, root.real, pch=19)
legend(-1, -1, legend= "Eigenvalues", pch=19)

# testy Grangera dla wszystkich 4 zmiennych - w dwie strony

causality(var, cause = c("d_wig"))
## $Granger
## 
##  Granger causality H0: d_wig do not Granger-cause d_dax d_bux d_px
## 
## data:  VAR object var
## F-Test = 0.95434, df1 = 3, df2 = 12940, p-value = 0.4133
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_wig and d_dax d_bux d_px
## 
## data:  VAR object var
## Chi-squared = 3.3229, df = 3, p-value = 0.3445
causality(var, cause = c("d_px"))
## $Granger
## 
##  Granger causality H0: d_px do not Granger-cause d_dax d_wig d_bux
## 
## data:  VAR object var
## F-Test = 1.0873, df1 = 3, df2 = 12940, p-value = 0.353
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_px and d_dax d_wig d_bux
## 
## data:  VAR object var
## Chi-squared = 4.2133, df = 3, p-value = 0.2393
causality(var, cause = c("d_dax"))
## $Granger
## 
##  Granger causality H0: d_dax do not Granger-cause d_wig d_bux d_px
## 
## data:  VAR object var
## F-Test = 0.0539, df1 = 3, df2 = 12940, p-value = 0.9835
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_dax and d_wig d_bux d_px
## 
## data:  VAR object var
## Chi-squared = 6.0249, df = 3, p-value = 0.1104
causality(var, cause = c("d_bux"))
## $Granger
## 
##  Granger causality H0: d_bux do not Granger-cause d_dax d_wig d_px
## 
## data:  VAR object var
## F-Test = 2.6654, df1 = 3, df2 = 12940, p-value = 0.04613
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_bux and d_dax d_wig d_px
## 
## data:  VAR object var
## Chi-squared = 1.2547, df = 3, p-value = 0.7399
causality(var, cause = c("d_bux","d_dax","d_px"))
## $Granger
## 
##  Granger causality H0: d_dax d_bux d_px do not Granger-cause d_wig
## 
## data:  VAR object var
## F-Test = 0.55048, df1 = 3, df2 = 12940, p-value = 0.6478
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_dax d_bux d_px and d_wig
## 
## data:  VAR object var
## Chi-squared = 3.3229, df = 3, p-value = 0.3445
causality(var, cause = c("d_wig","d_dax","d_px"))
## $Granger
## 
##  Granger causality H0: d_dax d_wig d_px do not Granger-cause d_bux
## 
## data:  VAR object var
## F-Test = 1.0039, df1 = 3, df2 = 12940, p-value = 0.3899
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_dax d_wig d_px and d_bux
## 
## data:  VAR object var
## Chi-squared = 1.2547, df = 3, p-value = 0.7399
causality(var, cause = c("d_bux","d_wig","d_px"))
## $Granger
## 
##  Granger causality H0: d_wig d_bux d_px do not Granger-cause d_dax
## 
## data:  VAR object var
## F-Test = 2.9119, df1 = 3, df2 = 12940, p-value = 0.03306
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_wig d_bux d_px and d_dax
## 
## data:  VAR object var
## Chi-squared = 6.0249, df = 3, p-value = 0.1104
causality(var, cause = c("d_bux","d_dax","d_wig"))
## $Granger
## 
##  Granger causality H0: d_dax d_wig d_bux do not Granger-cause d_px
## 
## data:  VAR object var
## F-Test = 0.31322, df1 = 3, df2 = 12940, p-value = 0.8158
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_dax d_wig d_bux and d_px
## 
## data:  VAR object var
## Chi-squared = 4.2133, df = 3, p-value = 0.2393
# testy Grangera dla pary wig i dax
subset_for_VAR2<-data.frame(d_wig,d_dax)
VARselect(subset_for_VAR2, lag.max = 12, type = "const")
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      1      1      1      1 
## 
## $criteria
##                    1             2             3             4             5
## AIC(n) -1.733003e+01 -1.732898e+01 -1.732745e+01 -1.732591e+01 -1.732477e+01
## HQ(n)  -1.732598e+01 -1.732223e+01 -1.731800e+01 -1.731377e+01 -1.730993e+01
## SC(n)  -1.731873e+01 -1.731015e+01 -1.730109e+01 -1.729202e+01 -1.728335e+01
## FPE(n)  2.976215e-08  2.979341e-08  2.983904e-08  2.988487e-08  2.991901e-08
##                    6             7             8             9            10
## AIC(n) -1.732376e+01 -1.732401e+01 -1.732360e+01 -1.732306e+01 -1.732146e+01
## HQ(n)  -1.730622e+01 -1.730376e+01 -1.730066e+01 -1.729742e+01 -1.729312e+01
## SC(n)  -1.727481e+01 -1.726752e+01 -1.725958e+01 -1.725151e+01 -1.724238e+01
## FPE(n)  2.994918e-08  2.994192e-08  2.995418e-08  2.997017e-08  3.001830e-08
##                   11            12
## AIC(n) -1.731957e+01 -1.731935e+01
## HQ(n)  -1.728853e+01 -1.728561e+01
## SC(n)  -1.723296e+01 -1.722520e+01
## FPE(n)  3.007507e-08  3.008182e-08
var2 <- VAR(subset_for_VAR2, p = 1, type = "const")
causality(var2, cause = c("d_wig"))
## $Granger
## 
##  Granger causality H0: d_wig do not Granger-cause d_dax
## 
## data:  VAR object var2
## F-Test = 0.035035, df1 = 1, df2 = 6474, p-value = 0.8515
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_wig and d_dax
## 
## data:  VAR object var2
## Chi-squared = 2.0097, df = 1, p-value = 0.1563
causality(var2, cause = c("d_dax"))
## $Granger
## 
##  Granger causality H0: d_dax do not Granger-cause d_wig
## 
## data:  VAR object var2
## F-Test = 0.10635, df1 = 1, df2 = 6474, p-value = 0.7443
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_dax and d_wig
## 
## data:  VAR object var2
## Chi-squared = 2.0097, df = 1, p-value = 0.1563
# testy Grangera dla pary bux i dax
subset_for_VAR3<-data.frame(d_bux,d_dax)
VARselect(subset_for_VAR3, lag.max = 12, type = "const")
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      1      1      1      1 
## 
## $criteria
##                    1             2             3             4             5
## AIC(n) -1.748151e+01 -1.748129e+01 -1.748127e+01 -1.747989e+01 -1.747922e+01
## HQ(n)  -1.747746e+01 -1.747454e+01 -1.747182e+01 -1.746774e+01 -1.746438e+01
## SC(n)  -1.747021e+01 -1.746246e+01 -1.745491e+01 -1.744599e+01 -1.743780e+01
## FPE(n)  2.557871e-08  2.558418e-08  2.558479e-08  2.562016e-08  2.563722e-08
##                    6             7             8             9            10
## AIC(n) -1.747993e+01 -1.747944e+01 -1.747825e+01 -1.747590e+01 -1.747453e+01
## HQ(n)  -1.746239e+01 -1.745920e+01 -1.745531e+01 -1.745026e+01 -1.744619e+01
## SC(n)  -1.743098e+01 -1.742295e+01 -1.741424e+01 -1.740435e+01 -1.739544e+01
## FPE(n)  2.561893e-08  2.563160e-08  2.566199e-08  2.572251e-08  2.575788e-08
##                   11            12
## AIC(n) -1.747383e+01 -1.747555e+01
## HQ(n)  -1.744279e+01 -1.744181e+01
## SC(n)  -1.738722e+01 -1.738141e+01
## FPE(n)  2.577582e-08  2.573145e-08
var3 <- VAR(subset_for_VAR3, p = 1, type = "const")
causality(var3, cause = c("d_bux"))
## $Granger
## 
##  Granger causality H0: d_bux do not Granger-cause d_dax
## 
## data:  VAR object var3
## F-Test = 7.1313, df1 = 1, df2 = 6474, p-value = 0.007594
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_bux and d_dax
## 
## data:  VAR object var3
## Chi-squared = 0.29714, df = 1, p-value = 0.5857
causality(var3, cause = c("d_dax"))
## $Granger
## 
##  Granger causality H0: d_dax do not Granger-cause d_bux
## 
## data:  VAR object var3
## F-Test = 0.10136, df1 = 1, df2 = 6474, p-value = 0.7502
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_dax and d_bux
## 
## data:  VAR object var3
## Chi-squared = 0.29714, df = 1, p-value = 0.5857
# testy Grangera dla pary dax i px
subset_for_VAR4<-data.frame(d_dax,d_px)
VARselect(subset_for_VAR4, lag.max = 12, type = "const")
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      3      1      1      3 
## 
## $criteria
##                    1             2             3             4             5
## AIC(n) -1.788332e+01 -1.788411e+01 -1.788474e+01 -1.788299e+01 -1.788172e+01
## HQ(n)  -1.787927e+01 -1.787736e+01 -1.787529e+01 -1.787084e+01 -1.786687e+01
## SC(n)  -1.787202e+01 -1.786528e+01 -1.785837e+01 -1.784910e+01 -1.784029e+01
## FPE(n)  1.711480e-08  1.710131e-08  1.709064e-08  1.712051e-08  1.714226e-08
##                    6             7             8             9            10
## AIC(n) -1.787955e+01 -1.788138e+01 -1.788206e+01 -1.788234e+01 -1.788032e+01
## HQ(n)  -1.786201e+01 -1.786114e+01 -1.785912e+01 -1.785670e+01 -1.785198e+01
## SC(n)  -1.783060e+01 -1.782489e+01 -1.781804e+01 -1.781079e+01 -1.780123e+01
## FPE(n)  1.717946e-08  1.714808e-08  1.713641e-08  1.713163e-08  1.716632e-08
##                   11            12
## AIC(n) -1.788086e+01 -1.787994e+01
## HQ(n)  -1.784982e+01 -1.784620e+01
## SC(n)  -1.779425e+01 -1.778579e+01
## FPE(n)  1.715696e-08  1.717283e-08
var4 <- VAR(subset_for_VAR4, p = 1, type = "const")
causality(var4, cause = c("d_px"))
## $Granger
## 
##  Granger causality H0: d_px do not Granger-cause d_dax
## 
## data:  VAR object var4
## F-Test = 1.5022, df1 = 1, df2 = 6474, p-value = 0.2204
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_px and d_dax
## 
## data:  VAR object var4
## Chi-squared = 3.8847, df = 1, p-value = 0.04873
causality(var4, cause = c("d_dax"))
## $Granger
## 
##  Granger causality H0: d_dax do not Granger-cause d_px
## 
## data:  VAR object var4
## F-Test = 0.00025931, df1 = 1, df2 = 6474, p-value = 0.9872
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: d_dax and d_px
## 
## data:  VAR object var4
## Chi-squared = 3.8847, df = 1, p-value = 0.04873
# funkcja odpowiedzi na impuls pochodzący od przyrostów inflacji
irf=irf(var)
plot(irf)