## 3 Materials and Methods
### Instability Model Training Strategy  
As shown in Figure 2 (left), the instability detector is composed of a BBRBM that creates a high-level representation in the hidden layer values of the input layer values. Then, these hidden layer values are the input to a Feedforward Neural Network. This network is the supervised stage of the process. The idea is that given an input vector \(\mathbf{v}\), we can have a probability indicator that we are in the presence of an instability. Consistent with what we know about periods of instability (see Section 2.1), the BBRBM input features will be slices of \(k\) volatility lags and \(k\) price variation lags. Then, the input vector \(\mathbf{v}=\{v^{v},v^{\prime}\}\) is a set of \(k\) volatility values \(v^{v}=(v_{t-k},\ldots,v_{t-1},v_{t})\) and \(k\) values of \(v^{\prime}=(r_{t-k},\ldots,r_{t-1},r_{t})\) returns. However, the BBRBM accepts only 0 or 1 discrete values as inputs, so our strategy will be to discretize the values of volatility and returns according to percentile. So, for example, since we are interested in detecting unstable samples, we can make \(v^{\prime}_{i}=0\) if \(v^{\prime}_{i}<P^{\prime}_{2}\), where \(P^{\prime}_{2}\) is the 20 th percentile of returns, and similarly, \(v^{v}_{i}=1\) if \(v^{v}_{i}>P^{v}_{8}\), where \(P^{v}_{8}\) is the 80 th percentile of volatility. All other values will otherwise be zero. This way, we recognize samples in the lower right-hand region of the joint volatility-return distribution in Figure 1 (See Appendix B for more details justifying these percentiles). For example, consider \(k=3\), i.e., we look at today and two periods back. Then, if \(v^{v}=(1,1,0)\) and \(v^{\prime}=(0,0,1)\), it would indicate that before yesterday and yesterday, we had unstable samples, and the input vector to the BBRBM would be \(\mathbf{v}=(1,1,0,0,0,1)\). This binarization arrangement allows us to identify abnormal system states, leading to a regime change in the market. Figure 3b shows magnetization diagrams of different crises. The magnetization is the average of the last k states. Thus, in the example above, the magnetization of volatility at \(t\) when \(v^{v}=(1,1,0)\), would be \(2/3\); similarly, \(1/3\) for the returns. Then, in Figure 3a, we presented four crises: Black Monday in 1987, the dot-com crisis in 2000, the Subprime crisis in 2008, and the COVID-19 crisis in 2020. Each time series represents the value of the index at the indicated dates. Applying the model to the four crises, we can see in Figure 3b that for \(k=8\), one can obtain that after the critical moment \(t_{c}\), the magnetization of the volatility is very close to 1, while that of the returns is close to zero, indicating a clear transition of the system to a state of high instability (high variability and negative returns). To better understand the features used to train the BBRBM, we present in Figure 4 time slices with eight lags for volatility and returns of the S&P500, represented in \(4~{}\times~{}4\) images. The first two columns of each image depict the states of 8 consecutive days of volatility, and the following two columns represent the same 8 days of returns. As we observe, samples corresponding to periods of instability tend to be in high volatility (yellow color or +1 state) and low/normal volatility (purple color or zero state). In comparison, periods just before instability (BTC) are characterized by states of low volatility (purple color or zero state) and medium or high returns (yellow color or +1 state). The clear distinction between unstable (UNS) and non-stable samples (BTC) allows us to consider generating synthetic samples to train the BBRBM and ANN to detect unstable samples. So, we can have as many synthetic samples as we want, which frees us from using  
Figure 4: An array representation of the time slices of volatility and returns with \(k\) lags. We take a time slice of \(k=8\) lags of binarized volatility and returns and plot it in a matrix form only for graphical representation. The input to the BBRBM is a vector of length \(2k\).