---
title: "Análisis de la tasa de cambio VES/USD en Venezuela 2024-2025"
subtitle: "Histórico Paginado | Gráfico Interactivo | Depreciación"
author: "Arnaldo Di Remigio 27988203"
date: today
date-format: "DD/MM/YYYY"
format:
html:
theme: cosmo
toc: true
code-fold: true
code-tools: true
embed-resources: true
self-contained: true
editor: visual
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
```{r}
library(dplyr)
library(readr)
library(lubridate)
library(ggplot2)
library(plotly)
library(gt)
library(reactable)
library(scales)
```
```{r}
# --- CARGA DE DATOS ---
dfdolar <- read_csv("historico_dolar.csv", locale = locale(encoding = "UTF-8"))
if (nrow(dfdolar) == 0) stop("No se encontró 'historico_dolar.csv'. Colócalo en la misma carpeta.")
```
```{r}
locale_vzla <- locale(decimal_mark = ".", grouping_mark = ",")
dfdolar_limpio <- dfdolar %>%
rename_with(~ "Fecha..Date.", .cols = contains("fecha", ignore.case = TRUE) | starts_with("Fecha")) %>%
mutate(
Fecha_Date = parse_date_time(`Fecha..Date.`, orders = c("dmy", "dmY", "d/m/Y"), locale = "es") %>% as.Date(),
BCV_Num = parse_number(as.character(BCV), locale = locale_vzla),
Paralelo_Num = parse_number(as.character(Paralelo), locale = locale_vzla)
) %>%
filter(!is.na(Fecha_Date), !is.na(BCV_Num), !is.na(Paralelo_Num)) %>%
arrange(Fecha_Date) %>%
distinct(Fecha_Date, .keep_all = TRUE) %>%
mutate(
Promedio = round((BCV_Num + Paralelo_Num) / 2, 2),
Brecha_Pct = round(((Paralelo_Num - BCV_Num) / BCV_Num) * 100, 2)
)
```
```{r}
fechas_clave <- as.Date(c("2023-01-01", "2024-01-01", "2025-01-01", "2025-10-25"))
datos_clave <- dfdolar_limpio %>%
filter(Fecha_Date %in% fechas_clave) %>%
select(Fecha_Date, BCV_Num, Paralelo_Num)
if (!fechas_clave[4] %in% datos_clave$Fecha_Date) {
ultima <- dfdolar_limpio %>% slice_max(Fecha_Date, n = 1)
datos_clave <- bind_rows(datos_clave, ultima %>% select(Fecha_Date, BCV_Num, Paralelo_Num)) %>% arrange(Fecha_Date)
}
```
```{r}
depreciacion_anual <- datos_clave %>%
mutate(
BCV_Anterior = lag(BCV_Num),
Paralelo_Anterior = lag(Paralelo_Num),
Fecha_Anterior = lag(Fecha_Date)
) %>%
filter(!is.na(BCV_Anterior)) %>%
mutate(
Periodo = paste(format(Fecha_Anterior, "%d/%m/%Y"), "→", format(Fecha_Date, "%d/%m/%Y")),
Depreciacion_BCV = round(((BCV_Num - BCV_Anterior) / BCV_Anterior) * 100, 2),
Depreciacion_Paralelo = round(((Paralelo_Num - Paralelo_Anterior) / Paralelo_Anterior) * 100, 2)
) %>%
select(Periodo, Depreciacion_BCV, Depreciacion_Paralelo)
```
```{r}
cambio_mensual <- dfdolar_limpio %>%
mutate(Year = year(Fecha_Date), Month = month(Fecha_Date, label = TRUE, abbr = FALSE)) %>%
group_by(Year, Month) %>%
summarise(
BCV_Inicio = first(BCV_Num),
BCV_Fin = last(BCV_Num),
Paralelo_Inicio = first(Paralelo_Num),
Paralelo_Fin = last(Paralelo_Num),
.groups = 'drop'
) %>%
mutate(
Cambio_Pct_Paralelo = round(((Paralelo_Fin - Paralelo_Inicio) / Paralelo_Inicio) * 100, 2),
Mes_Año = paste(Month, Year)
) %>%
arrange(desc(Cambio_Pct_Paralelo))
```
### Evolución de la tasa de cambio 2023 - 2025
```{r}
reactable(
dfdolar_limpio %>%
select(Fecha_Date, BCV = BCV_Num, Paralelo = Paralelo_Num, Promedio, Brecha_Pct),
searchable = TRUE,
striped = TRUE,
highlight = TRUE,
bordered = TRUE,
defaultPageSize = 15,
showPageSizeOptions = TRUE,
pageSizeOptions = c(10, 15, 25, 50, 100),
defaultColDef = colDef(
headerStyle = list(fontWeight = "bold", background = "#f0f0f0"),
align = "center",
format = colFormat(separators = TRUE, digits = 2)
),
columns = list(
Fecha_Date = colDef(name = "Fecha", format = colFormat(date = TRUE, locales = "es-VE")),
BCV = colDef(name = "BCV"),
Paralelo = colDef(name = "Paralelo"),
Promedio = colDef(name = "Promedio"),
Brecha_Pct = colDef(
name = "Brecha (%)",
cell = JS("
")
)
),
theme = reactableTheme(
searchInputStyle = list(width = "100%", marginBottom = "10px"),
headerStyle = list(fontSize = "14px")
)
)
```
### Grafico: Evolución de la tasa de cambio 2023 - 2025
```{r}
g <- ggplot(dfdolar_limpio, aes(x = Fecha_Date)) +
geom_line(aes(y = BCV_Num, color = "BCV (Oficial)"), size = 1.2) +
geom_line(aes(y = Paralelo_Num, color = "Paralelo"), size = 1.5) +
geom_line(aes(y = Promedio, color = "Promedio"), size = 1, linetype = "dotted") +
scale_color_manual(values = c("BCV (Oficial)" = "#1f77b4", "Paralelo" = "#d62728", "Promedio" = "#2ca02c")) +
scale_y_continuous(labels = comma_format(big.mark = ".", decimal.mark = ",")) +
labs(x = "Fecha", y = "Tasa (Bs/USD)", color = "Tipo") +
theme_minimal(base_size = 14) +
theme(
plot.title = element_text(face = "bold", size = 18),
legend.position = "top",
axis.title = element_text(face = "bold")
)
ggplotly(g, tooltip = c("x", "y")) %>%
layout(hovermode = "x unified", legend = list(orientation = "h", x = 0.1, y = 1.1)) %>%
config(displayModeBar = TRUE, displaylogo = FALSE, modeBarButtonsToRemove = c("select2d", "lasso2d"))
```
### % de depreciación anual
```{r}
depreciacion_anual %>%
gt() %>%
tab_header("Depreciación del Bolívar", "Cambio % entre 1° de enero") %>%
cols_label(Periodo = "Período", Depreciacion_BCV = "BCV (%)", Depreciacion_Paralelo = "Paralelo (%)") %>%
fmt_number(columns = everything(), decimals = 2, suffixing = TRUE) %>%
data_color(columns = starts_with("Depreciacion"), colors = col_numeric("Reds", domain = NULL))
```
### Meses con mayor depreciación
```{r}
cambio_mensual %>%
slice_head(n = 10) %>%
select(Mes_Año, Cambio_Pct_Paralelo) %>%
gt() %>%
tab_header("Top 10 Meses con Mayor Devaluación", "Tasa Paralelo") %>%
cols_label(Mes_Año = "Mes", Cambio_Pct_Paralelo = "Devaluación (%)") %>%
fmt_number(columns = Cambio_Pct_Paralelo, decimals = 2, suffixing = TRUE) %>%
data_color(columns = Cambio_Pct_Paralelo, colors = col_numeric(c("#ffccbc", "#b71c1c"), domain = NULL))
```