Conformal Prediction Intervals of XGBoost Model: Bitcoin Peaks Amid Coinbase’s Earnings Struggle
Update: 2025-08-09
Description
[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.
In the second quarter, Coinbase did not meet Wall Street’s expectations. This decline occurred alongside lower market volatility, despite BTC prices reaching record highs according to Kaiko Research.
The chart below indicates that the market priced the aforementioned from August. We can observe a negative decoupling between the Bitcoin and Coinbase Global share prices.
<figure data-wp-context="{"imageId":"68976f1d442bd"}" data-wp-interactive="core/image" class="wp-block-image size-large wp-lightbox-container">

class="lightbox-trigger"
type="button"
aria-haspopup="dialog"
aria-label="Enlarge"
data-wp-init="callbacks.initTriggerButton"
data-wp-on-async--click="actions.showLightbox"
data-wp-style--right="state.imageButtonRight"
data-wp-style--top="state.imageButtonTop"
>
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
</svg>
</button></figure>
Source code:
library(tidyverse)
library(tidymodels)
library(modeltime)
library(timetk)
library(tidyquant)
#Coinbase Global
df_coin <-
tq_get("COIN") %>%
select(date, Coinbase = close)
#Bitcoin
df_btc <-
tq_get("BTC-USD") %>%
select(date, Bitcoin = close)
#Merging the datasets
df_merged <-
df_coin %>%
left_join(df_btc) %>%
drop_na() %>%
filter(date >= last(date) - months(36)) %>%
pivot_longer(-date,
names_to = "id",
values_to = "close") %>%
mutate(id = as_factor(id))
#Split Data
splits <-
time_series_split(
df_merged,
assess = "15 days",
cumulative = TRUE
)
#Create & Fit Forecasting Models
#Recipe
recipe_ml <-
recipe(close ~ ., training(splits)) %>%
step_timeseries_signature(date) %>%
step_rm(date) %>%
step_dummy(all_nominal_predictors(), one_hot = TRUE) %>%
step_zv(all_predictors()) %>%
step_normalize(all_numeric_predictors())
#Model & Workflow
model_xgb <-
boost_tree("regression") %>%
set_engine("xgboost")
wflw_fit_xgb <-
workflow() %>%
add_model(model_xgb) %>%
add_recipe(recipe_ml) %>%
fit(training(splits))
#Adding fitted models to a Model Table
models_tbl <- modeltime_table(
wflw_fit_xgb
)
#Calibrating the model to a testing set
calibration_tbl <-
models_tbl %>%
modeltime_calibrate(
new_data = testing(splits),
id = "id"
)
#Accuracy of the finalized model
calibration_tbl %>%
modeltime_accuracy(metric_set = metric_set(rmse, rsq, mape),
acc_by_id = TRUE) %>%
table_modeltime_accuracy()
#Conformal Split Method
#https://business-science.github.io/modeltime/articles/modeltime-conformal-prediction.html
forecast_tbl <-
calibration_tbl %>%
modeltime_forecast(
new_data = testing(splits),
actual_data = df_merged %>% filter(date >= as.Date("2025-07-23")),
conf_interval = 0.95,
conf_method = "conformal_split", # Split Conformal Method
conf_by_id = TRUE, # TRUE = local CI by ID, FALSE = global CI
keep_data = TRUE
)
#Plotting prediction intervals
forecast_tbl %>%
group_by(id) %>%
plot_modeltime_forecast(
.facet_ncol = 1,
.line_size = 1.5,
.interactive = FALSE
) +
labs(title = "Conformal Prediction Intervals of XGBoost Model",
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.title = ggtext::element_markdown(face = "bold",
hjust = 0.5,
size = 18),
strip.text = element_text(face = "bold"),
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.
Comments
In Channel