Skip to content

Commit 426bd09

Browse files
authored
ENH: Migrate exercise and solutions: Part 2 (#118)
* lqramsey exercise * arellano exercise * update matsuyama * update coase * lucas_model update * lu_tricks update * amss update * asl update * classical_filtering update * estspec * fix dollar signs * adding dollar sign back * aligned update * adding a sentence * update smoothing_tax
1 parent ccbc004 commit 426bd09

11 files changed

+256
-104
lines changed

lectures/amss.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,16 @@ $$
616616
\Pi(\tilde s| s_-) u_c(\tilde s)}}
617617
$$
618618

619-
**Exercise**: Please verify that $\check \Pi(s|s_-)$ is a valid Markov
619+
```{exercise-start}
620+
:label: amss_ex1
621+
```
622+
Please verify that $\check \Pi(s|s_-)$ is a valid Markov
620623
transition density, i.e., that its elements are all non-negative and
621624
that for each $s_-$, the sum over $s$ equals unity.
622625

626+
```{exercise-end}
627+
```
628+
623629
### Absence of State Variable Degeneracy
624630

625631
Along a Ramsey plan, the state variable $x_t = x_t(s^t, b_0)$

lectures/arellano.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -689,14 +689,21 @@ Periods of relative stability are followed by sharp spikes in the discount rate
689689
## Exercises
690690

691691
(arellano_ex1)=
692-
### Exercise 1
692+
```{exercise-start}
693+
:label: arella_ex1
694+
```
693695

694696
To the extent that you can, replicate the figures shown above
695697

696698
* Use the parameter values listed as defaults in `Arellano_Economy`.
697699
* The time series will of course vary depending on the shock draws.
698700

699-
## Solutions
701+
```{exercise-end}
702+
```
703+
704+
```{solution-start} arella_ex1
705+
:class: dropdown
706+
```
700707

701708
Compute the value function, policy and equilibrium prices
702709

