library(fable, fabletools, fable.prophet)
ddsmp <- na.omit(dsmp) |>
(function(df) df |>
dplyr::mutate(
sq = 1:n(),
date = as_date(index),
quarter = quarter(index),
month = month(index),
wkdays = weekdays(index),
wk_1m = rep(1:7200, nrow(df)/7200),
dy_1m = rep(1:1440, nrow(df)/1440),
hr_1m = rep(1:60, nrow(df)/60)) |>
dplyr::select(index, year, quarter, month,
week, wkdays, wk_1m, dy_1m, hr_1m,
sq, date, close) |>
as_tsibble(index = index)
)()
✓ 1.2 GiB [master*]> timeID <- unique(ddsmp$date)
✓ 1.2 GiB [master*]> bse <- ddsmp[ddsmp$year == 2016,]$date[1] #"2016-01-04" #1st trading date in 2nd year
✓ 1.2 GiB [master*]> timeID %<>% .[. >= bse]
✓ 1.2 GiB [master*]> #timeID %<>% .[. >= as_date('2016-01-04')]
✓ 1.2 GiB [master*]> vrb <- 1200 #1200 observations
✓ 1.2 GiB [master*]> frb <- 1
✓ 1.2 GiB [master*]> i <- 1
✓ 1.2 GiB [master*]>
✓ 1.2 GiB [master*]> train <- ddsmp |>
(function(df)
filter(df, date < timeID[i]) |>
tail(vrb))()
✓ 1.2 GiB [master*]>
✓ 1.2 GiB [master*]> train <- train |>
as_tsibble(key = c(close, quarter, month, week, wkdays), index = index)
✓ 1.2 GiB [master*]>
✓ 1.2 GiB [master*]> fit <- train |>
model(
ets = ETS(close),
#ets_bc = ETS(box_cox(close, 0.3)),
arima = ARIMA(close),
rw = RW(close),
rw_df = RW(close ~ drift()),
naive = NAIVE(close),
snaive = SNAIVE(close))
Warning: Seasonal periods (`period`) of length greather than 24 are not supported by ETS. Seasonality will be ignored.
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
is.na() applied to non-(list or vector) of type 'closure'
Warning: 2 errors (1 unique) encountered for ets
[2] invalid 'type' (closure) of argument
Warning: 2 errors (1 unique) encountered for arima
[2] object is not a matrix
Warning: 2 errors (1 unique) encountered for rw
[2] object is not a matrix
Warning: 2 errors (1 unique) encountered for rw_df
[2] object is not a matrix
Warning: 2 errors (1 unique) encountered for naive
[2] object is not a matrix
Warning: 2 errors (1 unique) encountered for snaive
[2] object is not a matrix
✓ 1.2 GiB [master*]>
✓ 1.2 GiB [master*]> fc <- fit |>
fabletools::forecast(h = frb)
New names:
* close -> close...1
* close -> close...8
Error: Can't subset columns that don't exist.
x Column `close` doesn't exist.
Run `rlang::last_error()` to see where the error occurred.
x 1.2 GiB [master*]> fc <- fit |>
forecast(h = frb)
New names:
* close -> close...1
* close -> close...8
Error: Can't subset columns that don't exist.
x Column `close` doesn't exist.
Run `rlang::last_error()` to see where the error occurred.
x 1.2 GiB [master*]>
x 1.2 GiB [master*]> ## accuracy
x 1.2 GiB [master*]> fc |> fabletools::accuracy(train)
Error in fabletools::accuracy(fc, train) : object 'fc' not found
fable, fabletools, fable.prophet
这程序包。