get_models()
recursively estimates time-series models by using rolling and expanding time windows.
get_models(.tbl, .group, .col, .initial, .assess, .cumulative, .fun, ...) # S3 method for default get_models(.tbl, .group, .col, .initial, .assess, .cumulative, .fun, ...) # S3 method for tbl_df get_models(.tbl, .group, .col, .initial, .assess, .cumulative, .fun, ...)
.tbl | A tidy |
---|---|
.group | The column in which the data should be grouped. This will often be a column with stock tickers or stocks names. |
.col | The reference column in which the operations should be based on. |
.initial | The number of periods used to train the model in each split. |
.assess | The forecast horizon. |
.cumulative | If |
.fun | Currently supports only a forecasting function from the |
... | Additional parameters to be passed to |
A tidy tibble
contaning the following in-sample statistics for each period:
term: The parameters estimated by .fun
estimate: The values of the estimated parameters
model.desc: A description of the model including the three integer components (p, d, q) are the AR order, the degree of differencing, and the MA order.
sigma: The square root of the estimated residual variance
logLik: The data's log-likelihood under the model
AIC: The Akaike Information Criterion
BIC: The Bayesian Information Criterion
ME: Mean error
RMSE: Root mean squared error
MAE: Mean absolute error
MPE: Mean percentage error
MAPE: Mean absolute percentage error
MASE: Mean absolute scaled error
ACF1: Autocorrelation of errors at lag 1
Under the hood, get_forecasts uses rsample
infrastructure to sequentially access the model passed to .fun
. The data y1, y2, ..., yt is fitted and the process repeats itself for each stock in the .group
column.
library(YahooTickers) library(dplyr) library(forecast) # Download and forecast time series using the "auto.arima" function # from the forecast package get_tickers(dow) %>% slice(1:2) %>% get_stocks(., periodicity = "monthly") %>% get_returns(., tickers, arithmetic, TRUE, ret_adj = adjusted) %>% get_models(., tickers, ret_adj, 60, 1, FALSE, auto.arima, seasonal = FALSE, stationary = TRUE, max.p = 1, max.q = 1) #> # A tibble: 176 × 17 #> date tickers data term estimate model.desc sigma logLik AIC BIC #> <date> <fct> <list> <fct> <dbl> <fct> <dbl> <dbl> <dbl> <dbl> #> 1 2015-02-01 MMM <tibb… ar1 -0.217 ARIMA(1,0… 0.0489 97.0 -188. -182. #> 2 2015-02-01 MMM <tibb… inte… 0.0152 ARIMA(1,0… 0.0489 97.0 -188. -182. #> 3 2015-03-01 MMM <tibb… ar1 -0.218 ARIMA(1,0… 0.0489 96.9 -188. -182. #> 4 2015-03-01 MMM <tibb… inte… 0.0156 ARIMA(1,0… 0.0489 96.9 -188. -182. #> 5 2015-04-01 MMM <tibb… ar1 -0.236 ARIMA(1,0… 0.0487 97.2 -188. -182. #> 6 2015-04-01 MMM <tibb… inte… 0.0147 ARIMA(1,0… 0.0487 97.2 -188. -182. #> 7 2015-05-01 MMM <tibb… inte… 0.0128 ARIMA(0,0… 0.0500 95.1 -186. -182. #> 8 2015-06-01 MMM <tibb… ar1 -0.209 ARIMA(1,0… 0.0469 99.5 -193. -187. #> 9 2015-06-01 MMM <tibb… inte… 0.0149 ARIMA(1,0… 0.0469 99.5 -193. -187. #> 10 2015-07-01 MMM <tibb… ar1 -0.211 ARIMA(1,0… 0.0471 99.2 -192. -186. #> # … with 166 more rows, and 7 more variables: ME <dbl>, RMSE <dbl>, MAE <dbl>, #> # MPE <dbl>, MAPE <dbl>, MASE <dbl>, ACF1 <dbl>