## 4 Materials and Methods
### Random Forest-Based Black-Litterman Portfolio Optimization Model  
#### 4.1.1 Generating Views Using Random Forests  
As mentioned before, \(Q\) and \(\Omega\) revise the priori returns, which is extremely important to the BL model. Nowadays, many attempts are made to generate views by ML algorithms which try to train a predictor based on historical data to form specific return forecasts for certain assets, i.e., \(Q\). However, this kind of methods may not provide the view uncertainty. Therefore, we employ the random forests to form view vector and generate the view uncertainty at the same time.  
Random forest [35] is an ensemble method which constructs a set of base classification models, and synthesizes the final output by averaging the predicted value of each base classification model. The main training steps of random forests are shown in Algorithm 3.  
```
0:\(S\) data samples
0:\(M\) decision trees
1:for\(i\gets 1\) to \(M\)do
2: Sample randomly from the original training data set to form \(S\) new data samples.
3: Construct the decision tree based on the new data set and the corresponding node split rules.
```  
**Algorithm 3** Main training steps of random forests  
As a decision tree based ensemble method, random forest is appealing due to the advantages it provides, including the ability to maintain high prediction accuracy and not being prone to overfitting. Moreover, it can be directly applied in high-dimensional problems. In 2011, [PERSON] et al. [36] used random forests to replace the Gaussian process (GP) to ease the updating difficulty of GP models under a large-scale known point set in Bayesian optimization. Furthermore, the variance of the predicted values of multiple trees is used as an uncertainty measure. The core idea of this work is that consistent predictions based on different models and different training data indicate more reliable results. In this paper, we follow this idea to form the absolute view vector based on the random forests and measure the view uncertainty by the difference in the predicted values of multiple trees. Then, the procedure of obtaining view vector \(Q^{rf}\) and the view uncertainty \(\Omega^{rf}\) are summarized as follows.  
* Construct a random forest model based on the historical return data to predict asset returns, and use the model output \(y_{pred}\) as an absolute view.
* Calculate the maximum absolute deviation between the output of \(M\) decision trees and the model output \(\text{MAE}=\text{max}\left|y_{i}-y_{pred}\right|\), for \(i\in[1,2,\ldots,M]\).
* Calculate the proportion of subtrees whose absolute deviation from \(y_{pred}\) is less than \(\frac{\text{MAE}}{10}\) and take it as the uncertainty of the corresponding view.
* Repeat the above process until the \(K\) views and corresponding uncertainty are constructed.  
Based on the view vector and the view uncertainty generated from random forests concurrently, we can calculate the posterior estimate of expected returns and covariance matrix further. We believe that the adopting of random forests will significantly weaken the conservatism and greatly enhance the generalization of the BL model.