[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 quantitative cryptocurrency risk management, measuring single-asset downside volatility is rarely enough. During market stress, Bitcoin (BTC) and Ethereum (ETH) exhibit strong lower-tail dependence—meaning extreme drawdowns tend to occur simultaneously rather than independently. Building upon the joint tail risk modeling framework introduced in [arXiv:2611.28524v1], which combines conditional marginal tail estimation with dynamic copula dependence, this study translates theoretical tail dependence into an actionable trading signal.Rather than simply estimating today’s static probability of a joint crash (pjoint,tp_{\text{joint}, t}), our objective is to forecast whether systemic co-crash risk will escalate over the next 20 trading days. Specifically, we frame a forward-looking regime signal: will the average joint tail risk over the upcoming 20-day horizon exceed today’s baseline level (120∑h=120pjoint,t+h>pjoint,t\frac{1}{20}\sum_{h=1}^{20} p_{\text{joint}, t+h} > p_{\text{joint}, t})? When the model detects an elevated probability of rising joint tail dependence, it triggers a defensive posture (Hedge / Reduce Leverage); otherwise, it signals Standard Risk.System Architecture OverviewThe pipeline bridges financial econometrics and deep sequence modeling in native R using torch and tidymodels/yardstick:[BTC-USD & ETH-USD Daily OHLCV (2 Years)] | v[1. Marginal Tail Model: ES-CAViaR-R (alpha = 0.01)] - Recursive conditional VaR (q) & ES (es) - Asymmetric Laplace MLE (L-BFGS-B) - Standardized tail residuals: z_t = (ret_t - var_1,t) / (var_1,t - es_1,t) | v[2. Rank Transform & Batched Torch BB1 Copula MLE] - Rolling window: win_n = 90 days - Uniform pseudo-observations: u_btc, u_eth - Batched Adam optimization for BB1 parameters (theta, delta) - Joint tail risk probability at alpha = 0.01: p_joint(t) | v[3. Sequence Framing (lookback = 40, horizon = 20)] - Scaled input windows of p_joint (40 days) - Target trajectory deltas: (p[t+1:t+20] - p[t]) - Binary rise signal: mean(p[t+1:t+20]) > p[t] (YES / NO) | v[4. 2-Layer Torch LSTM + Softplus + Dense Aggregator] - 3 input channels: level, first diff, window-centered series - 2-layer LSTM (hidden = 64) + nn_softplus() heads - Optimizer: AdamW | Max budget: 50 epochs - Homoscedastic uncertainty loss via learned log_vars (no fixed weights) - Threshold selection via Youden J statistic | +----------+----------+ | | v v[4 Percentage Metrics] [20-Day Forecast Plot]- accuracy (%) - Daily posture classification- bal_accuracy (%) - Hedge vs. Standard Risk- sens (%) - ggtext title + ggplotly hover- spec (%)Stage 1: Marginal Tail Dynamics via ES-CAViaR-RTo capture time-varying tail risk and intraday range information before modeling cross-asset dependence, we first filter daily log-returns for both BTC-USD and ETH-USD using an ES-CAViaR-R specification at the $\alpha = 0.01$ extreme quantile level:Range-Augmented Quantile Recursion: Conditional Value-at-Risk (qt)(q_t) evolves autoregressively using lagged VaR and the Garman-Klass intraday volatility estimator (GKt−1GK_{t-1}).Conditional Expected Shortfall (EStES_t): Whenever a return breaches qt−1q_{t-1}, the tail spread wt=qt−EStw_t = q_t – ES_t updates dynamically based on standardized exceedance magnitude.Asymmetric Laplace MLE: Parameters are estimated via L-BFGS-B optimization under the Asymmetric Laplace density, yielding standardized tail residuals zt=(rt−VaR1,t)/(VaR1,t−ES1,t)z_t = (r_t – \text{VaR}_{1,t}) / (\text{VaR}_{1,t} – \text{ES}_{1,t}).Stage 2: Batched Torch BB1 Copula & Joint Crash ProbabilityStandardized residuals from Stage 1 are mapped into uniform pseudo-observations (uBTC,uETH)(u_{\text{BTC}}, u_{\text{ETH}}) over rolling 90-day windows (win_n = 90). Because linear correlation fails to capture asymmetric crash clustering, we model the joint distribution using the two-parameter BB1 (Clayton-Gumbel) copula, which simultaneously accommodates lower-tail (θ>0\theta > 0) and upper-tail (δ≥1\delta \ge 1) dependence.Rather than looping sequentially over hundreds of rolling windows on the CPU, we vectorize the entire rolling estimation as a single tensor batch in torch. Using optim_adam, all rolling windows are optimized simultaneously via exact analytical BB1 log-likelihood gradients. From the estimated parameters (θ^t,δ^t)(\hat{\theta}_t, \hat{\delta}_t), we extract the daily joint lower-tail exceedance probability at α=0.01\alpha = 0.01:pjoint(t)=CBB1(α,α;θ^t,δ^t)=(1+[2(α−θ^t−1)δ^t]1/δ^t)−1/θ^tp_{\text{joint}}(t) = C_{\text{BB1}}(\alpha, \alpha; \hat{\theta}_t, \hat{\delta}_t) = \left(1 + \left[2(\alpha^{-\hat{\theta}_t} – 1)^{\hat{\delta}_t}\right]^{1/\hat{\delta}_t}\right)^{-1/\hat{\theta}_t}Stage 3: Multi-Task 2-Layer LSTM & Homoscedastic Loss BalancingTo forecast how pjoint(t)p_{\text{joint}}(t) will evolve over the next 20 trading days, we construct 40-day lookback sequences enriched with three feature channels:Scaled Level: Standardized pjointp_{\text{joint}} values.First Difference (Δxt)(\Delta x_t): Daily momentum in tail dependence.Window-Centered Series (xt−x‾)(x_t – \bar{x}): Local regime deviation relative to the 40-day mean.These three channels feed into a 2-layer Torch LSTM (hidden_size = 64) paired with nn_softplus() projection heads and a dense trajectory aggregator. The network jointly predicts the 20-step trajectory deltas (ℒMSE)(\mathcal{L}_{\text{MSE}}) and the binary probability that average future tail risk will exceed today’s level (ℒBCE)(\mathcal{L}_{\text{BCE}}).Instead of introducing arbitrary manual weighting constants between classification and trajectory regression, the model learns task weights end-to-end via homoscedastic uncertainty weighting (log_vars) under the AdamW optimizer with a strict budget of 50 epochs. Finally, the optimal decision threshold is calibrated via Youden’s JJ statistic (Sensitivity+Specificity−1)(\text{Sensitivity} + \text{Specificity} – 1).Model Evaluation & Decision Signal InterpretationTo keep performance diagnostics transparent and directly interpretable for portfolio risk management, evaluation is distilled into four percentage-based yardstick metrics:MetricScore (%)Operational MeaningAccuracy62.2%Overall proportion of days where the 20-day risk regime direction is classified correctly.Balanced Accuracy62.2%Equal-weighted accuracy across rising-risk (YES) and easing-risk (NO) regimes, confirming no majority-class bias.Sensitivity (Recall)64.1%Proportion of actual joint tail-risk escalations successfully flagged in advance.Specificity60.4%Proportion of calm/easing periods correctly identified without triggering false hedge alarms.Predicting the 20-day forward direction of a rolling copula tail probability is inherently noisy, yet within a compact 50-epoch training budget, the model achieves a well-balanced ~62.2% classification profile without overfitting to either regime.In the final interactive ggplotly forecast visualization, daily projected probabilities are plotted against the Youden-optimal threshold: regions breaching the threshold are shaded in red (Hedge / Reduce Leverage), while periods remaining below are shaded in green (Standard Risk), translating complex copula-LSTM dynamics into an immediate, human-readable risk posture.Here is the full code:library(torch)library(plotly)library(tidyquant)library(yardstick)library(ggtext)library(tidyverse)set.seed(42)torch_manual_seed(42)# ============================================================# 1. DATA & ES-CAViaR-R MARGINAL TAIL ESTIMATION# ============================================================# Estimate ES-CAViaR-R conditional VaR, ES, and standardized residuals for one assetfit_escaviar_r