- Solve real problems with our hands-on interface
- Progress from basic puts and calls to advanced strategies

Posted May 28, 2026 at 3:50 pm
The article “Global Modeling with XGBoost: Gold vs. Silver” was originally published on DataGeeek.
China aims to increase its influence in the global bullion market by directing friendly countries to store their gold reserves within its borders. This move is part of Beijing’s efforts to reduce its reliance on the dollar and promote the global use of the yuan.
Goldman Sachs predicts that if just 1% of corporate bonds shift to gold, prices could rise to $5,000.
Source code for Global Modeling with XGBoost: Gold vs. Silver:
library(tidymodels)
library(tidyverse)
library(tidyquant)
library(timetk)
library(modeltime)
#Gold Futures (GC=F)
df_gold <-
tq_get("GC=F") %>%
select(date, gold = close)
#Silver Futures (SI=F)
df_silver <-
tq_get("SI=F") %>%
select(date, silver = close)
#Creating the survey data
df_survey <-
df_gold %>%
left_join(df_silver) %>%
pivot_longer(-date,
names_to = "id",
values_to = "value") %>%
mutate(id = toupper(id)) %>%
filter(date >= last(date) - months(36)) %>%
drop_na()
#Train/Test Splitting
splits <-
df_survey %>%
time_series_split(assess = "15 days",
cumulative = TRUE)
#Recipe
#The step_normalize() function is breaking the decision splits.
#Reducing the model's accuracy led to its removal.
rec_spec <-
recipe(value ~ ., training(splits)) %>%
step_string2factor("id") %>%
step_mutate_at(id, fn = droplevels) %>%
step_timeseries_signature(date) %>%
step_rm(date) %>%
step_dummy(all_nominal_predictors(), one_hot = TRUE) %>%
step_zv(all_predictors()) %>%
step_corr(all_predictors())
#Preprocessed data variables
rec_spec %>%
prep() %>%
bake(new_data = NULL) %>%
glimpse()
#Workflow fit
wflw_fit <-
workflow() %>%
add_model(
boost_tree("regression") %>%
set_engine("xgboost")
) %>%
add_recipe(rec_spec) %>%
fit(training(splits))
#Create a Modeltime Table
model_tbl <-
modeltime_table(wflw_fit)
#Calibrating by ID
calib_tbl <-
model_tbl %>%
modeltime_calibrate(
new_data = testing(splits),
id = "id"
)
#Measuring Test Accuracy
#Global Accuracy
calib_tbl %>%
modeltime_accuracy(acc_by_id = FALSE) %>%
table_modeltime_accuracy(.interactive = FALSE)
#Local Accuracy
calib_tbl %>%
modeltime_accuracy(acc_by_id = TRUE) %>%
table_modeltime_accuracy(.interactive = TRUE)
#Prediction intervals were used similarly to the Relative Strength Index (RSI).
calib_tbl %>%
modeltime_forecast(
new_data = testing(splits),
actual_data = testing(splits),
conf_by_id = TRUE) %>%
group_by(id) %>%
plot_modeltime_forecast(
.facet_ncol = 1,
.interactive = FALSE,
.line_size = 1.5
) +
labs(title = "Global Modeling with XGBoost",
subtitle = "<span style = 'color:dimgrey;'>Predictive Intervals</span> of <span style = 'color:red;'>XGBoost</span>",
y = "", x = "") +
scale_y_continuous(labels = scales::label_currency()) +
scale_x_date(labels = scales::label_date("%b %d"),
date_breaks = "4 days") +
theme_tq(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 = "snow"),
strip.text = element_text(face = "bold", color = "black"),
strip.background = element_rect(fill = "azure"),
axis.text= element_text(face = "bold"),
legend.position = "none")Visit DataGeeek for additional insights on this topic.
Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.
This material is from DataGeeek and is being posted with its permission. The views expressed in this material are solely those of the author and/or DataGeeek and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.
Please keep in mind that the examples discussed in this material are purely for technical demonstration purposes, and do not constitute trading advice. Also, it is important to remember that placing trades in a paper account is recommended before any live trading.
Futures are not suitable for all investors. The amount you may lose may be greater than your initial investment. Before trading futures, please read the CFTC Risk Disclosure. A copy and additional information are available at ibkr.com.
Investments in certain commodities (precious metals) may be subject to significant price volatility and often involve risks related to market fluctuations, liquidity constraints, geopolitical events, and changes in global economic conditions that could adversely affect their value.
U.S. Spot Gold trading through IB LLC accounts is only available to legal residents of the United States that do not reside in Arizona, Montana, New Hampshire, and Rhode Island.
There is a substantial risk of loss in foreign exchange trading. The settlement date of foreign exchange trades can vary due to time zone differences and bank holidays. When trading across foreign exchange markets, this may necessitate borrowing funds to settle foreign exchange trades. The interest rate on borrowed funds must be considered when computing the cost of trades across multiple markets.
Join The Conversation
For specific platform feedback and suggestions, please submit it directly to our team using these instructions.
If you have an account-specific question or concern, please reach out to Client Services.
We encourage you to look through our FAQs before posting. Your question may already be covered!