Augmented Dynamic Adaptive Model (ADAM) for daily seasonal data | R-Bloggers

Augmented Dynamic Adaptive Model (ADAM) for daily seasonal data | R-Bloggers

[This article was first published on DataGeeek, and kindly contributed to R-bloggers]. (You can report problems here about the content on this page)


Do you want to share your content on R-bloggers? Click here if you have a blog, or here If you don’t.

I have modeled the Bist 100 index to build predictive intervals. Because the data has daily seasonal, I preferred the Model Time :: Adam_reg function.

I have the Timetk :: step_timeseries_signature Function because the model cannot process too many external regressors and the algorithm naturally captures the trend and seasonal influences. So I did not work the data to keep it simple.

library(tidyverse)
library(tidyquant)
library(tidymodels)
library(timetk)
library(modeltime)

#BIST 100
df_bist <- 
  tq_get("XU100.IS") %>% 
  select(date, close)


#Splitting the Data 
splits <- 
  time_series_split(
    df_bist,
    assess     = "1 month",
    cumulative = TRUE
  )

df_train <- training(splits)
df_test <- testing(splits)


#Seasonality Diagnostic
arima_reg() %>% 
  set_engine("auto_arima") %>% 
  fit(close ~ date, df_train)


#Model
mod_adam <- 
  adam_reg() %>% 
  set_engine("auto_adam")

#Fitting
mod_fit <- 
  mod_adam %>% 
  fit(formula = close ~ date, data = df_train)

#Calibrate the model to the testing set
calibration_tbl <- 
  mod_fit %>%
  modeltime_calibrate(new_data = df_test)


#Accuracy of the finalized model
calibration_tbl %>%
  modeltime_accuracy(metric_set = metric_set(rmse, rsq, mape))



#Prediction Intervals
calibration_tbl %>% 
  modeltime_forecast(new_data = df_test, 
                     actual_data = df_test) %>%
  plot_modeltime_forecast(.interactive = FALSE,
                          .legend_show = FALSE,
                          .line_size = 1.5,
                          .color_lab = "",
                          .title = "BIST 100") +
  labs(subtitle = "Predictive Intervals of the Augmented Dynamic Adaptive Model") + 
  scale_y_continuous(labels = scales::label_currency(prefix = "₺", 
                                                     suffix = "")) +
  scale_x_date(labels = scales::label_date("%b %d"),
               date_breaks = "4 days") +
  theme_minimal(base_family = "Roboto Slab", base_size = 16) +
  theme(plot.subtitle = ggtext::element_markdown(face = "bold", size = 14),
        plot.title = element_text(face = "bold"),
        plot.background = element_rect(fill = "azure", color = "azure"),
        panel.background = element_rect(fill = "snow", color = "snow"),
        axis.text = element_text(face = "bold"),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1),
        legend.position = "none")


#Augmented #Dynamic #Adaptive #Model #ADAM #daily #seasonal #data #RBloggers

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *