-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path007_solution_midterm_exam2_format.Rmd
399 lines (323 loc) · 18.5 KB
/
007_solution_midterm_exam2_format.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
---
title: "Midterm Exam 2"
author:
- XXXXXXXX (Only code no name)
- XXXXXXXX (Only code no name)
- XXXXXXXX (Only code no name)
- XXXXXXXX (Only code no name)
- XXXXXXXX (Only code no name)
- XXXXXXXX (Only code no name)
date: ""
output:
html_document:
df_print: paged
highlight: tango
number_sections: yes
theme: flatly
toc: yes
toc_depth: 3
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,
warning = FALSE,
message = FALSE,
fig.align = "center")
```
```{r, libraries}
library(tidyverse)
library(lubridate)
library(tidyquant)
library(readxl)
library(zoo)
library(timetk)
library(modeest)
library(latex2exp)
```
# Financial markets II
## Nominal and real interest rate
+ Enter into the Bank of the Republic (Colombia) using the route:
**http://www.banrep.gov.co/** > Estadísticas > ¡NUEVO! Estadísticas Banrep > CATÁLOGO DE SERIES > Precios e inflación > Índices de precios al consumidor > Índice de precios al consumidor (IPC) > Base 2018 > Mensual > DESCARGAR > Descargar datos en Excel
```{r}
infla_monthly_na_values <- read_excel(path = "007_ipc_serie_variaciones-2.xlsx",
sheet = 1,
range = "A2:B801") %>%
set_names(nm = c("date", "ipc")) %>%
mutate(date = ymd(date) %>% floor_date(unit = "month"),
infla = ((ipc - lag(ipc, n = 12)) / lag(ipc, n = 12)) * 100)
infla_monthly <- infla_monthly_na_values %>%
drop_na()
```
1. Calculate the annual inflation using the monthly CPI that you can find in the column "IPC" from `r (infla_monthly$date[1] %>% as.character() %>% str_sub(start = 1, end = 7))` to `r (infla_monthly$date[length(infla_monthly$date)] %>% as.character() %>% str_sub(start = 1, end = 7))`. **(5 points)**
**Observation 1**: If the CPI is measured monthly then to calculate the annual inflation for a particular month you must use the formula, $\pi_t=\frac{CPI_t - CPI_{t-12}}{CPI_{t-12}}$. For example if you want to calculate the annual inflation of January 2000 you need to use the CPI of January 2000 and January 1999.
**Observation 2**: Taking into account **Observation 1** you need to begin to calculate the annual inflation from `r (infla_monthly$date[1] %>% as.character() %>% str_sub(start = 1, end = 7))` and not from a date between `r (infla_monthly_na_values$date[1] %>% as.character() %>% str_sub(start = 1, end = 7))` and `r (infla_monthly_na_values$date[12] %>% as.character() %>% str_sub(start = 1, end = 7))` because you don't have data before these dates to apply the formula $\pi_t=\frac{CPI_t - CPI_{t-12}}{CPI_{t-12}}$.
```{r}
ipc_base <- infla_monthly %>%
filter(ipc == 100) %>%
pull(date) %>%
as.character() %>%
str_sub(start = 1, end = 7)
infla_monthly %>%
mutate(infla = scales::number(infla, accuracy = 0.01, suffix = "%"),
date = date %>% as.character() %>% str_sub(start = 1, end = 7)) %>%
set_names(c("Date", str_glue("IPC (Base {ipc_base} = 100)"), "Inflation"))
```
```{r}
static_plot1 <- infla_monthly %>%
ggplot(aes(x = date,
y = infla)) +
geom_line(color = palette_light()[[1]]) +
labs(x = "",
y = "Percent",
title = "Annual inflation: Colombia",
subtitle = str_glue("Period: {infla_monthly$date[1] %>% as.character() %>% str_sub(start = 1, end = 7)} - {infla_monthly$date[length(infla_monthly$date)] %>% as.character() %>% str_sub(start = 1, end = 7)}
Price index used: Indice de Precios al Consumidor - IPC
IPC Base: {ipc_base} = 100"),
color = "") +
scale_y_continuous(labels = scales::number_format(accuracy = 1, suffix = "%")) +
theme(panel.border = element_rect(fill = NA, color = "black"),
plot.background = element_rect(fill = "#f3fcfc"),
panel.background = element_rect(fill = "#f3f7fc"),
legend.background = element_rect(fill = "#f3fcfc"),
legend.position = "none",
plot.title = element_text(face = "bold"),
axis.title = element_text(face = "bold"),
legend.title = element_text(face = "bold"),
axis.text = element_text(face = "bold"))
static_plot1
```
+ Enter into the Bank of the Republic (Colombia) using the route:
**http://www.banrep.gov.co/** > Estadísticas > ¡NUEVO! Estadísticas Banrep > CATÁLOGO DE SERIES > Tasas de interés y sector financiero > Tasas de interés > Tasa de política monetaria > Diaria > DESCARGAR > Descargar datos en Excel
2. Calculate the mode (in statistics the mode is the value that appears most frequently) of the interest rate fixed by the Bank of the Republic (Colombia) (in the data it refers to the column "Tasa de política monetaria") **for each month in each year**. In case of a tie choose any value within the most frequent values **(5 points)**.
```{r}
i_mode_monthly <- read_excel(path = "007_tip_serie_historica_diaria_IQY.xlsx",
sheet = 1,
range = "A2:B8408") %>%
set_names(nm = c("date", "i")) %>%
mutate(date = ymd(date)) %>%
summarize_by_time(.date_var = date, .by = "month", i = modeest::mfv1(i))
i_mode_monthly %>%
mutate(i = i %>% scales::number(accuracy = 0.01, suffix = "%")) %>%
set_names(nm = c("Date", "i")) %>%
mutate(Date = Date %>% as.character() %>% str_sub(start = 1, end = 7))
```
```{r}
static_plot2 <- i_mode_monthly %>%
ggplot(aes(x = date,
y = i)) +
geom_line(color = palette_light()[[1]]) +
labs(x = "",
y = "Percent",
title = "Monthly mode of monetary policy intervention rate: Colombia",
subtitle = str_glue("In the case of a tie the first most frequent value is choosen
Period: {i_mode_monthly$date[1] %>% as.character() %>% str_sub(start = 1, end = 7)} - {i_mode_monthly$date[length(i_mode_monthly$date)] %>% as.character() %>% str_sub(start = 1, end = 7)}"),
color = "") +
scale_y_continuous(labels = scales::number_format(accuracy = 1, suffix = "%")) +
theme(panel.border = element_rect(fill = NA, color = "black"),
plot.background = element_rect(fill = "#f3fcfc"),
panel.background = element_rect(fill = "#f3f7fc"),
legend.background = element_rect(fill = "#f3fcfc"),
legend.position = "none",
plot.title = element_text(face = "bold"),
axis.title = element_text(face = "bold"),
legend.title = element_text(face = "bold"),
axis.text = element_text(face = "bold"))
static_plot2
```
3. Calculate the real interest rate **for each month in each year** using the information found in point 1 and point 2, the information available and the formula $r_t = i_t - \pi_{t+12}$. **(5 points)**
**Observation 1**: The interest rate fixed by the Bank of the Republic (Colombia) is measure daily but the inflation is measure monthly. Therefore we are using the mode of the interest rate fixed by the Bank of the Republic (Colombia) for each month in each year so $i_t$ and $\pi_{t+12}$ are measure using the same periods. In that way all the variables are expressed monthly and $i_t$ will be equal to the mode of the interest rate fixed by the Bank of the Republic (Colombia) **for each month in each year**.
**Observation 2**: To calculate the real interest rate, keep in mind that it is not necessary to estimate an expected inflation rate since there is information from subsequent periods. Therefore $\pi_{t+12}$ is a variable that you already calculate in point 1.
**Observation 3**: To calculate the real interest rate, keep in mind that the nominal interest rate is expressed as **annual effective overdue**. In that sense, $\pi_{t+12}$ must be the inflation but 12 months later and that is why $\pi$ has a subscript equal to $t+12$.
```{r}
r_approx <- i_mode_monthly %>%
left_join(infla_monthly, by = "date") %>%
mutate(r_approx = i - lead(infla, n = 12))
r_approx %>%
select(date, i, infla, r_approx) %>%
mutate(across(.cols = i:r_approx,
.fns = scales::number,
accuracy = 0.01,
suffix = "%")) %>%
set_names(c("Date", "i", "Inflation", "r (approx)")) %>%
mutate(Date = Date %>% as.character() %>% str_sub(start = 1, end = 7))
```
4. Calculate the real interest rate **for each month in each year** using the information found in point 1 and point 2, the information available, the formula $1+r_t = \frac{1+i_t}{1+\pi_{t+12}}$ and taking into account the observations pointed out in point 3. **(5 points)**
**Observation 1**: Take into account that the objective is to calculate $r_t$ and not $1+r_t$.
**Observation 2**: To apply the formula $1+r_t = \frac{1+i_t}{1+\pi_{t+12}}$ to calculate $r_t$ take into account that $i_t$ and $\pi_{t+12}$ must be expressed in it's decimal form.
```{r}
r_approx_exact <- r_approx %>%
mutate(r_exact = (((1 + (i / 100)) / (1 + lead((infla / 100), n = 12))) - 1) * 100) %>%
drop_na()
r_approx_exact %>%
select(date, i, infla, r_approx, r_exact) %>%
mutate(across(.cols = i:r_exact,
.fns = scales::number,
accuracy = 0.01,
suffix = "%")) %>%
set_names(c("Date", "i", "Inflation", "r (approx)", "r (exact)")) %>%
mutate(Date = Date %>% as.character() %>% str_sub(start = 1, end = 7))
```
5. Plot the values of the interest rate fixed by the Bank of the Republic (Colombia) and the real interest rate for each month in each year using both formulas, $r_t = i_t - \pi_{t+12}$ and $1+r_t = \frac{1+i_t}{1+\pi_{t+12}}$, where the x-axis corresponds to the date and y-axis corresponds to the value of these variables. **(5 points)**
**Observation 1**: In the development of items 1 to 4, you will lose information from some periods. Therefore, when there is no data, do not indicate in the plot that a variable is equal to zero. It is not the same that a variable is equal to zero and that there is no data of this variable.
```{r}
# Data
r_approx_exact_clean <- r_approx_exact %>%
select(date, i, r_approx, r_exact) %>%
pivot_longer(cols = i:r_exact, names_to = "variable", values_to = "value") %>%
mutate(variable = case_when(
variable == "r_approx" ~ "r (approx)",
variable == "r_exact" ~ "r (exact)",
TRUE ~ variable),
variable = fct_relevel(variable, c("i", "r (exact)", "r (approx)")))
# Plot
r_approx_exact_clean %>%
ggplot(aes(x = date,
y = value)) +
geom_line(aes(color = variable,
group = variable)) +
geom_hline(yintercept = 0, color = palette_light()[[10]]) +
labs(x = "",
y = "Percent",
title = "Monetary policy intervention rate: i and r (exact and approximated)",
subtitle = str_glue("Period: {r_approx_exact_clean$date[1]} - {r_approx_exact_clean$date[length(r_approx_exact_clean$date)]}"),
color = "") +
scale_y_continuous(labels = scales::number_format(accuracy = 1, suffix = "%")) +
scale_color_tq() +
theme(panel.border = element_rect(fill = NA, color = "black"),
plot.background = element_rect(fill = "#f3fcfc"),
panel.background = element_rect(fill = "#f3f7fc"),
legend.background = element_rect(fill = "#f3fcfc"),
legend.position = "bottom",
plot.title = element_text(face = "bold"),
axis.title = element_text(face = "bold"),
legend.title = element_text(face = "bold"),
axis.text = element_text(face = "bold"))
```
## Exercise 8
This exercises is taken from:
**Oliver Blanchard (2017) Macroeconomics (7 Edition)** > Chapter 6 Financial Markets II: The extended IS-LM model > Questions and Problems > Exercise 8
In Chapter 6 the following formula is presented:
$$(1+i_t)=(1-p_t)(1+i_t+x_t)+p_t*0$$
Where $p_t$ is the probability the bond does not pay at all (the bond issuer is bankrupt) and has a zero return, $i_t$ is the nominal policy interest rate and $x_t$ is the risk premium.
6. If the probability of bankruptcy is zero, what is the rate of interest on the risk bond? **(5 points)**
The rate of interest of the risk bond is $i_t + x_t$. Also the **risk premium** can be found as follows:
$$\begin{split}
(1 + i_t) & = (1 - p_t)(1 + i_t + x_t) + p_t*0 \\
(1 + i_t) & = (1 - p_t)(1 + i_t)+ (1 - p_t)x_t
(1 + i_t)(1 - (1 - p_t)) & = (1 - p_t)x_t \\
(1 + i_t)p_t & = (1 - p_t)x_t \\
x_t & = \frac{(1 + i_t)p_t}{1 - p_t}
\end{split}$$
Therefore, if $p_t = 0$ then $x_t = 0$ and $i_t + x_t = i_t$. So the rate of interest of the risk bond will be equal to the nominal policy interest rate.
7. Calculate the probability of bankruptcy when the nominal interest rate for a risk borrower is $0.08(8\%)$ and the nominal policy interest rate is $0.03(3\%)$. **(5 points)**
Because $(1+i_t)=(1-p_t)(1+i_t+x_t) + 0*p_t$ then:
$$\begin{split}
(1 + 0.03) & = (1 - p_t)(1 + 0.08) \\
1.03 & = (1 - p_t)*1.08 \\
\frac{1.03}{1.08} & = 1 - p_t \\
p_t & = 1 - \frac{1.03}{1.08} \\
p_t & = 1-\frac{1.03}{1.08} \\
p_t & \approx 0.046
\end{split}$$
8. Calculate the nominal interest rate for a borrower when the probability of bankruptcy is $0.01$ and the nominal policy interest rate is $0.04(4\%)$. **(5 points)**
Because $(1+i_t)=(1-p_t)(1+i_t+x_t) + 0*p_t$ then:
$$\begin{split}
(1 + 0.04) & = (1 - 0.01)(1 + i_t + x_t) \\
\frac{1 + 0.04}{1-0.01} & = 1 + i_t + x_t \\
i_t + x_t & = \frac{1 + 0.04}{1 - 0.01} - 1 \\
i_t+x_t & = \frac{1.04}{0.99} - 1 \\
i_t+x_t & \approx 0.051 \; (5.1\%)
\end{split}$$
9. The formula assumes that payment upon default is zero. In fact, it is often positive. How would you change the formula in this case? **(5 points)**
If the payment upon default is positive then the formula would be:
$$(1+i_t)=(1-p_t)(1+i_t+x_t) + p_t*\alpha*(1+i_t+x_t)$$
Where $0 < \alpha <1$ because the borrower only pays a fraction. Therefore:
$$\begin{split}
(1+i_t) & = (1 + i_t + x_t)(1 - p_t + p_t*\alpha) \\
(1+i_t) & = (1+i_t+x_t)(1-p_t(1 - \alpha))
\end{split}$$
## Financial crisis of 2007–2008 in USA and IS-LM model
10. Explain **based on the extended IS-LM model**, using words and **attaching a plot**, how fiscal and monetary policy was used to mitigate the fall in real GDP during the financial crisis of 2007–2008 in USA. **(5 points)**
**Observation 1**: Be clear and precise in the explanation and please don’t include “bullshit” (Sorry for the last word but I did not find a better expression where I am using it in the sense indicated in **https://en.wikipedia.org/wiki/Bullshit**).
- The financial crisis of 2008 in the USA generated a shift of the **IS** curve to the left where equilibrium production went from $\widehat{Y}^*$ to $\widehat{Y}^{**}$ as shown in the plot below. To mitigate the effects of the crisis, the Obama administration used fiscal policy by cutting taxes, $\widehat{T}$, and increasing the public spending, $\widehat{G}$, causing the **IS** curve to shift to the right.
- In addition, from the point of view of monetary policy, the aim was to reduce the nominal intervention interest rate, $i$ and ,so that the real interest rate would decrease,$r$, moving the **LM** curve downward.
- Finally, the **Federal Reserve System (FED)** (central bank system of the USA) sought to reduce the risk premium, $x$, using an unconventional monetary policy that helped a greater shift of the IS curve to the right.
- These measures achieved that the equilibrium production was $\widehat{Y}^{***}$ mitigating the effects of the crisis, but they did not manage to return the economy to the initial level of production, $\widehat{Y}^{*}$.
```{r}
ggplot(data = tibble(x = c(0, 5, 2, 0.5, 1.5),
y = c(5, 0, 2, 2, 1.5))
) +
geom_point(aes(x = x, y = y),
color = "blue",
size = 3) +
geom_segment(aes(x = 0, y = 2,
xend = 4, yend = 2),
color = 'red') +
geom_segment(aes(x = 0, y = 1.5,
xend = 4, yend = 1.5),
color = 'red') +
geom_segment(aes(x = 0, y = 4,
xend = 4, yend = 0),
color = 'green') +
geom_segment(aes(x = 0, y = 2.5,
xend = 2.5, yend = 0),
color = 'green') +
geom_segment(aes(x = 0, y = 3,
xend = 3, yend = 0),
color = 'green') +
geom_segment(aes(x = 0, y = 0,
xend = 0, yend = 5)) +
geom_segment(aes(x = 0, y = 0,
xend = 5, yend = 0)) +
geom_segment(aes(x = 2, y = 2,
xend = 2, yend = 0),
linetype = 'dashed') +
geom_segment(aes(x = 0.5, y = 2,
xend = 0.5, yend = 0),
linetype = 'dashed') +
geom_segment(aes(x = 1.5, y = 1.5,
xend = 1.5, yend = 0),
linetype = 'dashed') +
geom_curve(aes(x = 0.5, y = 2,
xend = 1.5, yend = 1.5),
arrow = arrow(length = unit(0.03, "npc"))) +
geom_curve(aes(x = 2, y = 2,
xend = 0.5, yend = 2),
arrow = arrow(length = unit(0.03, "npc"))) +
annotate(geom = 'text',
x = 2.25, y = 0.25,
label = TeX('$\\widehat{Y}^*$')) +
annotate(geom = 'text',
x = 0.75, y = 0.25,
label = TeX('$\\widehat{Y}^{**}$')) +
annotate(geom = 'text',
x = 1.75, y = 0.25,
label = TeX('$\\widehat{Y}^{***}$')) +
annotate(geom = 'text',
x = 0.25, y = 2.25,
label = TeX('$\\bar{r}^*$')) +
annotate(geom = 'text',
x = 0.25, y = 1.75,
label = TeX('$\\bar{r}^{**}$')) +
annotate(geom = 'text',
x = 5.25, y = 0,
label = TeX('$\\widehat{Y}$')) +
annotate(geom = 'text',
x = 0, y = 5.25,
label = TeX('$r')) +
annotate(geom = 'text',
x = 4.25, y = 2,
label = TeX('$LM^*')) +
annotate(geom = 'text',
x = 4.25, y = 1.5,
label = TeX('$LM^{**}')) +
annotate(geom = 'text',
x = 4, y = 0.25,
label = TeX('$IS^*')) +
annotate(geom = 'text',
x = 2.5, y = 0.25,
label = TeX('$IS^{**}')) +
annotate(geom = 'text',
x = 3, y = 0.25,
label = TeX('$IS^{***}')) +
theme_void()
```