@@ -818,3 +825,5 @@ for ax, series, title in zip(axes, plot_series, titles):
818825
819826
plt.show()
820827
```
828+
```{solution-end}
829+
```

lectures/asset_pricing_lph.md

+102-51
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,9 @@ def simple_ols(X, Y, constant=False):
464464
return β_hat, σ_hat
465465
```
466466
467-
### Exercise 1
467+
```{exercise-start}
468+
:label: apl_ex1
469+
```
468470
469471
Look at the equation,
470472
@@ -474,11 +476,60 @@ $$
474476
475477
Verify that this equation is a regression equation.
476478
477-
### Exercise 2
479+
```{exercise-end}
480+
```
481+
482+
```{solution-start} apl_ex1
483+
:class: dropdown
484+
```
485+
486+
To verify that it is a **regression equation** we must show that the residual is orthogonal to the regressor.
487+
488+
Our assumptions about mutual orthogonality imply that
489+
490+
$$
491+
E\left[\epsilon_{i,t}\right]=0,\quad E\left[\epsilon_{i,t}u_{t}\right]=0
492+
$$
493+
494+
It follows that
495+
496+
$$
497+
\begin{aligned}
498+
E\left[\sigma_{i}\epsilon_{i,t}\left(R_{t}^{m}-R^{f}\right)\right]&=E\left[\sigma_{i}\epsilon_{i,t}\left(\xi+\lambda u_{t}\right)\right] \\
499+
&=\sigma_{i}\xi E\left[\epsilon_{i,t}\right]+\sigma_{i}\lambda E\left[\epsilon_{i,t}u_{t}\right] \\
500+
&=0
501+
\end{aligned}
502+
$$
503+
504+
```{solution-end}
505+
```
506+
507+
508+
```{exercise-start}
509+
:label: apl_ex2
510+
```
478511
479512
Give a formula for the regression coefficient $\beta_{i, R^m}$.
480513
481-
### Exercise 3
514+
```{exercise-end}
515+
```
516+
517+
```{solution-start} apl_ex2
518+
:class: dropdown
519+
```
520+
521+
The regression coefficient $\beta_{i, R^m}$ is
522+
523+
$$
524+
\beta_{i,R^{m}}=\frac{Cov\left(R_{t}^{i}-R^{f},R_{t}^{m}-R^{f}\right)}{Var\left(R_{t}^{m}-R^{f}\right)}
525+
$$
526+
527+
```{solution-end}
528+
```
529+
530+
```{exercise-start}
531+
:label: apl_ex3
532+
```
482533
483534
As in many sciences, it is useful to distinguish a **direct problem** from an **inverse problem**.
484535
@@ -522,51 +573,12 @@ E[(a + b R_t^m) R^m_t)] &= 1 \\
522573
E[(a + b R_t^m) R^f_t)] &= 1
523574
\end{align*}
524575
525-
### Exercise 4
526-
527-
Using the equations above, find a system of two **linear** equations that you can solve for $a$ and $b$ as functions of the parameters $(\lambda, \xi, E[R_f])$.
528-
529-
Write a function that can solve these equations.
530-
531-
Please check the **condition number** of a key matrix that must be inverted to determine a, b
532-
533-
### Exercise 5
534-
535-
Using the estimates of the parameters that you generated above, compute the implied stochastic discount factor.
536-
537-
538-
539-
## Solutions
540-
541-
### Solution to Exercise 1
542-
543-
To verify that it is a **regression equation** we must show that the residual is orthogonal to the regressor.
544-
545-
Our assumptions about mutual orthogonality imply that
546-
547-
$$
548-
E\left[\epsilon_{i,t}\right]=0,\quad E\left[\epsilon_{i,t}u_{t}\right]=0
549-
$$
550-
551-
It follows that
552-
553-
$$
554-
\begin{aligned}
555-
E\left[\sigma_{i}\epsilon_{i,t}\left(R_{t}^{m}-R^{f}\right)\right]&=E\left[\sigma_{i}\epsilon_{i,t}\left(\xi+\lambda u_{t}\right)\right] \\
556-
&=\sigma_{i}\xi E\left[\epsilon_{i,t}\right]+\sigma_{i}\lambda E\left[\epsilon_{i,t}u_{t}\right] \\
557-
&=0
558-
\end{aligned}
559-
$$
560-
561-
### Solution to Exercise 2
562-
563-
The regression coefficient $\beta_{i, R^m}$ is
564-
565-
$$
566-
\beta_{i,R^{m}}=\frac{Cov\left(R_{t}^{i}-R^{f},R_{t}^{m}-R^{f}\right)}{Var\left(R_{t}^{m}-R^{f}\right)}
567-
$$
576+
```{exercise-end}
577+
```
568578
569-
### Solution to Exercise 3
579+
```{solution-start} apl_ex3
580+
:class: dropdown
581+
```
570582
571583
**Direct Problem:**
572584
@@ -670,14 +682,36 @@ for i in range(N):
670682
671683
Q: How close did your estimates come to the parameters we specified?
672684
685+
```{solution-end}
686+
```
687+
688+
```{exercise-start}
689+
:label: apl_ex4
690+
```
691+
692+
Using the equations above, find a system of two **linear** equations that you can solve for $a$ and $b$ as functions of the parameters $(\lambda, \xi, E[R_f])$.
693+
694+
Write a function that can solve these equations.
695+
696+
Please check the **condition number** of a key matrix that must be inverted to determine a, b
673697
698+
```{exercise-end}
699+
```
700+
701+
```{solution-start} apl_ex4
702+
:class: dropdown
703+
```
704+
705+
The system of two linear equations is shown below:
674706
675-
### Solution to Exercise 4
676707
677-
\begin{align}
708+
$$
709+
\begin{aligned}
678710
a ((E(R^f) + \xi) + b ((E(R^f) + \xi)^2 + \lambda^2 + \sigma_f^2) & =1 \cr
679711
a E(R^f) + b (E(R^f)^2 + \xi E(R^f) + \sigma_f ^ 2) & = 1
680-
\end{align}
712+
\end{aligned}
713+
$$
714+
681715
682716
```{code-cell} ipython3
683717
# Code here
@@ -705,7 +739,21 @@ a, b, condM = solve_ab(ERf, σf, λ, ξ)
705739
a, b, condM
706740
```
707741
708-
### Solution to Exercise 5
742+
```{solution-end}
743+
```
744+
745+
```{exercise-start}
746+
:label: apl_ex5
747+
```
748+
749+
Using the estimates of the parameters that you generated above, compute the implied stochastic discount factor.
750+
751+
```{exercise-end}
752+
```
753+
754+
```{solution-start} apl_ex5
755+
:class: dropdown
756+
```
709757
710758
Now let's pass $\hat{E}(R^f), \hat{\sigma}^f, \hat{\lambda}, \hat{\xi}$ to the function `solve_ab`.
711759
@@ -715,4 +763,7 @@ a_hat, b_hat, M_hat = solve_ab(ERf_hat, σf_hat, λ_hat, ξ_hat)
715763
716764
```{code-cell} ipython3
717765
a_hat, b_hat, M_hat
766+
```
767+
768+
```{solution-end}
718769
```

lectures/classical_filtering.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,9 @@ and that the zeros of $\theta (z)$ are not inside the unit circle.
935935

936936
## Exercises
937937

938-
### Exercise 1
938+
```{exercise-start}
939+
:label: cf_ex1
940+
```
939941

940942
Let $Y_t = (1 - 2 L ) u_t$ where $u_t$ is a mean zero
941943
white noise with $\mathbb{E} u^2_t = 1$. Let
@@ -964,7 +966,13 @@ $$
964966
X_{t-j}
965967
$$
966968

967-
### Exercise 2
969+
```{exercise-end}
970+
```
971+
972+
```{exercise-start}
973+
:label: cf_ex2
974+
```
975+
968976

969977
**Multivariable Prediction:** Let $Y_t$ be an $(n\times 1)$
970978
vector stochastic process with moving average representation
@@ -1038,3 +1046,6 @@ $$
10381046
= \left[{C(L) \over L^J} \right]_+ C(L)^{-1}\, X_t
10391047
$$
10401048

1049+
```{exercise-end}
1050+
```
1051+

lectures/coase.md

+30-15
Original file line numberDiff line numberDiff line change
@@ -575,27 +575,22 @@ Note that downstream firms choose to be larger, a point we return to below.
575575
## Exercises
576576

577577
(lucas_asset_exer1)=
578-
### Exercise 1
579-
578+
```{exercise-start}
579+
:label: coa_ex1
580+
```
580581
The number of firms is endogenously determined by the primitives.
581582

582583
What do you think will happen in terms of the number of firms as $\delta$ increases? Why?
583584

584585
Check your intuition by computing the number of firms at delta in (1.01, 1.05, 1.1).
585586

586-
### Exercise 2
587-
588-
The **value added** of firm $i$ is $v_i := p^*(t_{i-1}) - p^*(t_i)$.
589-
590-
One of the interesting predictions of the model is that value added is increasing with downstreamness, as are several other measures of firm size.
591-
592-
Can you give any intution?
593-
594-
Try to verify this phenomenon (value added increasing with downstreamness) using the code above.
595-
596-
## Solutions
587+
```{exercise-end}
588+
```
597589

598-
### Exercise 1
590+
```{solution-start} coa_ex1
591+
:class: dropdown
592+
```
593+
Here is one solution
599594

600595
```{code-cell} python3
601596
for delta in (1.01, 1.05, 1.1):
@@ -606,8 +601,26 @@ for delta in (1.01, 1.05, 1.1):
606601
num_firms = len(transaction_stages)
607602
print(f"When delta={delta} there are {num_firms} firms")
608603
```
604+
```{solution-end}
605+
```
606+
607+
```{exercise-start}
608+
:label: coa_ex2
609+
```
610+
The **value added** of firm $i$ is $v_i := p^*(t_{i-1}) - p^*(t_i)$.
609611

610-
### Exercise 2
612+
One of the interesting predictions of the model is that value added is increasing with downstreamness, as are several other measures of firm size.
613+
614+
Can you give any intution?
615+
616+
Try to verify this phenomenon (value added increasing with downstreamness) using the code above.
617+
618+
```{exercise-end}
619+
```
620+
621+
```{solution-start} coa_ex2
622+
:class: dropdown
623+
```
611624

612625
Firm size increases with downstreamness because $p^*$, the equilibrium price function, is increasing and strictly convex.
613626

@@ -640,3 +653,5 @@ ax.set_xticklabels(("downstream firms", "upstream firms"))
640653
plt.show()
641654
```
642655

656+
```{solution-end}
657+
```

0 commit comments

Comments
 (0)