# Denton proportional procedure

Denton procedure will interpolate high frequency data into low frecuency. Let be $I$ a vector indicator with high frecuency data from t=1 to T. Lets assume that $A_n$ is a vector of low frecuency data where $A_n$ represent the n period and is length N. So the objetive is interpolate the vector $I$ into $A$. Lets assume that the length of I divide by A is equal to q (if q=4 => that is annual data with quarterly data). Lets assume that q=4.

Original source: https://www.imf.org/external/pubs/ft/qna/pdf/2017/chapter6.pdf

The minimization problem is define as:

$$
\min_{X_t} \sum_{t=2}^T (\frac{X_t}{I_t} - \frac{X_{t-1}}{I_{t-1}})^2
$$
Subject to:
$$
\sum_{t=4n-3}^{4n} X_t = A_n \text{    for n = 1,...,N}
$$

So we want the vector $X_t$ such that aggregate the same value  in annual data but minimize the variation growth of the quarterly data.

It is better to express this problem as a quadratic matricial minimization problem. Lets define:


\begin{equation}
D = 
\begin{pmatrix}
-1 & 1 & 0 &\cdots & 0\\
0 & -1 & 1 & \cdots & 0\\
\vdots & \vdots & \vdots & \ddots & \vdots\\
0 & 0 & 0 & \cdots & 0
\end{pmatrix}
\end{equation}

D is square matrix (TxT) with -1 in the diagonal and 1 in the subsecuent element of the diagonal and the last rows has 0 in all of his elements. 



\begin{equation}
J = 
\begin{pmatrix}
1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 &\cdots & 0\\
0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 &\cdots & 0\\
\vdots & \vdots & \vdots  & \vdots & \vdots & \vdots & \vdots  & \vdots & \ddots & \vdots\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \cdots & 1
\end{pmatrix}
\end{equation}

J is matrix (N x T) with 1s in rows and 0 that it is use to aggregate the data of X (in the representation above it is assume to be year data with quarterly data).

Let $\tilde{I}$ be the diagonal inverse matrix of $I$. It is a square matrix of $TxT$ and $\tilde{X}= \tilde{I}X$. Therefore the problem can be represented as:

$$
\min_{X} (D\tilde{X})^T D\tilde{X}
$$
Subject to:
$$JX = A \text{ and } \tilde{X}= \tilde{I}X$$


Let assume that $M=\tilde{I^T} D^TD\tilde{I}$

Rewrite the problem as:

$$
\min_{X} X^T M X
$$
Subject to:
$$
JX = A
$$

The langrange is given by:

$$
L = X^T M X - \lambda^{T} (JX - A )
$$


The FOC under the lagrange multiplier will be $(M + M^T)X - J^T \lambda = 0$ and $JX =A$. In matricial form:

\begin{equation}
\begin{pmatrix}
(M+M^T) & -J^T \\
J & 0
\end{pmatrix}
\begin{pmatrix}
X \\
\lambda
\end{pmatrix}=
\begin{pmatrix}
0 \\
A
\end{pmatrix}
\end{equation}

The solution is given by:

\begin{equation}
\begin{pmatrix}
X \\
\lambda
\end{pmatrix}=
\begin{pmatrix}
(M+M^T) & -J^T \\
J & 0
\end{pmatrix}^{-1}
\begin{pmatrix}
0 \\
A
\end{pmatrix}
\end{equation}



```python
import denton
import numpy as np


help(denton.proportional_method)
```

    Help on function proportional_method in module denton:
    
    proportional_method(I, A)
        Inputs:
            I = indicator array to be use in the benchmark. 
            Ordered from t0 to tn (high frequncy) ex. quarterly data
            A =  aggregate data represented as every element as mean of a the n subset of I 
            (in the same order) (low frequncy) ex. annual data
            I/A has to be integer i.e the elements in the indicator data must the multiple of A.
        Output
            B = array with high frequency interpolation of the high frequency data in the low frequency
        
        Example:
        Taken from: https://www.imf.org/external/pubs/ft/qna/pdf/2017/chapter6.pdf
        Table: Example 6.2
        
        import numpy as np
        import denton
        
        I = np.array([99.4,99.6,100.1,100.9,101.7,102.2,102.9,
             103.8,104.9,106.3,107.3,107.8,107.9,
             107.5,107.2,107.5])
        A = np.array([1000, 1040, 1060.8, 1064.9])
        
        #the average of every 4 in the quarterly data = annual data
        B = denton.proportional_method(I, A)    
        
        #to replicate the table then divide by 4
        B_imf = denton.proportional_method(I, A)/4
    



```python
I = np.array([99.4,99.6,100.1,100.9,101.7,102.2,102.9,
              103.8,104.9,106.3,107.3,107.8,107.9,
              107.5,107.2,107.5])
A = np.array([1000, 1040, 1060.8, 1064.9])

#the average of every 4 in the data annual data
B = denton.proportional_method(I, A)

#to replicate the table then divide by 4
B_imf = denton.proportional_method(I, A)/4

print(B_imf)

```

    [[247.47624703]
     [248.38181462]
     [250.44888312]
     [253.69305523]
     [257.37943434]
     [259.40742807]
     [261.02059637]
     [262.19254122]
     [262.88387148]
     [264.79745537]
     [266.21069991]
     [266.90797325]
     [267.15445131]
     [266.16323935]
     [265.41990401]
     [266.16240533]]



```python

```

73a7ce95edb603f60e9885dcb2d4cfe483c6cc88
ipynb
Jupyter Notebook
example.ipynb
MaxLugo/denton
6c7b2fa6df66cd3aa4bdf3e4ca9fda4435553d5b
MIT
example.ipynb
MaxLugo/denton
6c7b2fa6df66cd3aa4bdf3e4ca9fda4435553d5b
MIT
example.ipynb
MaxLugo/denton
6c7b2fa6df66cd3aa4bdf3e4ca9fda4435553d5b
MIT
2021-01-04T19:18:02.000Z
2021-01-04T19:18:02.000Z
Qwen/Qwen-72B
1. YES
2. YES