Una Serie de Tiempo es una coleccion de observaciones sobre un determinado fenómeno, efectuadas en momento sucesivos, usualmente equiespaciados.
Algunos ejemplos de series de tiempo son: 1. Precios de acciones 2. Niveles de inventario 3. Rotacion de Personal 4. Ventas 5. PIB (GDP)
Mas informacion: link
#install.packages("forecast")
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(readxl)
Ejemplo: Los siguientes de datos de producción trimestral inician en el primer trimestre de 2020. Se busca pronosticar la producción de los siguientes 5 trimestres
produccion <- c(50,53,55,57,55,60)
ts<-ts(produccion,start = c(2020,1),frequency = 4)
ts
## Qtr1 Qtr2 Qtr3 Qtr4
## 2020 50 53 55 57
## 2021 55 60
ARIMA significa AutoRegressive Integrated Moving Average o Modelo Autorregresivo Integrado de Promedio Movil
arima<-auto.arima(ts)
summary(arima)
## Series: ts
## ARIMA(0,1,0)
##
## sigma^2 = 9.2: log likelihood = -12.64
## AIC=27.29 AICc=28.62 BIC=26.89
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 1.675 2.76895 2.341667 2.933747 4.145868 0.3902778 -0.5152989
pronostico <- forecast(arima,level=c(95), h=5)
pronostico
## Point Forecast Lo 95 Hi 95
## 2021 Q3 60 54.05497 65.94503
## 2021 Q4 60 51.59246 68.40754
## 2022 Q1 60 49.70291 70.29709
## 2022 Q2 60 48.10995 71.89005
## 2022 Q3 60 46.70652 73.29348
plot(pronostico)
# Read the Excel file into a data frame
hershey <- read_excel("C:\\Users\\USER\\Documents\\Ventas_Históricas_Lechitas.xlsx")
## New names:
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...5`
## • `` -> `...6`
# Assuming 'hershey' is your data frame
# Store the second row as column names
new_colnames <- as.character(hershey[2, ])
# Remove the first two rows from the data frame
hershey <- hershey[-(1:2), ]
# Set the new column names
colnames(hershey) <- new_colnames
# Convert 'Ventas' column to numeric
hershey$Ventas <- as.numeric(hershey$Ventas)
ts1<-ts(hershey$Ventas,start =c(2017,1),frequency =12)
ts1
## Jan Feb Mar Apr May Jun Jul Aug
## 2017 25520.51 23740.11 26253.58 25868.43 27072.87 27150.50 27067.10 28145.25
## Sep Oct Nov Dec
## 2017 27546.29 28400.37 27441.98 27852.47
ARIMA significa AutoRegressive Integrated Moving Average o Modelo Autorregresivo Integrado de Promedio Movil
arima2<-auto.arima(ts1)
summary(arima2)
## Series: ts1
## ARIMA(1,1,0) with drift
##
## Coefficients:
## ar1 drift
## -0.8190 292.0193
## s.e. 0.1727 122.4233
##
## sigma^2 = 608019: log likelihood = -88.31
## AIC=182.62 AICc=186.05 BIC=183.81
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -65.80228 675.2882 575.9571 -0.2638862 2.179851 NaN 0.1402586
pronostico2 <- forecast(arima2,level=c(95), h=12)
pronostico2
## Point Forecast Lo 95 Hi 95
## Jan 2018 28047.46 26519.17 29575.75
## Feb 2018 28418.95 26865.83 29972.07
## Mar 2018 28645.88 26619.37 30672.40
## Apr 2018 28991.21 26912.67 31069.75
## May 2018 29239.57 26864.20 31614.93
## Jun 2018 29567.35 27120.63 32014.07
## Jul 2018 29830.08 27168.41 32491.75
## Aug 2018 30146.08 27401.37 32890.80
## Sep 2018 30418.46 27504.21 33332.71
## Oct 2018 30726.57 27723.23 33729.91
## Nov 2018 31005.41 27860.30 34150.52
## Dec 2018 31308.22 28071.73 34544.71
plot(pronostico2)
library(finreportr)
Con la función de finerportr podemos obtener la siguiente información
CompanyInfo() = Brinda información general como Nombre, Ubicación, ZIP, etc.
AnnualReports() = Brinda el nombre, fecha y número de acceso
GetIncome()= Brinda el Estado de Resultados.
GetBalanceSheet() = Brinda el Balance General
GetCashFlow() = Brinda el Flujo de Efectivo.
options(HTTPUserAgent = "a a@gmail.com")
CompanyInfo("JPM")
## company CIK SIC state state.inc FY.end street.address
## 1 JPMORGAN CHASE & CO 0000019617 6021 NY DE 1231 383 MADISON AVENUE
## city.state
## 1 NEW YORK NY 10017
AnnualReports("BABA",foreign=TRUE)
## filing.name filing.date accession.no
## 1 20-F/A 2024-02-23 0001193125-24-044480
## 2 20-F 2023-07-21 0000950170-23-033752
## 3 20-F 2022-07-26 0001104659-22-082622
## 4 20-F 2021-07-27 0001104659-21-096092
## 5 20-F 2020-07-09 0001104659-20-082409
## 6 20-F 2019-06-05 0001047469-19-003492
## 7 20-F 2018-07-27 0001047469-18-005257
## 8 20-F 2017-06-15 0001047469-17-004019
## 9 20-F 2016-05-24 0001047469-16-013400
## 10 20-F 2015-06-25 0001047469-15-005768
google_income<-GetIncome("GOOG",2016)
amazon_balance <- GetBalanceSheet("AMZN",2015)
apple_cash<-GetCashFlow("AAPL",2014)