[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.

Goldman Sachs stated that if the FED’s reputation suffers, and investors move only a small portion of their bond holdings into gold, the price of gold could rise to nearly $5,000 an ounce.

But at least now, the ensemble model indicates that gold prices are in an overbought zone.

Source code:

library(tidymodels)
library(tidyverse)
library(modeltime)
library(modeltime.ensemble)
library(timetk)

#Gold Futures
df_gold <-
  tq_get("GC=F") %>%
  select(date, close) %>%
  drop_na()


#Splitting
splits <-
  time_series_split(df_gold,
                    assess = "30 days",
                    cumulative = TRUE)

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

#Recipe
rec_spec <-
  recipe(close ~ ., data = df_train) %>%
  step_timeseries_signature(date) %>%
  step_fourier(date, period = 365, K = 5) %>%
  step_dummy(all_nominal_predictors(), one_hot = TRUE) %>%
  step_zv(all_predictors()) %>%
  step_normalize(all_numeric_predictors())


#Model 1 - Auto ARIMA
mod_spec_arima <-
  arima_reg() %>%
  set_engine("auto_arima")

wflw_fit_arima <-
  workflow() %>%
  add_model(mod_spec_arima) %>%
  add_recipe(rec_spec %>% step_rm(all_predictors(), -date)) %>%
  fit(df_train)

#Model 2 - Prophet
mod_spec_prophet <-
  prophet_reg() %>%
  set_engine("prophet")

wflw_fit_prophet <-
  workflow() %>%
  add_model(mod_spec_prophet) %>%
  add_recipe(rec_spec) %>%
  fit(df_train)

#Model 3: Boosted ARIMA
mod_arima_boosted <-
  arima_boost(
    min_n = 2,
    learn_rate = 0.015
  ) %>%
  set_engine(engine = "auto_arima_xgboost")

wflw_fit_arima_boost <-
  workflow() %>%
  add_model(mod_arima_boosted) %>%
  add_recipe(rec_spec) %>%
  fit(df_train)

#Modeltime Workflow for Ensemble Forecasting
df_models <-
  modeltime_table(
    wflw_fit_arima,
    wflw_fit_prophet,
    wflw_fit_arima_boost
  )


#Make an Ensemble
ensemble_fit <-
  df_models %>%
  ensemble_average(type = "mean")

#Calibration
calibration_tbl <-
  modeltime_table(
    ensemble_fit
  ) %>%
  modeltime_calibrate(df_test)


#Accuracy
calibration_tbl %>%
  modeltime_accuracy() %>%
  table_modeltime_accuracy(
    .interactive = TRUE
  )


#Predictive intervals
calibration_tbl %>%
  modeltime_forecast(actual_data = df_test,
                     new_data = df_test) %>%
  plot_modeltime_forecast(.interactive = FALSE,
                          .legend_show = FALSE,
                          .line_size = 1.5,
                          .color_lab = "",
                          .title = "Gold Futures") +
  labs(subtitle = "<span style = 'color:dimgrey;'>Predictive Intervals</span> of the <span style = 'color:red;'>Ensemble Model</span>") +
  scale_y_continuous(labels = scales::label_currency()) +
  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"),
        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.

Continue reading: Ensemble Model for Gold Futures

Analyzing Goldman Sachs Statement on Gold Prices

In a recent statement, Goldman Sachs mentioned that the price of gold could surge to nearly ,000 an ounce if there’s a small shift of investors’ bond holdings into gold due to a damaged reputation of the FED. While the ensemble model indicates that gold prices are currently overbought, there’s potential for significant long-term implications and future developments. In this light, let’s analyze these potential impacts.

Long-term Implications and Future Developments

Gold Prices

Should investors orchestrate a small shift from their bond holdings into gold due to FED’s hampered reputation, it could lead to a significant surge in gold prices as forecasted by Goldman Sachs. Current ensemble models may indicate an overbought zone, yet this can change as the situation develops. This could offer potentially lucrative opportunities for investors looking to capitalize on the predicted increment in gold prices.

Financial Markets

Furthermore, this shift could have long-term impacts on the global financial markets. With more investors moving their bond holdings into gold, the demand for bonds may decrease, potentially leading to an increase in bond yields and a dip in bond prices. This could impact the broader financial markets, affecting governments, corporations, and other entities that rely on bond markets for funding.

Actionable Advice

Following this trend and future implications, here is some practical advice:

  1. Monitor Market Conditions: Regularly observe and analyze gold prices and bond yields. This can assist in predicting market movements and making informed investment decisions.
  2. Consider Diversification: Diversify your investment portfolio to include both bonds and gold. This strategy could help balance out any potential losses that may come from holding bonds, with the predicted gains from the increased value of gold.
  3. Utilize Financial Models: Use ensemble models to analyze potential future movements in the gold and bond markets. Such models can be instrumental in forecasting market conditions, helping to inform investment decisions.
  4. Stay Informed: Keep abreast with financial news from reliable sources. Closely follow what financial institutions like Goldman Sachs say as they often have valuable insights into potential market movements.

In conclusion, while the future developments of gold prices depend on numerous volatile variables, it is crucial to stay informed and prepared for any possible shifts in the market. Leveraging ensemble forecasting models can also provide valuable predictive information to navigate the financial marketplace with greater confidence.

Read the original article