Augmented Dynamic Adaptive Model (ADAM) for Daily Seasonal Data

I have modeled the BIST 100 index to build predictive intervals. Because the data has daily seasonality, I preferred the modeltime::adam_reg function.

I did not use the timetk::step_timeseries_signature function because the model cannot process too many exterior regressors, and the algorithm captures the trend and seasonality well by nature. So I did not preprocess 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 = "<span style = 'color:dimgrey;'>Predictive Intervals</span> of the <span style = 'color:red;'>Augmented Dynamic Adaptive Model</span>") + 
  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")

5 responses to “Augmented Dynamic Adaptive Model (ADAM) for Daily Seasonal Data”

  1. lupaz Avatar
    lupaz

    Hi, thank you, I had trouble getting this to run and plot until (1) installed package smooth, and then (2) installed package showtext and installed Roboto Slab font. Now it runs, but I don’t yet understand what the output actually represents. What is the “predictive interval”? I ran this with data for the SPY ETF, and it generates a plot that looks roughly like the actual SPY closing prices. But what does it mean? What “interval” does it show? I was expecting forecasting code to generate a plot perhaps of (a) the predicted values (or perhaps an interval), along with the actual data. Could you show us how one might predict the next day’s closing price, and compare it to the actual closing price? Thank you again.

    Like

    1. Selcuk Disci Avatar

      I use predictive intervals to determine the overbought and oversold zones, similar to the RSI(Relative Strength Index).

      Like

  2. lupaz Avatar
    lupaz

    Sounds good, but… I don’t see an interval (a low value and a high value) anywhere, just a single value plotted. A valuable plot here to demonstrate its utility would be (1) daily close values of SPY, or BIST 100 along with (2) dashed lines showing the upper and lower bounds from the predictive interval. How are those values derived from this ADAM model? Thank you again for trying to introduce us to this method.

    Like

    1. Selcuk Disci Avatar

      Please look at the grey area, which is indicated in the plot title as colorful writing.

      Like

  3. lupaz Avatar
    lupaz

    Oh, thank you. It was difficult for me to see the grey area as anything but background, since it trends so little in the plot. When I run SPY there shows a slightly higher amount of trend upward, and I missed seeing the gray area as an interval when I first ran it. Now I have to study the code more to try and experiment to understand better what is actually going on here. Thank you for your patience with me.

    Liked by 1 person

Leave a reply to Selcuk Disci Cancel reply

I’m Selcuk Disci

Welcome to DataGeeek.com, dedicated to data science and machine learning with R, mostly based on financial data.

Let’s connect