rm(list=ls())
library (readxl)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
setwd("C:/Users/aguil/OneDrive/Documents/PRONOSTICOS_FINANCIEROS")
netflix <- read_excel("netflix_ventas.xlsx")
walmart <- read_excel("walmart_ventas.xlsx")
cocacola <- read_excel ("cocacola_ventas.xlsx")
Generamos la serie de tiempo
netflix <- ts(netflix$ventas, start = c(2019,1), frequency = 1)
walmart <- ts(walmart$ventas, start = c(2014,1), frequency = 1)
cocacola <- ts(cocacola$ventas, start = c(2016,1), frequency = 1)
Graficamos Netflix
autoplot(netflix)+
ggtitle("Serie de tiempo de Netflix")
Graficamos Walmart
autoplot(walmart)+
ggtitle("Serie de tiempo de Walmart")
Graficamos Coca cola
autoplot(cocacola)+
ggtitle("Serie de tiempo de Coca cola")
Ahora vamos a pronosticar con el metodo holt amortiguado a las 3 empresas en sus proximas ventas de los siguientes 3 años
pronosticos_netflix_ha <- holt(netflix, h=3, damped = TRUE)
## Warning in ets(x, "AAN", alpha = alpha, beta = beta, phi = phi, damped =
## damped, : Not enough data to use damping
summary(pronosticos_netflix_ha)
##
## Forecast method: Damped Holt's method
##
## Model Information:
## Damped Holt's method
##
## Call:
## holt(y = netflix, h = 3, damped = TRUE)
##
## Smoothing parameters:
## alpha = 0.3599
## beta = 1
##
## Initial states:
## l = 20156
## b = 4840
##
## sigma: 2601.738
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -1591.85 2601.738 2081.481 -6.926427 8.575129 0.695566 0.09904217
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2024 35790.08 32455.82 39124.34 30690.77 40889.39
## 2025 37765.42 32137.16 43393.68 29157.74 46373.10
## 2026 39740.76 30066.48 49415.05 24945.22 54536.30
autoplot(pronosticos_netflix_ha)
ggtitle("Grafica de pronostico de Netflix")
## $title
## [1] "Grafica de pronostico de Netflix"
##
## attr(,"class")
## [1] "labels"
pronosticos_walmart_ha <- holt(walmart, h=3, damped = TRUE)
summary(pronosticos_walmart_ha)
##
## Forecast method: Damped Holt's method
##
## Model Information:
## Damped Holt's method
##
## Call:
## holt(y = walmart, h = 3, damped = TRUE)
##
## Smoothing parameters:
## alpha = 1e-04
## beta = 1e-04
## phi = 0.98
##
## Initial states:
## l = -10705.0427
## b = 6940.6339
##
## sigma: 18843.5
##
## AIC AICc BIC
## 224.9728 252.9728 226.7884
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -486.7837 13324.37 9982.536 3.523397 50.46309 1.12239 -0.04582585
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2024 57056.74 32907.82 81205.65 20124.16 93989.32
## 2025 62502.39 38353.47 86651.31 25569.81 99434.97
## 2026 67839.11 43690.19 91988.03 30906.52 104771.69
autoplot(pronosticos_walmart_ha)
ggtitle("Grafica de pronostico de Walmart")
## $title
## [1] "Grafica de pronostico de Walmart"
##
## attr(,"class")
## [1] "labels"
pronosticos_cocacola_ha <- holt(cocacola, h=3, damped = TRUE)
## Warning in ets(x, "AAN", alpha = alpha, beta = beta, phi = phi, damped =
## damped, : Not enough data to use damping
summary(pronosticos_cocacola_ha)
##
## Forecast method: Damped Holt's method
##
## Model Information:
## Damped Holt's method
##
## Call:
## holt(y = cocacola, h = 3, damped = TRUE)
##
## Smoothing parameters:
## alpha = 0.3801
## beta = 1
##
## Initial states:
## l = 8831
## b = 2862
##
## sigma: 17047.97
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 6551.708 17047.97 8065.101 7.448459 18.99857 0.7358668 -0.0966162
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2024 78743.12 56895.27 100591.0 45329.72 112156.5
## 2025 101530.15 64293.75 138766.6 44581.98 158478.3
## 2026 124317.18 60358.84 188275.5 26501.34 222133.0
autoplot(pronosticos_cocacola_ha)
ggtitle("Grafica de pronostico de Coca cola")
## $title
## [1] "Grafica de pronostico de Coca cola"
##
## attr(,"class")
## [1] "labels"
Grafica comparativa
autoplot(pronosticos_netflix_ha, PI=FALSE)+
autolayer(pronosticos_walmart_ha, PI=FALSE)+
autolayer(pronosticos_cocacola_ha, PI=FALSE)+
coord_cartesian( xlim=c(2022,2026) )