# Dynamic Model Averaging in Economics and Finance with fDMA: A Package for R
## 3 Theoretical Framework
### Dynamic Model Averaging (DMA)  
DMA was introduced in great details in the original paper by [1]. However, below a short exposition is presented, necessary to understand what each function in fDMA does. Suppose that \(y_{t}\) is the forecast time-series (dependent variable), and let \(x_{t}^{(k)}\) be the column vector of independent variables in \(k\)-th regression model. For instance, 10 potential oil price drivers are listed in Table 1. If each of them would be represented by a suitable time-series, then \(2^{10}\) possible linear \begin{table}
\begin{tabular}{p{142.3 pt} p{142.3 pt}} \hline \hline Stock markets & Empirically it was found that oil price and stock indices are usually following similar time paths. Also, that predictive accuracy of oil price forecasts increase when data from stock markets is used. Oil price can affect interest rates, production, GDP, which further affects the expected free cash flow. This further affects stock prices. Moreover, there is a rising financialization of oil market, i.e., since 2000s increasing links between oil and stocks markets [103; 104; 105; 106; 107; 108; 109; 110; 111; 112]. \\ \hline Speculative forces & Links between spot and futures markets. Above mentioned financialization. Trading on OTC electronic exchanges [113; 114; 115; 116; 117; 118]. \\ \hline Inventories & They can be released to cover supply shortages, as so called buffer inventory. Also, they can be stored to be sold at higher prices in the future. This is called speculative inventory [119; 120; 121; 122]. \\ \hline Oil price volatility & It has a direct effect on the energy sector. Higher volatility might put pressure on consumers to switch to alternative energy sources, and therefore, demand decrease [123; 124]. \\ \hline Other commodities & Empirically, correlations between oil price and prices of other commodities, for example gold, are found. Gold price usually increase during market downturns [125; 126; 127; 128; 129; 130; 131; 96; 132]. \\ \hline Economic activity & Economic growth stimulates oil demand [133; 134; 135; 136; 137; 138; 139; 140]. \\ \hline Policy uncertainty & Empirically, economic policy uncertainty increases predictive accuracy of oil price forecasts. Usually, positive uncertainty shocks affect commodity prices returns negatively [141; 142; 143]. \\ \hline \hline \end{tabular}
\end{table} 
Table 1: _Cont._regression models can be constructed. Indeed, each variable can be included or not included in a model. So, 2 choices are possible for each variable, constituting \(2^{10}\) possibilities. This includes a model with constant only. So, in general having potentially useful \(m\) independent variables, up to \(K=2^{m}\) models can be constructed. In other words the state space model is given by  
\[y_{t}=(x_{t}^{(k)})^{\top}\theta_{t}^{(k)}+\epsilon_{t}^{(k)}\quad, \tag{1}\]  
\[\theta_{t}^{(k)}=\theta_{t-1}^{(k)}+\delta_{t}^{(k)}\quad,\]  
where \(k=1,\ldots,K\) and \(\theta_{t}\) is the column vector of regression coefficients. It is assumed that errors follow the normal distribution, i.e., \(\epsilon_{t}^{(k)}\sim\mathcal{N}(0,V_{t}^{(k)})\) and \(\delta_{t}^{(k)}\sim\mathcal{N}(0,W_{t}^{(k)})\). Please notice herein that having \(m\) potential explanatory variables \(2^{m}\) is the upper limit of constructed models. However, all methodology described in this paper (if not stated otherwise) is applicable for any subset of these \(2^{m}\) models, i.e., \(K\leq 2^{m}\). Let \(L_{t}=k\) if the process is governed by \(k\)-th model in time \(t\). The evolution can be determined by \(K\times K\) transition matrix \((p_{k,l})\) with \(p_{k,l}=p[L_{t}=l|L_{t-1}=k]\). For large \(K\) computations are impossible, therefore an approximation is necessary. In particular, let \(\theta_{t}=(\theta_{t}^{(1)},\ldots,\theta_{t}^{(K)})^{\top}\), then the underlying state consists of the pair \((\theta_{t},L_{t})\). Its probability distribution is \(p(\theta_{t},L_{t})=\sum_{k=1}^{K}[p(\theta_{t}^{(k)}|L_{t}=k)p(L_{t}=k)]\).