A34-Aplicación del Filtro HP (Hodrick Prescott)
Carlos Felipe Belloso Castillo (BC23009)
library(readxl)
datos_PIB_trim_ESA <- read_excel("C:/Users/Karlla Castillo/Downloads/datos_PIB_trim_CA.xlsx",
range = "C7:c144",
col_types = c("numeric")
)
datos_PIB_trim_GUA <- read_excel("C:/Users/Karlla Castillo/Downloads/datos_PIB_trim_CA.xlsx",
range = "D51:d144",
col_types = c("numeric")
)
datos_PIB_trim_HON <- read_excel("C:/Users/Karlla Castillo/Downloads/datos_PIB_trim_CA.xlsx",
range = "E47:E144",
col_types = c("numeric")
)
datos_PIB_trim_NI <- read_excel("C:/Users/Karlla Castillo/Downloads/datos_PIB_trim_CA.xlsx",
range = "f71:f144",
col_types = c("numeric")
)
datos_PIB_trim_CR <- read_excel("C:/Users/Karlla Castillo/Downloads/datos_PIB_trim_CA.xlsx",
range = "B11:B144",
col_types = c("numeric")
)
datos_PIB_trim_PAN <- read_excel("C:/Users/Karlla Castillo/Downloads/datos_PIB_trim_CA.xlsx",
range = "H31:H137",
col_types = c("numeric")
)
datos_PIB_trim_RD <- read_excel("C:/Users/Karlla Castillo/Downloads/datos_PIB_trim_CA.xlsx",
range = "g11:g144",
col_types = c("numeric")
)El Salvador (1990 I - 2024 II)
implementación personalizada
library(mFilter)
library(forecast)
pib_ESA <- ts(datos_PIB_trim_ESA,
start = c(1990, 1),
frequency = 4)
# aplicando el filtro hp y escogiendo el valor de lambda de 1600 dado que es trimestral
hp_ESA <- hpfilter(pib_ESA, freq = 1600)
trend_ESA <- hp_ESA$trend
cycle_ESA <- hp_ESA$cycle
plot(pib_ESA, type = "l", main = "Filtro de Hodrick-Prescott - El Salvador 1990-2024", ylab = "PIB", xlab = "Tiempo")
lines(trend_ESA, col = "red", lwd = 2)
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)plot(cycle_ESA, type = "l", main = "Componente Ciclico, El Salvador", ylab = "Ciclo", xlab = "Tiempo")Guatemala (2001 I - 2024 II)
implementación personalizada
library(mFilter)
library(forecast)
pib_GUA <- ts(datos_PIB_trim_GUA,
start = c(2001, 1),
frequency = 4)
# aplicando el filtro hp y escogiendo el valor de lambda de 1600 dado que es trimestral
hp_GUA <- hpfilter(pib_GUA, freq = 1600)
trend_GUA <- hp_GUA$trend
cycle_GUA <- hp_GUA$cycle
plot(pib_GUA, type = "l", main = "Filtro de Hodrick-Prescott - Guatemala 2001-2024", ylab = "PIB", xlab = "Tiempo")
lines(trend_GUA, col = "red", lwd = 2)
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)plot(cycle_GUA, type = "l", main = "Componente Ciclico, Guatemala", ylab = "Ciclo", xlab = "Tiempo")Honduras (2000 I - 2024 II)
implementación personalizada
library(mFilter)
library(forecast)
pib_HON <- ts(datos_PIB_trim_HON,
start = c(2000, 1),
frequency = 4)
# aplicando el filtro hp y escogiendo el valor de lambda de 1600 dado que es trimestral
hp_HON <- hpfilter(pib_HON, freq = 1600)
trend_HON <- hp_HON$trend
cycle_HON <- hp_HON$cycle
plot(pib_HON, type = "l", main = "Filtro de Hodrick-Prescott - Honduras 2000-2024", ylab = "PIB", xlab = "Tiempo")
lines(trend_HON, col = "red", lwd = 2)
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)plot(cycle_HON, type = "l", main = "Componente Ciclico, Guatemala", ylab = "Ciclo", xlab = "Tiempo")
## Representación rápida.
Nicaragua (2006 I - 2024 II)
implementación personalizada
library(mFilter)
library(forecast)
pib_NI <- ts(datos_PIB_trim_NI,
start = c(2006, 1),
frequency = 4)
# aplicando el filtro hp y escogiendo el valor de lambda de 1600 dado que es trimestral
hp_NI <- hpfilter(pib_NI, freq = 1600)
trend_NI <- hp_NI$trend
cycle_NI <- hp_NI$cycle
plot(pib_NI, type = "l", main = "Filtro de Hodrick-Prescott - Nicaragua 2006-2024", ylab = "PIB", xlab = "Tiempo")
lines(trend_NI, col = "red", lwd = 2)
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)Costa Rica (1991 I - 2024 II)
implementación personalizada
library(mFilter)
library(forecast)
pib_CR <- ts(datos_PIB_trim_CR,
start = c(1991, 1),
frequency = 4)
# aplicando el filtro hp y escogiendo el valor de lambda de 1600 dado que es trimestral
hp_CR <- hpfilter(pib_CR, freq = 1600)
trend_CR <- hp_CR$trend
cycle_CR <- hp_CR$cycle
plot(pib_CR, type = "l", main = "Filtro de Hodrick-Prescott - Costa Rica 1991-2024", ylab = "PIB", xlab = "Tiempo")
lines(trend_CR, col = "red", lwd = 2)
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)plot(cycle_CR, type = "l", main = "Componente Ciclico, Costa Rica", ylab = "Ciclo", xlab = "Tiempo")Panamá ((1996 I - 2022 III))
implementación personalizada
library(mFilter)
library(forecast)
pib_PAN <- ts(datos_PIB_trim_PAN,
start = c(1996, 1),
frequency = 4)
# aplicando el filtro hp y escogiendo el valor de lambda de 1600 dado que es trimestral
hp_PAN <- hpfilter(pib_PAN, freq = 1600)
trend_PAN <- hp_PAN$trend
cycle_PAN <- hp_PAN$cycle
plot(pib_PAN, type = "l", main = "Filtro de Hodrick-Prescott - Panamá 1996 -2024", ylab = "PIB", xlab = "Tiempo")
lines(trend_PAN, col = "red", lwd = 2)
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)República Dominica (1991 I - 2024 II)
implementación personalizada
library(mFilter)
library(forecast)
pib_RD <- ts(datos_PIB_trim_RD,
start = c(1996, 1),
frequency = 4)
# aplicando el filtro hp y escogiendo el valor de lambda de 1600 dado que es trimestral
hp_RD <- hpfilter(pib_RD, freq = 1600)
trend_RD <- hp_RD$trend
cycle_RD <- hp_RD$cycle
plot(pib_RD, type = "l", main = "Filtro de Hodrick-Prescott - República Dominica 1996 -2024", ylab = "PIB", xlab = "Tiempo")
lines(trend_RD, col = "red", lwd = 2)
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)plot(cycle_RD, type = "l", main = "Componente Ciclico, República Dominica", ylab = "Ciclo", xlab = "Tiempo")