Close Navigation
Differential Machine Learning with Twin Networks in R: Forecasting Bitcoin with Volatility Proxies

Differential Machine Learning with Twin Networks in R: Forecasting Bitcoin with Volatility Proxies

Posted July 7, 2026 at 12:12 pm

Selcuk Disci
DataGeeek

The article “Differential Machine Learning with Twin Networks in R: Forecasting Bitcoin with Volatility Proxies” was originally posted on DataGeeek blog.

Introduction

Differential Machine Learning (DML), as introduced in the recent arXiv paper (Differential Machine Learning for 0DTE Options with Stochastic Volatility and Jumps), extends supervised learning by incorporating not only function values but also their derivatives. In financial contexts, this often means sensitivities such as Greeks. However, when direct derivatives are unavailable, we can approximate market dynamics using volatility indicators.

In this project, we adapt DML to Bitcoin price forecasting. Instead of derivatives, we use RSI, MACD, and Bollinger Bands as proxies for volatility. These indicators capture momentum, trend strength, and price dispersion, providing a practical way to embed uncertainty into the learning process. To implement this, we design a twin-network architecture in Keras: one network learns price dynamics from time-based features, while the other learns volatility signals. Finally, we combine them via a stacking ensemble to achieve robust forecasts with confidence intervals.

Why Volatility Variables Instead of Derivatives?

  • RSI (Relative Strength Index): Measures momentum and overbought/oversold conditions.
  • MACD (Moving Average Convergence Divergence): Captures trend direction and strength.
  • Bollinger Bands (upper/lower bands, %B): Quantifies price dispersion and volatility.

These indicators act as empirical substitutes for theoretical derivatives. While DML in its pure form requires sensitivities, in practice, these volatility proxies provide similar information about how prices respond to market forces.

Why Twin Networks?

The idea is to separate the learning tasks:

  • The primary network models the continuous component of the price process.
  • The auxiliary network models the volatility/jump component. Together, they mimic the decomposition found in stochastic models such as Bates or Heston, but implemented within a flexible neural framework.

Ensemble via Stacking

Once both networks are trained, their predictions are combined using a linear regression meta-model. This stacking ensemble learns the optimal weighting between the primary and auxiliary outputs. The result is a forecast that integrates both trend and volatility signals, significantly improving accuracy compared to either network alone.

Evaluation

Differential Machine Learning with Twin Networks in R: Forecasting Bitcoin with Volatility Proxies

Source: DataGeeek

  • Metrics: RMSE and MAPE, computed with the yardstick package.
  • Results:
    • Individual networks → RMSE ~76,000, MAPE ~99%.
    • Stacking ensemble → RMSE ~3,030, MAPE ~3.65.

This demonstrates the power of combining price and volatility signals in a unified framework.

Confidence Intervals

To quantify uncertainty, we compute residual-based confidence intervals around the point forecasts:

Differential Machine Learning with Twin Networks in R: Forecasting Bitcoin with Volatility Proxies

This approach uses the standard deviation of training residuals to generate 95% confidence bands. It provides interpretable uncertainty estimates without requiring explicit probabilistic modeling.

Visualization

The forecasts are visualized with ggplot2:

  • Grey ribbon → confidence intervals.
  • Red line → stacking ensemble forecast.
  • Black line → actual BTC prices.
Differential Machine Learning with Twin Networks in R: Forecasting Bitcoin with Volatility Proxies

Source: DataGeeek

This design clearly communicates both the central forecast and the uncertainty range. The chart you will include at the end of the blog shows exactly this: a red forecast line, black actuals, and a grey confidence band, illustrating how the ensemble integrates volatility information into predictive intervals.

Differential Machine Learning with Twin Networks in R: Forecasting Bitcoin with Volatility Proxies

Source: Yahoo Finance

Keras3 in R: Flexible Deep Learning for Financial Forecasting

What is Keras3?

