# Dynamic Model Averaging in Economics and Finance with fDMA: A Package for R
## 9 An Example: Oil Market
In particular,  
* trends$stock_markets represents Google Trends for \"stock markets\",
* trends$interest_rate represents Google Trends for \"interest rate\",
* trends$economic_activity represents Google Trends for \"economic activity\",
* trends$exchange_rate represents Google Trends for \"exchange rate\",
* trends$oil_production represents Google Trends for \"oil production\",
* trends$oil_consumption represents Google Trends for \"oil consumption\",
* trends$market_stress represents Google Trends for \"market stress\".  
These data are also in a monthly frequency. They cover the period between January 2004 and December 2016, because Google Trends does not cover the earlier period.  
From the economic point of view it is reasonable to consider logarithmic differences of these time-series.  
R> wti <- crudeoil[-1, 1] R> drivers <- (lag(crudeoil[, -1], k = 1))[-1, ] R> ld.wti <- (diff(log(wti)))[-1, ] R> ld.drivers <- (diff(log(drivers)))[-1, ] R> stest(ld.wti) ADF stat. ADF p-val. PP stat. PP p-val. KPSS stat. KPSS p-val. WTI -7.7723 0.01 -210.7704 0.01 0.0643 0.1 R> R> R> R> stest(ld.drivers) ADF stat. ADF p-val. PP stat. PP p-val. KPSS stat. KPSS p-val. MSCI -6.5991 0.01 -300.5006 0.01 0.0546 0.1000 TB3 MS -6.7647 0.01 -245.1034 0.01 0.0822 0.1000 CSP -6.4724 0.01 -458.5101 0.01 0.0792 0.1000 TWEMM -7.6516 0.01 -200.0467 0.01 0.1304 0.1000 PROD -7.6770 0.01 -452.8701 0.01 0.5389 0.0329 CONS -9.3762 0.01 -467.6868 0.01 0.0389 0.1000 VX0 -9.2563 0.01 -325.9003 0.01 0.0282 0.1000 R> R> archtest(ld.wti)  
[PERSON]'s LM ARCH\"Test  
data: ld.wti statistic = 38.584, lag = 1, p-value = 5.246e-10 alternative hypothesis: ARCH effects of order 1 are present R> R> descstat(cbind(ld.wti,ld.drivers)) mean sd variance median min max WTI 0.00265415 0.08648 0.007480 0.0114849 -0.33198 0.3922 MSCI 0.00358386 0.04368 0.001908 0.0092134 -0.21128 0.1035 TB3 MS -0.00879474 0.28379 0.080537 0.000000 -1.84583 1.7918 CSP 0.00228619 0.04407 0.001942 -0.0052036 -0.13723 0.1346 TWEXM 0.00004198 0.01673 0.000280 0.0008499 -0.04784 0.0647 PROD 0.00039764 0.05570 0.003102 0.0010922 -0.26236 0.2075 CONS 0.00035543 0.05425 0.002943 0.0063261 -0.13512 0.1319 VX0 -0.00207592 0.19108 0.036511 -0.0113524 -0.47960 0.7587 skew kurtosis coeff. of variation WTI -0.29526 2.0239 0.030689 MSCI -0.82550 1.9446 0.082055 TB3 MS 0.30278 15.4820 -0.030990 CSP 0.70715 0.8223 0.051873 TWEXM 0.05247 0.4998 0.002509 PROD -0.33301 2.1423 0.007139 CONS -0.04308 -0.4467 0.006552 VX0 0.44346 1.0880 -0.010864  
Except some problem with PROD, all time-series can be assumed stationary at 5% significance level. For WTI differences also ARCH effects are present. Therefore, it seems reasonable to consider exponentially weighted moving average (EWMA) estimation of variances in DMA. Also, a few forgetting factors can be tested. As suggested by Riskmetrics for the monthly time-series \(\kappa=0.97\) is taken. All variances are less than 1. Therefore, no rescaling of the time-series seems necessary. It seems also enough to take initvar = 1 in the estimations of DMA.  
R> gra <- c(1, 0.99, 0.98, 0.97, 0.96, 0.95) R> grl <- c(1, 0.99, 0.98, 0.97, 0.96, 0.95) R> g <- grid.DMA(y = ld.wti, x = ld.drivers, + grid.alpha = gra, grid.lambda = grl, + initvar = 1, V.meth = \"ewma\", kappa = 0.97)  
R> summary(g) RMSE:
1 0.99 0.98 0.97 0.96 0.95
1 0.0872 0.0868 0.0867 0.0866 0.0866 0.0866
0.99 0.0872 0.0867 0.0866 0.0866 0.0866 0.0865
0.98 0.0869 0.0866 0.0866 0.0866  
* alphas by columns, lambdas by rows According to minimising RMSE the best DMA model is the one with \(\alpha=0.99\) and \(\lambda=0.97\). Therefore, this model is examined a little.  
R> dma.model <- g$models[[2]][[4]] R> plot(dma.model)  
Make a plot selection (or 0 to exit):  
1: actual and predicted
2: residuals
3: exp. var
4: posterior inclusion probabilities - one plot
5: posterior inclusion probabilities - separate plots (files in working directory)
6: expected coefficients - one plot
7: expected coefficients - separate plots (files in working directory)
8: exp.