@@ -4,7 +4,7 @@ jupytext:
4
4
extension : .md
5
5
format_name : myst
6
6
format_version : 0.13
7
- jupytext_version : 1.16.2
7
+ jupytext_version : 1.16.1
8
8
kernelspec :
9
9
display_name : Python 3 (ipykernel)
10
10
language : python
@@ -49,7 +49,12 @@ We will use the following imports:
49
49
import numpy as np
50
50
import matplotlib.pyplot as plt
51
51
from matplotlib import cm
52
- plt.rcParams["figure.figsize"] = (11, 5) #set default figure size
52
+
53
+ # Custom figsize for this lecture
54
+ plt.rcParams["figure.figsize"] = (11, 5)
55
+
56
+ # Set decimal printing to 3 decimal places
57
+ np.set_printoptions(precision=3, suppress=True)
53
58
```
54
59
55
60
## Samuelson's model
@@ -142,8 +147,8 @@ T = 80
142
147
α_1 = 1.53
143
148
α_2 = -.9
144
149
145
- y_neg1 = 28. # y_{-1}
146
- y_0 = 24.
150
+ y_neg1 = 28.0 # y_{-1}
151
+ y_0 = 24.0
147
152
```
148
153
149
154
Now we construct $A$ and $b$.
@@ -197,6 +202,13 @@ point precision:
197
202
np.allclose(y, y_second_method)
198
203
```
199
204
205
+ $A$ is invertible as it is lower triangular and [ its diagonal entries are non-zero] ( https://www.statlect.com/matrix-algebra/triangular-matrix )
206
+
207
+ ``` {code-cell} ipython3
208
+ # Check if A is lower triangular
209
+ np.allclose(A, np.tril(A))
210
+ ```
211
+
200
212
``` {note}
201
213
In general, `np.linalg.solve` is more numerically stable than using
202
214
`np.linalg.inv` directly.
@@ -392,7 +404,13 @@ class population_moments:
392
404
Parameters:
393
405
α_0, α_1, α_2, T, y_neg1, y_0
394
406
"""
395
- def __init__(self, α_0, α_1, α_2, T, y_neg1, y_0, σ_u):
407
+ def __init__(self, α_0=10.0,
408
+ α_1=1.53,
409
+ α_2=-.9,
410
+ T=80,
411
+ y_neg1=28.0,
412
+ y_0=24.0,
413
+ σ_u=1):
396
414
397
415
# compute A
398
416
A = np.identity(T)
@@ -437,8 +455,7 @@ class population_moments:
437
455
return self.μ_y, self.Σ_y
438
456
439
457
440
- series_process = population_moments(
441
- α_0=10.0, α_1=1.53, α_2=-.9, T=80, y_neg1=28., y_0=24., σ_u=1)
458
+ series_process = population_moments()
442
459
443
460
μ_y, Σ_y = series_process.get_moments()
444
461
A_inv = series_process.A_inv
@@ -483,12 +500,17 @@ Notice how the population variance increases and asymptotes.
483
500
Let's print out the covariance matrix $\Sigma_y$ for a time series $y$.
484
501
485
502
```{code-cell} ipython3
486
- series_process = population_moments(
487
- α_0=0, α_1=.8, α_2=0, T=6, y_neg1=0., y_0=0., σ_u=1)
503
+ series_process = population_moments(α_0=0,
504
+ α_1=.8,
505
+ α_2=0,
506
+ T=6,
507
+ y_neg1=0.,
508
+ y_0=0.,
509
+ σ_u=1)
488
510
489
511
μ_y, Σ_y = series_process.get_moments()
490
512
print("μ_y = ", μ_y)
491
- print("Σ_y = ", Σ_y)
513
+ print("Σ_y = \n ", Σ_y)
492
514
```
493
515
494
516
Notice that the covariance between $y_t$ and $y_{t-1}$ -- the elements on the superdiagonal -- are *not* identical.
@@ -502,9 +524,9 @@ We describe how to do that in [Linear State Space Models](https://python.quantec
502
524
But just to set the stage for that analysis, let's print out the bottom right corner of $\Sigma_y$.
503
525
504
526
```{code-cell} ipython3
505
- series_process = population_moments(
506
- α_0=10.0, α_1=1.53, α_2=-.9, T=80, y_neg1=28., y_0=24., σ_u=1)
527
+ series_process = population_moments()
507
528
μ_y, Σ_y = series_process.get_moments()
529
+
508
530
print("bottom right corner of Σ_y = \n", Σ_y[72:,72:])
509
531
```
510
532
@@ -529,26 +551,13 @@ To study the structure of $A^{-1}$, we shall print just up to $3$ decimals.
529
551
Let's begin by printing out just the upper left hand corner of $A^{-1}$.
530
552
531
553
```{code-cell} ipython3
532
- with np.printoptions(precision=3, suppress=True):
533
- print(A_inv[0:7,0:7])
554
+ print(A_inv[0:7,0:7])
534
555
```
535
556
536
557
Evidently, $A^{-1}$ is a lower triangular matrix.
537
558
538
-
539
- Let's print out the lower right hand corner of $A^{-1}$ and stare at it.
540
-
541
- ```{code-cell} ipython3
542
- with np.printoptions(precision=3, suppress=True):
543
- print(A_inv[72:,72:])
544
- ```
545
-
546
559
Notice how every row ends with the previous row's pre-diagonal entries.
547
560
548
-
549
-
550
-
551
-
552
561
Since $A^{-1}$ is lower triangular, each row represents $ y_t$ for a particular $t$ as the sum of
553
562
- a time-dependent function $A^{-1} b$ of the initial conditions incorporated in $b$, and
554
563
- a weighted sum of current and past values of the IID shocks $\{u_t\}$.
@@ -566,9 +575,6 @@ This is a **moving average** representation with time-varying coefficients.
566
575
Just as system {eq}`eq:eqma` constitutes a
567
576
**moving average** representation for $y$, system {eq}`eq:eqar` constitutes an **autoregressive** representation for $y$.
568
577
569
-
570
-
571
-
572
578
## A forward looking model
573
579
574
580
Samuelson’s model is *backward looking* in the sense that we give it *initial conditions* and let it
@@ -638,7 +644,7 @@ for i in range(T):
638
644
```
639
645
640
646
```{code-cell} ipython3
641
- B
647
+ print(B)
642
648
```
643
649
644
650
```{code-cell} ipython3
0 commit comments