Keras3 is the modern R interface to the Keras deep learning library, built on top of TensorFlow. It allows R users to define, train, and evaluate neural networks with concise syntax while leveraging TensorFlow’s computational power. Unlike earlier versions, Keras3 is fully aligned with TensorFlow 2.x, ensuring long-term support and compatibility.

How We Used Keras3

In our workflow, Keras3 was the backbone for implementing the twin-network architecture:

Differential Machine Learning with Twin Networks in R: Forecasting Bitcoin with Volatility Proxies

Source: DataGeeek

Why ReLU?

  • ReLU (Rectified Linear Unit) is the activation function used in hidden layers.
  • Formula: ReLU(x)=max(0,x).
  • Benefits:
    • Introduces non-linearity, enabling the network to learn complex relationships.
    • Efficient and helps avoid vanishing gradients.
    • Well-suited for financial data where signals can be sparse and directional.

Why Adam?

  • Adam (Adaptive Moment Estimation) is the optimizer chosen.
  • Combines momentum (using past gradients to accelerate learning) and adaptive learning rates (adjusting step sizes per parameter).
  • Benefits:
    • Robust for noisy, non-stationary data like cryptocurrency prices.
    • Requires minimal tuning, making it ideal for plug-and-play workflows.
    • Widely adopted in both academic and applied machine learning.

Contribution to the R Ecosystem

Keras3 bridges the gap between R’s tidyverse/tidymodels ecosystem and modern deep learning:

  • Integrates seamlessly with data preprocessing pipelines (recipestimetk).
  • Allows financial analysts and data scientists to stay within R while accessing TensorFlow’s deep learning capabilities.
  • Encourages reproducibility: models can be defined, trained, and evaluated entirely in R, without switching to Python.
  • Expands R’s role beyond traditional statistical modeling into state-of-the-art AI applications.

Why It Matters for DML

By using Keras3:

  • We could separate learning tasks into a primary network (trend/seasonality) and an auxiliary network (volatility/momentum).
  • Both networks were trained with ReLU activations and Adam optimization, ensuring stability and efficiency.
  • Their outputs were combined in a stacking ensemble, yielding forecasts that integrate both price dynamics and volatility signals.

This demonstrates how Keras3 empowers R users to implement advanced architectures like twin networks, making Differential Machine Learning concepts practical in financial forecasting.

Conclusion

This case study demonstrates how Differential Machine Learning concepts can be adapted for financial forecasting in R:

  • Volatility indicators serve as practical substitutes for derivatives.
  • Twin-network architecture in Keras captures both trend and volatility.
  • Stacking ensembles significantly improves predictive performance.
  • Residual-based confidence intervals provide interpretable uncertainty estimates.

By combining academic ideas with reproducible R workflows, we can build robust forecasting pipelines that bridge theory and practice.

Disclosure: Interactive Brokers Third Party

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.

Disclosure: API Proof-of-Concept Disclosure

The third-party code discussed within this article is not investment or trading advice, and is for proof-of-concept, educational, and illustrative purposes only. IBKR makes no representations or warranty regarding its accuracy or completeness. Users are solely responsible for conducting their own independent testing and due diligence before applying any code or concepts in a live or production environment

Disclosure: Bitcoin (BTC) Trading

Trading Bitcoin involves significant risk. Bitcoin prices can be highly volatile and may fluctuate rapidly, potentially resulting in substantial losses. Because Bitcoin operates on a decentralized blockchain, network congestion or technical issues may occasionally delay transaction settlement. Regulatory frameworks for digital assets are still evolving and could impact availability, liquidity, or pricing. When trading through Interactive Brokers, execution and custody are facilitated by regulated partners such as Paxos or Zero Hash; however, these arrangements do not eliminate the possibility of operational or counterparty risk.

Disclosure: Digital Assets

Trading in digital assets, including cryptocurrencies, is especially risky and is only for individuals with a high risk tolerance and the financial ability to sustain losses. Eligibility to trade in digital asset products may vary based on jurisdiction.

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!

Leave a Reply

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.