2.1. Multiscale Random Forest: Mathematical Definition and Implementation
The traditional RF algorithm [
26] combines the bagging algorithm with the random subspace method. Let
, be the training dataset, where
is a
-dimensional feature vector and
is a three class label. It constitutes an ensemble prediction model
composed of a set of decision trees, where
is the input feature vector,
is the
-th decision tree prediction model,
is an independent and identically distributed random vector, and
represents the number of decision trees in the RF. Taking a three class classification problem as an example, the specific steps for constructing the RF model are as follows:
Step 1: Given the training data , conduct resampling with replacement on to obtain , and thus obtain the bootstrap dataset . Repeat times to obtain bootstrap datasets .
Step 2: For each bootstrap dataset , apply the random subspace method and the classification tree algorithms for learning. Specifically, when splitting each node of the decision tree, randomly select a feature subset from the entire set of features according to a uniform distribution, and then choose an optimal splitting feature and feature value from this subset to construct the decision tree. In this way, decision trees are obtained.
Step 3: For a new data vector
, classification is performed by each decision tree from Step 2, resulting in the output label vector
for
. The bootstrap probability is the proportion of
in the label vector
, the formula is:
where
I[⋅] is the indicator function.
Step 4: The predicted label is determined by:
It is noteworthy that, for a new data vector
, we formulate the following hypothesis regarding the outcome variable
predicted by the random forest:
Let the true probability of be denoted by and con sequently the probabilities of and are , where . Since implies that , the hypothesis in (3) can be equivalently expressed as , and the null hypothesis is a polyhedral cone. The BP defined in Equation (1) can then be interpreted as the p-value for testing hypothesis (3). However, as discussed in the introduction, this BP-based p-value is biased and only achieves first-order accuracy. To address this limitation, we introduce the MRF method in what follows.
The proposed MRF model improves on the traditional RF algorithm in both the training and prediction phases using the concept of the multiscale bootstrap method. In the training phase, the training samples are resampled multiple times to generate multiple RF models, which are then integrated to form the MRF model. This enhances the learning ability of the prediction model on existing data. In the prediction phase, the MRF model improves the prediction accuracy by using unbiased
p-value testing. Specifically, the multiscale
and the relationship between the multiscale
and the sample scale are obtained. The unbiased
p-value of third-order accuracy is calculated using regression analysis and extrapolation methods, thereby improving the prediction accuracy of the prediction model. To further illustrate the method, we continue with the three-class classification problem as an example. Let
denote a bootstrap sample generated from original training data
with resampling scale factor
, i.e., sample size
for the
b-th resampling is:
where
is the number of scales, [·] denotes the floor function, which returns the greatest integer less than or equal to the input,
represents the number of samples in the original training set
. The specific steps for the MRF model during the training and prediction phases are as follows:
Step 1: Using the new samples , generate B RF models , according to the standard RF algorithm. Integrate these RF models to obtain the MRF model .
Step 2: During the prediction phase for new data, for a given new input variable
, classification is performed by each RF model
in the MRF model using its multiple decision trees, and the multiscale
at scale
is:
where
is resampling with replacement on
,
is the number of decision trees per forest,
I[⋅] is the indicator function.
For a new data vector
, to estimate the third-order accuracy unbiased
p-value
, construct
, where
is the sample scale and
is the inverse function of the standard normal distribution. We fit the logistic regression model following Shimodaira [
19]:
Step 3: By taking
as the dependent variable and
as the independent variable, regression analysis yields
. Extrapolating
gives
, then the third-order accuracy unbiased
p-value for the new sample
having label
is given by:
Step 4: The predicted label is determined by:
This process yields a prediction model with higher-order
p-value correction, reducing the bias inherent in conventional bootstrap aggregation voting and improving classification reliability. As noted by Shimodaira [
19] the improved performance of multiscale bootstrap in noisy datasets arises from the curvature effect in the null hypothesis
. By accounting for this curvature, the method corrects the bias in conventional bootstrap probabilities, yielding more accurate
p-values and more reliable inference.
In classical hypothesis testing, for a new data , if the hypothesis testing p-value is greater than 0.05, i.e., , we accept the null hypothesis . However, in the rules of the multiscale random forests, an additional condition is attached, namely that the null hypothesis is accepted only when . This threshold of 0.5 follows the rule of ordinary random forests, where the threshold is also 0.5, and it does not contradict the 0.05 threshold used in classical hypothesis testing.
From a statistical inference perspective, comparing the error orders of bootstrap
and multiscale
reveals critical differences in their asymptotic properties. Specifically, standard
exhibits a first-order bias under regularity conditions, with the asymptotic behavior characterized as [
19]:
where
is the number of original training samples
and
denotes the true unbiased
p-value of the null hypothesis
. In contrast, the
p-value achieves third-order accuracy, with a substantially reduced asymptotic bias:
By substituting the conventional hard decision rule:
with a statistically justified
p-value thresholding:
the MRF model provides a statistically grounded decision boundary that is less sensitive to sampling variability and better aligned with formal hypothesis testing. This modification directly improves prediction reliability in high-variance environments, such as stock market trend classification.
2.4. Data Source, Preprocessing, and Feature Selection
The CSI 300 stock index includes 300 representative stocks from the Shenzhen and Shanghai stock exchanges, reflecting the comprehensive performance of China’s stock market. For this study, we selected relevant indicators of the CSI 300 stock index and attempted to predict the daily closing price trends. The experimental samples were sourced from the website Choice Financial Terminal [
27], with 3019 samples collected from 1 January 2012, to 11 June 2024, excluding holidays and trading halts. The basic indicators include the opening price, highest price, lowest price, closing price, trading volume, and trading amount for the day. The 15 technical indicators include the simple moving average, weighted moving average, momentum, stochastic K, stochastic D, relative strength index, exponential moving average, moving average convergence divergence, Larry Williams’%R, accumulation/distribution oscillator, commodity channel index, price rate of change, bias ratio, different of moving average, and change rate. Among them, the simple moving average, relative strength index, Larry Williams’%R, price rate of change, bias ratio, and exponential moving average were selected for different periods, giving another five technical indicators. The calculation formulas for the 20 technical indicators are provided in
Table 1, while the data collections and the calculation procedures of the technical indicators are detailed in the
Supplementary Materials (Supplementary Folder S1).
In
Table 1,
represents the closing price on day
and
represents the closing price on the day
− 1.
and
represent the lowest and highest prices, respectively, within the
days preceding day
.
and
represent the average increase and average decrease, respectively, of the closing prices within the
days preceding day
.
denotes the exponential moving average up to day
− 1.
indicates the trading volume on day
.
and
refer to the highest and lowest prices, respectively, on day
.
is the moving average with parameter
for
, and
is the mean absolute deviation between
and
.
Combining the basic and technical indicators of various cycles resulted in 26 indicators as high-dimensional input data
. The sample matrix of the dataset composed of input and output variables is:
This dataset consists of the input variable
and the output variable
, with
being the number of samples.
We took 80% of the dataset as the training set, 10% as the validation set, and 10% as the test set. The training set ranged from 1 January 2012 to 9 December 2021 (2415 days); the validation set ranged from 10 December 2021 to 10 March 2023 (302 days); and the test set ranged from 11 March 2023 to 11 June 2024 (302 days). The MRF, RF, SVM, and WKNN algorithms were used to build prediction models on the training set. The hyperparameters of the different models were optimized to obtain trained prediction models.
To identify the most influential predictors among the 26 candidate features, a five-fold cross-validated stepwise regression was performed on the combined training and validation dataset. In each fold, four subsets were used for model fitting and evaluated using the Akaike Information Criterion (AIC). The model with the minimum AIC was selected, and its retained variables were adopted as the final input features. Consequently, 16 significant predictors were identified: SMA(10), WMA(10), WR(6), RSI(6), RSI(12), AD, MTM(10), Stochastic D, ROC(12), BIAS(10), BIAS(15), MACD(9), CCI, MA(5), Closing Price, and ROC(1).
To compare the performance improvement of the prediction models produced by stepwise regression analysis, two datasets were used: the original dataset with 26 indicators and the dataset with 16 indicators selected by stepwise regression. The test samples from both datasets were input into the trained prediction models, and the prediction results for each test sample were output. The general process of constructing the prediction models in this study is shown in
Figure 1. In
Figure 1, the original dataset containing all 26 indicators is denoted as Dataset I, while the dataset comprising the 16 selected indicators is referred to as Dataset II.