You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lectures/additive_functionals.md
+53-55Lines changed: 53 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,9 @@ For example, outputs, prices, and dividends typically display irregular but per
41
41
42
42
Asymptotic stationarity and ergodicity are key assumptions needed to make it possible to learn by applying statistical methods.
43
43
44
-
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.
44
+
But there are good ways to model time series that have persistent growth.
45
+
46
+
These models still enable statistical learning based on a law of large numbers for an asymptotically stationary and ergodic process.
45
47
46
48
Thus, {cite}`Hansen_2012_Eca` described two classes of time series models that accommodate growth.
47
49
@@ -83,8 +85,9 @@ from scipy.stats import norm, lognorm
83
85
84
86
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.
85
87
86
-
Our special additive functional displays interesting time series behavior while also being easy to construct, simulate, and analyze
87
-
by using linear state-space tools.
88
+
Our special additive functional displays interesting time series behavior.
89
+
90
+
It is also easy to construct, simulate, and analyze by using linear state-space tools.
88
91
89
92
We construct our additive functional from two pieces, the first of which is a **first-order vector autoregression** (VAR)
90
93
@@ -186,7 +189,9 @@ which is a standard linear state space system.
186
189
187
190
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).
188
191
189
-
But here we will use a different set of code for simulation, for reasons described below.
192
+
But here we will use a different set of code for simulation.
193
+
194
+
The reasons for this are described below.
190
195
191
196
## Dynamics
192
197
@@ -225,9 +230,13 @@ While {eq}`ftaf` is not a first order system like {eq}`old1_additive_functionals
225
230
226
231
* For an example of such a mapping, see [this example](https://python.quantecon.org/linear_models.html#second-order-difference-equation).
227
232
228
-
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$.
233
+
In fact, this whole model can be mapped into the additive functional system definition in {eq}`old1_additive_functionals` -- {eq}`old2_additive_functionals`.
229
234
230
-
You can try writing these matrices down now as an exercise --- correct expressions appear in the code below.
235
+
This requires appropriate selection of the matrices $A, B, D, F$.
236
+
237
+
You can try writing these matrices down now as an exercise.
238
+
239
+
Correct expressions appear in the code below.
231
240
232
241
### Simulation
233
242
@@ -755,12 +764,13 @@ It is convenient for us to introduce the following notation:
755
764
756
765
We want to characterize and simulate components $\tau_t, m_t, s_t$ of the decomposition.
757
766
758
-
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).
767
+
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).
768
+
769
+
We use [LinearStateSpace](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/lss.py) from [QuantEcon.py](http://quantecon.org/quantecon-py).
759
770
760
771
This will allow us to use the routines in [LinearStateSpace](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/lss.py) to study dynamics.
761
772
762
-
To start, observe that, under the dynamics in {eq}`old1_additive_functionals` and {eq}`old2_additive_functionals` and with the
763
-
definitions just given,
773
+
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.
764
774
765
775
$$
766
776
\begin{bmatrix}
@@ -837,24 +847,21 @@ $$
837
847
\end{aligned}
838
848
$$
839
849
840
-
By picking out components of $\tilde y_t$, we can track all variables of
841
-
interest.
850
+
By picking out components of $\tilde y_t$, we can track all variables of interest.
842
851
843
852
## Code
844
853
845
854
The class `AMF_LSS_VAR` mentioned {ref}`above <amf_lss>` does all that we want to study our additive functional.
846
855
847
-
In fact, `AMF_LSS_VAR` does more
848
-
because it allows us to study an associated multiplicative functional as well.
856
+
In fact, `AMF_LSS_VAR` does more because it allows us to study an associated multiplicative functional as well.
849
857
850
-
(A hint that it does more is the name of the class -- here AMF stands for
851
-
"additive and multiplicative functional" -- the code computes and displays objects associated with
852
-
multiplicative functionals too.)
858
+
(A hint that it does more is the name of the class -- here AMF stands for "additive and multiplicative functional".)
859
+
860
+
The code computes and displays objects associated with multiplicative functionals too.
853
861
854
862
Let's use this code (embedded above) to explore the {ref}`example process described above <addfunc_eg1>`.
855
863
856
-
If you run {ref}`the code that first simulated that example <addfunc_egcode>` again and then the method call
857
-
you will generate (modulo randomness) the plot
864
+
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.
858
865
859
866
```{code-cell} ipython3
860
867
plot_additive(amf, T)
@@ -863,14 +870,14 @@ plt.show()
863
870
864
871
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.
865
872
866
-
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).
873
+
We have chosen to simulate many paths, all starting from the *same* non-random initial conditions $x_0, y_0$.
874
+
875
+
You can tell this from the shape of the 95% probability coverage shaded areas.
867
876
868
-
Notice tell-tale signs of these probability coverage shaded areas
877
+
Notice tell-tale signs of these probability coverage shaded areas:
869
878
870
-
* the purple one for the martingale component $m_t$ grows with
871
-
$\sqrt{t}$
872
-
* the green one for the stationary component $s_t$ converges to a
873
-
constant band
879
+
* the purple one for the martingale component $m_t$ grows with $\sqrt{t}$
880
+
* the green one for the stationary component $s_t$ converges to a constant band
874
881
875
882
### Associated multiplicative functional
876
883
@@ -909,8 +916,7 @@ An instance of class `AMF_LSS_VAR` ({ref}`above <amf_lss>`) includes this assoc
909
916
910
917
Let's plot this multiplicative functional for our example.
911
918
912
-
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
913
-
obtain the graph in the next cell.
919
+
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.
914
920
915
921
```{code-cell} ipython3
916
922
plot_multiplicative(amf, T)
@@ -919,28 +925,25 @@ plt.show()
919
925
920
926
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.
921
927
922
-
Comparing this figure and the last also helps show how geometric growth differs from
923
-
arithmetic growth.
928
+
Comparing this figure and the last also helps show how geometric growth differs from arithmetic growth.
929
+
930
+
The top right panel of the above graph shows a panel of martingales associated with the panel of $M_t = \exp(y_t)$.
924
931
925
-
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
926
-
for a limited horizon $T$.
932
+
We have generated these for a limited horizon $T$.
927
933
928
934
It is interesting to how the martingale behaves as $T \rightarrow +\infty$.
929
935
930
936
Let's see what happens when we set $T = 12000$ instead of $150$.
931
937
932
938
### Peculiar large sample property
933
939
934
-
Hansen and Sargent {cite}`Hans_Sarg_book` (ch. 8) describe the following two properties of the martingale component
935
-
$\widetilde M_t$ of the multiplicative decomposition
940
+
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:
936
941
937
-
* while $E_0 \widetilde M_t = 1$ for all $t \geq 0$,
938
-
nevertheless $\ldots$
942
+
* while $E_0 \widetilde M_t = 1$ for all $t \geq 0$, nevertheless $\ldots$
939
943
* as $t \rightarrow +\infty$, $\widetilde M_t$ converges to
940
944
zero almost surely
941
945
942
-
The first property follows from the fact that $\widetilde M_t$ is a multiplicative martingale with initial condition
943
-
$\widetilde M_0 = 1$.
946
+
The first property follows from the fact that $\widetilde M_t$ is a multiplicative martingale with initial condition $\widetilde M_0 = 1$.
944
947
945
948
The second is a **peculiar property** noted and proved by Hansen and Sargent {cite}`Hans_Sarg_book`.
946
949
@@ -960,8 +963,7 @@ The purple 95 percent frequency coverage interval collapses around zero, illustr
960
963
961
964
## More about the multiplicative martingale
962
965
963
-
Let's drill down and study probability distribution of the multiplicative martingale $\{\widetilde M_t\}_{t=0}^\infty$ in
964
-
more detail.
966
+
Let's drill down and study probability distribution of the multiplicative martingale $\{\widetilde M_t\}_{t=0}^\infty$ in more detail.
965
967
966
968
As we have seen, it has representation
967
969
@@ -977,8 +979,9 @@ It follows that $\log {\widetilde M}_t \sim {\mathcal N} ( -\frac{t H \cdot H}{2
977
979
978
980
Next, we want a program to simulate the likelihood ratio process $\{ \tilde{M}_t \}_{t=0}^\infty$.
979
981
980
-
In particular, we want to simulate 5000 sample paths of length $T$ for the case in which $x$ is a scalar and
In particular, we want to simulate 5000 sample paths of length $T$ for the case in which $x$ is a scalar.
983
+
984
+
We use $[A, B, D, F] = [0.8, 0.001, 1.0, 0.01]$ and $\nu = 0.005$.
982
985
983
986
After accomplishing this, we want to display and study histograms of $\tilde{M}_T^i$ for various values of $T$.
984
987
@@ -988,7 +991,9 @@ Here is code that accomplishes these tasks.
988
991
989
992
Let's write a program to simulate sample paths of $\{ x_t, y_{t} \}_{t=0}^{\infty}$.
990
993
991
-
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.
994
+
We'll do this by formulating the additive functional as a linear state space model.
995
+
996
+
We put the [LinearStateSpace](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/lss.py) class to work.
`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)`).
1195
1197
1196
1198
* See the documentation [here](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.lognorm.html#scipy.stats.lognorm).
1197
1199
@@ -1248,21 +1250,17 @@ plt.tight_layout()
1248
1250
plt.show()
1249
1251
```
1250
1252
1251
-
These probability density functions help us understand mechanics underlying the **peculiar property** of our multiplicative martingale
1253
+
These probability density functions help us understand mechanics underlying the **peculiar property** of our multiplicative martingale:
1252
1254
1253
1255
* As $T$ grows, most of the probability mass shifts leftward toward zero.
1254
-
* For example, note that most mass is near $1$ for $T =10$ or $T = 100$ but
1255
-
most of it is near $0$ for $T = 5000$.
1256
+
* 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$.
1256
1257
* As $T$ grows, the tail of the density of $\widetilde M_T$ lengthens toward the right.
1257
-
* Enough mass moves toward the right tail to keep $E \widetilde M_T = 1$
1258
-
even as most mass in the distribution of $\widetilde M_T$ collapses around $0$.
1258
+
* 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$.
1259
1259
1260
1260
### Multiplicative martingale as likelihood ratio process
Likelihood ratio processes exhibit the peculiar property that naturally also appears [here](https://python.quantecon.org/likelihood_ratio_process.html).
0 commit comments