Unveiling the Black Box: Counterfactual Analysis for Transparent and Robust Reinforcement Learning in Algorithmic Trading

Authors

  • Abdelmounim Lefrayah Artificial Intelligence, Modeling and Computational Engineering - AIMCE, ENSAM, Hassan II University, Casablanca, Morocco
  • Badr Hirchoua Artificial Intelligence, Modeling and Computational Engineering - AIMCE, ENSAM, Hassan II University, Casablanca, Morocco
  • Mustapha Hain Artificial Intelligence, Modeling and Computational Engineering - AIMCE, ENSAM, Hassan II University, Casablanca, Morocco

DOI:

https://doi.org/10.19139/soic-2310-5070-4109

Keywords:

Reinforcement Learning, Algorithmic Trading, Counterfactual Analysis, Trajectory Reanalysis, Interpretability, Explainable AI, Financial Machine Learning, Risk Management

Abstract

Reinforcement learning (RL) has emerged as a powerful paradigm for developing adaptive trading agents;however, the “black-box” nature of these models remains a persistent barrier to institutional trust and regulatory acceptance.This paper introduces a novel framework that integrates Counterfactual Analysis (CFA) into the evaluation of RL tradingtrajectories to provide granular, causal interpretations of agent behavior. By identifying high-entropy decision points andsimulating alternative “what-if” scenarios through a learned market environment model, our approach quantifies the PolicyRegret of specific actions.The counterfactual engine reveals a 9.56% validation rate, identifying a learned “Strategic Conservatism” where the agentprioritizes capital preservation over high-regret aggressive strategies. This framework establishes counterfactual analysis asa vital tool for bridging the gap between algorithmic trading and practical deployment, promoting transparency, causality,and robustness in automated financial decision-making systems.We validate this framework using daily historical trading data of the SPY ETF (2022–2023). Our results demonstratethat the PPO-based agent significantly outperforms conventional benchmarks, achieving a 14.32% total return and a 1.32Sharpe Ratio, while maintaining a superior risk profile with a 9.4% maximum drawdown.

Downloads

Published

2026-09-17

How to Cite

Lefrayah, A., Hirchoua, B., & Hain, M. (2026). Unveiling the Black Box: Counterfactual Analysis for Transparent and Robust Reinforcement Learning in Algorithmic Trading. Statistics, Optimization & Information Computing. https://doi.org/10.19139/soic-2310-5070-4109

Issue

Section

Research Articles

Categories