Augmented Dynamic Adaptive Model (ADAM) for Daily Seasonal Data
[This article was first published on DataGeeek, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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 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")

To leave a comment for the author, please follow the link and comment on their blog: DataGeeek.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.