Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 53 additions & 55 deletions lectures/additive_functionals.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ For example, outputs, prices, and dividends typically display irregular but per

Asymptotic stationarity and ergodicity are key assumptions needed to make it possible to learn by applying statistical methods.

But there are good ways to model time series that have persistent growth that still enable statistical learning based on a law of large numbers for an asymptotically stationary and ergodic process.
But there are good ways to model time series that have persistent growth.

These models still enable statistical learning based on a law of large numbers for an asymptotically stationary and ergodic process.

Thus, {cite}`Hansen_2012_Eca` described two classes of time series models that accommodate growth.

Expand Down Expand Up @@ -83,8 +85,9 @@ from scipy.stats import norm, lognorm

This lecture focuses on a subclass of these: a scalar process $\{y_t\}_{t=0}^\infty$ whose increments are driven by a Gaussian vector autoregression.

Our special additive functional displays interesting time series behavior while also being easy to construct, simulate, and analyze
by using linear state-space tools.
Our special additive functional displays interesting time series behavior.

It is also easy to construct, simulate, and analyze by using linear state-space tools.

We construct our additive functional from two pieces, the first of which is a **first-order vector autoregression** (VAR)

Expand Down Expand Up @@ -186,7 +189,9 @@ which is a standard linear state space system.

To study it, we could map it into an instance of [LinearStateSpace](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/lss.py) from [QuantEcon.py](http://quantecon.org/quantecon-py).

But here we will use a different set of code for simulation, for reasons described below.
But here we will use a different set of code for simulation.

The reasons for this are described below.

## Dynamics

Expand Down Expand Up @@ -225,9 +230,13 @@ While {eq}`ftaf` is not a first order system like {eq}`old1_additive_functionals

* For an example of such a mapping, see [this example](https://python.quantecon.org/linear_models.html#second-order-difference-equation).

In fact, this whole model can be mapped into the additive functional system definition in {eq}`old1_additive_functionals` -- {eq}`old2_additive_functionals` by appropriate selection of the matrices $A, B, D, F$.
In fact, this whole model can be mapped into the additive functional system definition in {eq}`old1_additive_functionals` -- {eq}`old2_additive_functionals`.

You can try writing these matrices down now as an exercise --- correct expressions appear in the code below.
This requires appropriate selection of the matrices $A, B, D, F$.

You can try writing these matrices down now as an exercise.

Correct expressions appear in the code below.

### Simulation

Expand Down Expand Up @@ -755,12 +764,13 @@ It is convenient for us to introduce the following notation:

We want to characterize and simulate components $\tau_t, m_t, s_t$ of the decomposition.

A convenient way to do this is to construct an appropriate instance of a [linear state space system](https://python-intro.quantecon.org/linear_models.html) by using [LinearStateSpace](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/lss.py) from [QuantEcon.py](http://quantecon.org/quantecon-py).
A convenient way to do this is to construct an appropriate instance of a [linear state space system](https://python-intro.quantecon.org/linear_models.html).

We use [LinearStateSpace](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/lss.py) from [QuantEcon.py](http://quantecon.org/quantecon-py).

This will allow us to use the routines in [LinearStateSpace](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/lss.py) to study dynamics.

To start, observe that, under the dynamics in {eq}`old1_additive_functionals` and {eq}`old2_additive_functionals` and with the
definitions just given,
To start, observe that, under the dynamics in {eq}`old1_additive_functionals` and {eq}`old2_additive_functionals` and with the definitions just given, we have the following.

$$
\begin{bmatrix}
Expand Down Expand Up @@ -837,24 +847,21 @@ $$
\end{aligned}
$$

By picking out components of $\tilde y_t$, we can track all variables of
interest.
By picking out components of $\tilde y_t$, we can track all variables of interest.

## Code

The class `AMF_LSS_VAR` mentioned {ref}`above <amf_lss>` does all that we want to study our additive functional.

In fact, `AMF_LSS_VAR` does more
because it allows us to study an associated multiplicative functional as well.
In fact, `AMF_LSS_VAR` does more because it allows us to study an associated multiplicative functional as well.

(A hint that it does more is the name of the class -- here AMF stands for
"additive and multiplicative functional" -- the code computes and displays objects associated with
multiplicative functionals too.)
(A hint that it does more is the name of the class -- here AMF stands for "additive and multiplicative functional".)

The code computes and displays objects associated with multiplicative functionals too.

Let's use this code (embedded above) to explore the {ref}`example process described above <addfunc_eg1>`.

If you run {ref}`the code that first simulated that example <addfunc_egcode>` again and then the method call
you will generate (modulo randomness) the plot
If you run {ref}`the code that first simulated that example <addfunc_egcode>` again and then the method call you will generate (modulo randomness) the plot.

```{code-cell} ipython3
plot_additive(amf, T)
Expand All @@ -863,14 +870,14 @@ plt.show()

When we plot multiple realizations of a component in the 2nd, 3rd, and 4th panels, we also plot the population 95% probability coverage sets computed using the LinearStateSpace class.

We have chosen to simulate many paths, all starting from the *same* non-random initial conditions $x_0, y_0$ (you can tell this from the shape of the 95% probability coverage shaded areas).
We have chosen to simulate many paths, all starting from the *same* non-random initial conditions $x_0, y_0$.

You can tell this from the shape of the 95% probability coverage shaded areas.

Notice tell-tale signs of these probability coverage shaded areas
Notice tell-tale signs of these probability coverage shaded areas:

* the purple one for the martingale component $m_t$ grows with
$\sqrt{t}$
* the green one for the stationary component $s_t$ converges to a
constant band
* the purple one for the martingale component $m_t$ grows with $\sqrt{t}$
* the green one for the stationary component $s_t$ converges to a constant band

### Associated multiplicative functional

Expand Down Expand Up @@ -909,8 +916,7 @@ An instance of class `AMF_LSS_VAR` ({ref}`above <amf_lss>`) includes this assoc

Let's plot this multiplicative functional for our example.

If you run {ref}`the code that first simulated that example <addfunc_egcode>` again and then the method call in the cell below you'll
obtain the graph in the next cell.
If you run {ref}`the code that first simulated that example <addfunc_egcode>` again and then the method call in the cell below you'll obtain the graph in the next cell.

```{code-cell} ipython3
plot_multiplicative(amf, T)
Expand All @@ -919,28 +925,25 @@ plt.show()

As before, when we plotted multiple realizations of a component in the 2nd, 3rd, and 4th panels, we also plotted population 95% confidence bands computed using the LinearStateSpace class.

Comparing this figure and the last also helps show how geometric growth differs from
arithmetic growth.
Comparing this figure and the last also helps show how geometric growth differs from arithmetic growth.

The top right panel of the above graph shows a panel of martingales associated with the panel of $M_t = \exp(y_t)$.

The top right panel of the above graph shows a panel of martingales associated with the panel of $M_t = \exp(y_t)$ that we have generated
for a limited horizon $T$.
We have generated these for a limited horizon $T$.

It is interesting to how the martingale behaves as $T \rightarrow +\infty$.

Let's see what happens when we set $T = 12000$ instead of $150$.

### Peculiar large sample property

Hansen and Sargent {cite}`Hans_Sarg_book` (ch. 8) describe the following two properties of the martingale component
$\widetilde M_t$ of the multiplicative decomposition
Hansen and Sargent {cite}`Hans_Sarg_book` (ch. 8) describe the following two properties of the martingale component $\widetilde M_t$ of the multiplicative decomposition:

* while $E_0 \widetilde M_t = 1$ for all $t \geq 0$,
nevertheless $\ldots$
* while $E_0 \widetilde M_t = 1$ for all $t \geq 0$, nevertheless $\ldots$
* as $t \rightarrow +\infty$, $\widetilde M_t$ converges to
zero almost surely

The first property follows from the fact that $\widetilde M_t$ is a multiplicative martingale with initial condition
$\widetilde M_0 = 1$.
The first property follows from the fact that $\widetilde M_t$ is a multiplicative martingale with initial condition $\widetilde M_0 = 1$.

The second is a **peculiar property** noted and proved by Hansen and Sargent {cite}`Hans_Sarg_book`.

Expand All @@ -960,8 +963,7 @@ The purple 95 percent frequency coverage interval collapses around zero, illustr

## More about the multiplicative martingale

Let's drill down and study probability distribution of the multiplicative martingale $\{\widetilde M_t\}_{t=0}^\infty$ in
more detail.
Let's drill down and study probability distribution of the multiplicative martingale $\{\widetilde M_t\}_{t=0}^\infty$ in more detail.

As we have seen, it has representation

Expand All @@ -977,8 +979,9 @@ It follows that $\log {\widetilde M}_t \sim {\mathcal N} ( -\frac{t H \cdot H}{2

Next, we want a program to simulate the likelihood ratio process $\{ \tilde{M}_t \}_{t=0}^\infty$.

In particular, we want to simulate 5000 sample paths of length $T$ for the case in which $x$ is a scalar and
$[A, B, D, F] = [0.8, 0.001, 1.0, 0.01]$ and $\nu = 0.005$.
In particular, we want to simulate 5000 sample paths of length $T$ for the case in which $x$ is a scalar.

We use $[A, B, D, F] = [0.8, 0.001, 1.0, 0.01]$ and $\nu = 0.005$.

After accomplishing this, we want to display and study histograms of $\tilde{M}_T^i$ for various values of $T$.

Expand All @@ -988,7 +991,9 @@ Here is code that accomplishes these tasks.

Let's write a program to simulate sample paths of $\{ x_t, y_{t} \}_{t=0}^{\infty}$.

We'll do this by formulating the additive functional as a linear state space model and putting the [LinearStateSpace](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/lss.py) class to work.
We'll do this by formulating the additive functional as a linear state space model.

We put the [LinearStateSpace](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/lss.py) class to work.

```{code-cell} ipython3
class AMF_LSS_VAR:
Expand Down Expand Up @@ -1142,8 +1147,7 @@ def population_means(amf, T=150):
return xmean, ymean
```

Now that we have these functions in our toolkit, let's apply them to run some
simulations.
Now that we have these functions in our toolkit, let's apply them to run some simulations.

```{code-cell} ipython3
def simulate_martingale_components(amf, T=1000, I=5000):
Expand Down Expand Up @@ -1189,9 +1193,7 @@ Then let's use the plots to investigate how these densities evolve through time
We will plot the densities of $\log {\widetilde M}_t$ for different values of $t$.

```{note}
`scipy.stats.lognorm` expects you to pass the standard deviation
first $(tH \cdot H)$ and then the exponent of the mean as a
keyword argument `scale` (`scale=np.exp(-t * H2 / 2)`).
`scipy.stats.lognorm` expects you to pass the standard deviation first $(tH \cdot H)$ and then the exponent of the mean as a keyword argument `scale` (`scale=np.exp(-t * H2 / 2)`).

* See the documentation [here](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.lognorm.html#scipy.stats.lognorm).

Expand Down Expand Up @@ -1248,21 +1250,17 @@ plt.tight_layout()
plt.show()
```

These probability density functions help us understand mechanics underlying the **peculiar property** of our multiplicative martingale
These probability density functions help us understand mechanics underlying the **peculiar property** of our multiplicative martingale:

* As $T$ grows, most of the probability mass shifts leftward toward zero.
* For example, note that most mass is near $1$ for $T =10$ or $T = 100$ but
most of it is near $0$ for $T = 5000$.
* For example, note that most mass is near $1$ for $T =10$ or $T = 100$ but most of it is near $0$ for $T = 5000$.
* As $T$ grows, the tail of the density of $\widetilde M_T$ lengthens toward the right.
* Enough mass moves toward the right tail to keep $E \widetilde M_T = 1$
even as most mass in the distribution of $\widetilde M_T$ collapses around $0$.
* Enough mass moves toward the right tail to keep $E \widetilde M_T = 1$ even as most mass in the distribution of $\widetilde M_T$ collapses around $0$.

### Multiplicative martingale as likelihood ratio process

[This lecture](https://python.quantecon.org/likelihood_ratio_process.html) studies **likelihood processes**
and **likelihood ratio processes**.
[This lecture](https://python.quantecon.org/likelihood_ratio_process.html) studies **likelihood processes** and **likelihood ratio processes**.

A **likelihood ratio process** is a multiplicative martingale with mean unity.

Likelihood ratio processes exhibit the peculiar property that naturally also appears
[here](https://python.quantecon.org/likelihood_ratio_process.html).
Likelihood ratio processes exhibit the peculiar property that naturally also appears [here](https://python.quantecon.org/likelihood_ratio_process.html).
Loading