## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = FALSE
)

## -----------------------------------------------------------------------------
# library(rollcast)
# 
# set.seed(1)
# y <- 100 + cumsum(rnorm(300, mean = 0.03, sd = 0.8))
# 
# fit <- rollcast(
#   y,
#   window = 60,
#   tau = 0.25,
#   lambda = 0.01,
#   conditional_k = 40,
#   state_bw = 1,
#   residual_bw = 0.35,
#   error_scale = 0.25,
#   residual_smoothing = 0.03,
#   rho_min = 0.05,
#   rho_max = 0.90,
#   rho_decay = 1
# )
# 
# fit

## -----------------------------------------------------------------------------
# sort(fit$current$probabilities, decreasing = TRUE)

## -----------------------------------------------------------------------------
# pred <- predict(
#   fit,
#   horizon = 20,
#   nsim = 3000,
#   seed = 123
# )
# 
# head(pred$summary)

## -----------------------------------------------------------------------------
# pred$dfun(100, h = 1)
# pred$pfun(100, h = 1)
# pred$qfun(c(0.05, 0.50, 0.95), h = 1)
# pred$rfun(5, h = 1)

## -----------------------------------------------------------------------------
# paths <- pred$rfun(100)
# dim(paths)

## -----------------------------------------------------------------------------
# fixed <- rollcast(
#   y,
#   window = 60,
#   tau = 0.25,
#   lambda = 0.01,
#   conditional_k = 40,
#   state_bw = 1,
#   residual_bw = 0.35,
#   error_scale = 0.25,
#   residual_smoothing = 0.03,
#   rho_min = 0.05,
#   rho_max = 0.90,
#   rho_decay = 1
# )

## -----------------------------------------------------------------------------
# tuned <- rollcast(
#   y,
#   window = c(40, 60, 90),
#   tau = c(0.15, 0.25, 0.40),
#   lambda = c(0.001, 0.01, 0.05),
#   conditional_k = 40,
#   state_bw = 1,
#   residual_bw = c(0.20, 0.35, 0.55),
#   error_scale = c(0, 0.25, 0.50),
#   residual_smoothing = 0.03,
#   rho_min = 0.05,
#   rho_max = 0.90,
#   rho_decay = 1,
#   verbose = TRUE
# )
# 
# tuned$hyperparameter_search

## -----------------------------------------------------------------------------
# anchor_only <- rollcast(
#   y,
#   window = 60,
#   tau = 0.25,
#   lambda = 0.01,
#   conditional_k = 40,
#   state_bw = 1,
#   residual_bw = 0.35,
#   error_scale = 0,
#   residual_smoothing = 0.03,
#   rho_min = 0.05,
#   rho_max = 0.90,
#   rho_decay = 1
# )

## -----------------------------------------------------------------------------
# plot(pred)

## -----------------------------------------------------------------------------
# plot(pred, type = "fan")

