Data and Code to reproduce results in paper "Explaining Regime Dynamics: A Tree-based Interpretation Framework for R2-RD Models"
Abstract
Data and Code to reproduce results in paper "Explaining Regime Dynamics: A Tree-based Interpretation Framework for R2-RD Models" This is a working paper. The restriction on codes will be removed after publication. This repository contains the necessary codes to reproduce results in the paper. Raw data: README.txt This study focuses on exploring the dynamics of macro-financial regimes with relevance to credit markets. As such, we require a rich set of time series reflecting credit activity and lending behavior over time. The Federal Reserve Economic Data (FRED) database maintained by the Federal Reserve Bank of St. Louis provides comprehensive, publicly accessible data on the U.S. credit market, and is thus selected as our primary data source. The FRED restrics access to redistribute the data (https://fred.stlouisfed.org/legal/). Thus, it is not allowed to upload the raw data. However, the README.txt file is uploaded. This is the metadata for the collected data. It presents the "Series ID", "Start Period", "End Period" of the collected series. With this metadata, researcher should be able to collect the same dataset from the platform (https://fred.stlouisfed.org). Data cleaning: app.py This file contains the code to clean the dataset, as described in the paper Section 3.2. To ensure temporal consistency, we restrict all time series to the period from January 2000 to the data download date (September 25, 2025). This window provides sufficient coverage while avoiding earlier periods with sparse observations. We first assess missing values across the selected series. Figure~\ref{fig:missing-data} visualizes the missing data pattern, where dark blue indicates available values and light blue indicates missing entries. If a series had more than 60\% missing values within the selected period, it was discarded. After this filtering step, 60 time series remained. For the retained series, missing values were imputed using time-based linear interpolation, which estimates missing values by linearly interpolating between the nearest available observations before and after the missing entry, based on their time indices. This method preserves the temporal continuity of each series and provides a reasonable approximation for short gaps. Upon visual inspection, some series still exhibited strong upward or downward trends, which violates the stationarity assumption required by the R2-RD model. Therefore, we applied first-order differencing to each series, defined as $\Delta x_t = x_t - x_{t-1}$. After differencing, the majority of series no longer display clear trending behavior, suggesting that the transformation has effectively removed most of the non-stationary components and prepared the data for regime-based modeling. After these steps, we obtained a clean dataset of 60 monthly series, with missing values handled and long-term trends removed, ready for modeling. Notably, we did not apply any standard normalization (e.g., z-score or min-max scaling) at this stage. This decision is motivated by three considerations: (1) normalization typically requires computing global statistics such as the full-sample mean or range, which would violate the expanding-window assumption underpinning the robust rolling regime detection framework; (2) in the next step, we apply R2-PCA, a dimensionality reduction technique that includes built-in normalization consistent with an expanding-window structure; and (3) while Hidden Markov Models are not inherently scale-invariant, the R2-RD framework operates on the principal component space where the scale sensitivity has already been addressed through R2-PCA preprocessing. Modeling: app.py This file contains the explanation part to the R2-RD model. However, the Python package "models" cannot be made public, because the copyright belongs to the company ask2.ai (ask2.ai).
Fields of Study & Subjects
Credit Risk and Financial Regulations
Global Financial Crisis and Policies
Sustainable Finance and Green Bonds
Publication details
- Journal / source
- Zenodo (CERN European Organization for Nuclear Research)
- Publication date
- 1 May 2026
- Document type
- Book