Skip to content

Commit 9ec31d5

Browse files
committed
TST: (styleguide) qe-writing-001 (sonnet 4.5)
1 parent e9402db commit 9ec31d5

File tree

1 file changed

+53
-55
lines changed

1 file changed

+53
-55
lines changed

lectures/additive_functionals.md

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ For example, outputs, prices, and dividends typically display irregular but per
4141

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

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.
4547

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

@@ -83,8 +85,9 @@ from scipy.stats import norm, lognorm
8385

8486
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.
8587

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.
8891

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

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

187190
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).
188191

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.
190195

191196
## Dynamics
192197

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

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

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`.
229234

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.
231240

232241
### Simulation
233242

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

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

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).
759770

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

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.
764774

765775
$$
766776
\begin{bmatrix}
@@ -837,24 +847,21 @@ $$
837847
\end{aligned}
838848
$$
839849

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.
842851

843852
## Code
844853

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

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.
849857

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.
853861

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

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.
858865

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

864871
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.
865872

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.
867876

868-
Notice tell-tale signs of these probability coverage shaded areas
877+
Notice tell-tale signs of these probability coverage shaded areas:
869878

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
874881

875882
### Associated multiplicative functional
876883

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

910917
Let's plot this multiplicative functional for our example.
911918

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.
914920

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

920926
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.
921927

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)$.
924931

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$.
927933

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

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

932938
### Peculiar large sample property
933939

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:
936941

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$
939943
* as $t \rightarrow +\infty$, $\widetilde M_t$ converges to
940944
zero almost surely
941945

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$.
944947

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

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

961964
## More about the multiplicative martingale
962965

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.
965967

966968
As we have seen, it has representation
967969

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

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

980-
In particular, we want to simulate 5000 sample paths of length $T$ for the case in which $x$ is a scalar and
981-
$[A, B, D, F] = [0.8, 0.001, 1.0, 0.01]$ and $\nu = 0.005$.
982+
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$.
982985

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

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

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

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.
992997

993998
```{code-cell} ipython3
994999
class AMF_LSS_VAR:
@@ -1142,8 +1147,7 @@ def population_means(amf, T=150):
11421147
return xmean, ymean
11431148
```
11441149

1145-
Now that we have these functions in our toolkit, let's apply them to run some
1146-
simulations.
1150+
Now that we have these functions in our toolkit, let's apply them to run some simulations.
11471151

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

11911195
```{note}
1192-
`scipy.stats.lognorm` expects you to pass the standard deviation
1193-
first $(tH \cdot H)$ and then the exponent of the mean as a
1194-
keyword argument `scale` (`scale=np.exp(-t * H2 / 2)`).
1196+
`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)`).
11951197
11961198
* See the documentation [here](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.lognorm.html#scipy.stats.lognorm).
11971199
@@ -1248,21 +1250,17 @@ plt.tight_layout()
12481250
plt.show()
12491251
```
12501252

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:
12521254

12531255
* 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$.
12561257
* 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$.
12591259

12601260
### Multiplicative martingale as likelihood ratio process
12611261

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

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

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

0 commit comments

Comments
 (0)