Author: [Bruce Zhou]
Affiliation: [Jota Machinery]
Corresponding Author: [jotamachinery@gmail.com]

Abstract

Stock market prediction models heavily rely on the quality and balance of historical trading signal labels. However, manual labeling of stock data — marking BUY, SELL, and MONITOR points — is notoriously tedious, inconsistent, and prone to human error. In this study, the authors propose a metaheuristic-driven framework to automate stock data labeling, specifically applying hill-climbing and simulated annealing search algorithms to daily stock price data from the Saudi Stock Exchange (Tadawul). This paper explores the limitations of traditional labeling, outlines the proposed partitioned optimization strategy, and evaluates the performance of these algorithms across multiple stocks. Experimental findings demonstrate that metaheuristic labeling yields up to 106% improvement in profitability-based objectives compared to manual methods while also providing more balanced label distributions. This automation is not only computationally efficient but also scalable and effective, laying the groundwork for better machine learning model training in financial forecasting.

1. Introduction

1.1 Background and Motivation

Labeling financial time series with trading signals — such as BUY and SELL — is foundational to building predictive trading models. These labels are typically derived by analysts using rule-based heuristics that segment historical data into actionable trade windows. However, this process is inherently labor-intensive, inconsistent, and vulnerable to subjective bias. With financial datasets growing in volume and velocity, manual approaches struggle to keep pace.

In the context of the Saudi Stock Market (Tadawul), where over 200 companies and indices are tracked daily, effective labeling of decades-long time series data becomes a bottleneck in training reliable financial models. Moreover, the market’s volatility necessitates highly adaptive, data-specific labeling strategies, which static manual rules cannot provide.

Smart Stock Labeling via Metaheuristics (Saudi Case)

1.2 Challenges of Manual Labeling

Traditional manual or semi-manual labeling often uses sliding-window or threshold-based heuristics. These rely on parameters like the window size (w) and the price change threshold (v), which are tuned manually. Prior studies showed wide variability in optimal w values (ranging from 4 to 20 days) for different stocks. This lack of generalizability results in imbalanced datasets dominated by SELL or MONITOR labels, while BUY labels — critical for forecasting profitable trades — remain underrepresented. Such imbalance impairs classifier performance and skews evaluation metrics, ultimately degrading trading signal quality.

2. Methodology

To overcome these challenges, the study introduces an automatic labeling framework that formulates the problem as a combinatorial optimization task. The key idea is to find a labeling sequence that maximizes the cumulative profit from hypothetical trades implied by those labels.

2.1 Partitioned Optimization Framework

The framework applies a divide-and-conquer strategy by dividing the dataset into fixed-length partitions (e.g., months):

  1. Partitioning: Split n trading days into n/l partitions of length l.
  2. Initialization: For each partition, randomly assign labels (BUY, SELL, MONITOR) to each day.
  3. Search: Apply a metaheuristic algorithm (hill-climbing or simulated annealing) to optimize label sequences within each partition.
  4. Aggregation: Merge the optimized partitions into a global labeling for the entire dataset.

Partitioned optimization reduces computational cost and allows localized tuning while still ensuring consistency in the aggregated result.

2.2 Hill-Climbing Labeling Algorithm

Hill-climbing (HC) starts with a random label sequence and explores neighboring configurations:

function HillClimbingLabel(initial_labels):
    I = initial_labels
    repeat:
        N = all_neighbors(I)
        I0 = argmax_{J in N} f(J)
        if f(I0) > f(I):
            I = I0
        else:
            break
    return I

Each neighbor differs from the current sequence by one label. If any neighbor yields a higher profit (as measured by the objective function f), the algorithm moves there. To avoid local optima, HC is run with multiple random restarts, retaining the best result.

2.3 Simulated Annealing Labeling Algorithm

Simulated annealing (SA) introduces controlled randomness to escape local optima:

function SimulatedAnnealingLabel(initial_labels, T0, alpha):
    I = initial_labels
    T = T0
    while T > 0:
        J = random_neighbor(I)
        Δ = f(J) - f(I)
        if Δ > 0 or rand() < exp(Δ / T):
            I = J
        T = alpha * T
    return I

Here, T is the temperature that cools over time. Moves to worse neighbors are probabilistically accepted when T is high, allowing the search to explore diverse solutions. Over time, the algorithm converges to near-optimal sequences.

2.4 Objective Function: Profit-Based Modeling

The optimization goal is to maximize hypothetical trading profits implied by the label sequence:

Equation 1: Total Profit

f(P)=∑(BPj,SPj)∈P(SPj−BPj)f(P) = \sum_{(BP_j, SP_j) \in P}(SP_j – BP_j)f(P)=(BPj​,SPj​)∈P∑​(SPj​−BPj​)

Where:

  • BPjBP_jBPj​ is the buy price at point j
  • SPjSP_jSPj​ is the corresponding sell price

This objective assumes that each BUY is paired with the next SELL, and profit is the price difference. Alternative formulations include averaging over multiple buy/sell points to reflect diversified entry/exit strategies.

3. Experimental Design

3.1 Dataset

The experiment used the Tadawul dataset (1994–2017), which includes:

  • Daily prices: open, high, low, close
  • Volume
  • Stock identifiers and indices

Four assets were analyzed in detail:

  • TASI Index (1010)
  • Alrajhi Bank (1120)
  • SABIC (2010)
  • NADEC (6010)

3.2 Implementation

  • Programming language: Java
  • Hardware: 3.2 GHz CPU, 8 GB RAM
  • Each algorithm was run 20 times with different random seeds to account for stochastic variation.
  • Baseline for comparison: manually labeled data using sliding-window thresholding.

4. Results

4.1 Metaheuristic Labeling vs. Manual Labeling

Table 1 (from the paper) shows that metaheuristic methods outperformed manual labeling by 63%–106% in cumulative profit across all assets. On average, they achieved ~80% higher profit scores.

Figure 3 illustrates that HC and SA mark BUY signals just before price uptrends and SELL before downtrends. In contrast, manual labeling failed to detect many such opportunities.

4.2 Partitioned vs. Non-Partitioned Optimization

  • Performance: Full-data optimization produced at most 4% higher profit than partitioned approaches.
  • Efficiency: Partitioned version took 1.3ms/day, whereas full optimization took 14ms/day — an 11× speedup.

Thus, the partitioned method achieves nearly identical results at a fraction of the time cost, making it more practical for large-scale datasets.

4.3 Hill-Climbing vs. Simulated Annealing

Both algorithms yielded comparable label quality:

  • For Alrajhi Bank, the label sequences from HC and SA were nearly identical.
  • Any performance differences were marginal and dataset-dependent.
  • This suggests that both methods are effective, with hill-climbing offering slightly faster convergence and SA providing more robustness against local optima.

4.4 Label Distribution and Balance

  • Automatic labels had balanced ratios of SELL and MONITOR labels.
  • Manual labels had >50% SELL labels, leading to class imbalance.
  • Auto-labeling yielded more BUY labels, which are essential for supervised learning in forecasting models.

Table 3 (in the paper) confirms the improved label diversity with HC and SA, increasing data usability for machine learning.

5. Discussion

5.1 Practical Benefits

  • Reduced human labor: No need for manual parameter tuning or domain heuristics.
  • Improved ML training: Balanced labels improve classifier learning, generalization, and risk estimation.
  • Market-specific tuning: The framework adapts to asset-specific dynamics, improving realism.

5.2 Efficiency vs. Accuracy

  • Partitioning introduces only a small accuracy trade-off (~4%) but brings huge gains in speed.
  • This makes the framework suitable for real-time labeling, even in high-frequency markets.

5.3 Broader Applicability

Though tested on Tadawul, the framework is agnostic to geography or market type. It can be applied to:

  • Cryptocurrencies
  • U.S. equities
  • Commodities or ETFs

It is also compatible with labeling multi-dimensional features (e.g., volume, RSI, MACD) if extended.

6. Conclusion and Future Work

This study demonstrates that metaheuristic search methods — hill-climbing and simulated annealing — can automate the labeling of stock market data more effectively than manual approaches. The proposed framework is fast, scalable, and yields more profitable and balanced labels.

Key Contributions:

  • Formulating labeling as a profit-maximization search problem
  • Demonstrating partitioned optimization for scalable performance
  • Validating HC and SA across diverse Saudi stocks

Future Directions:

  • Train ML models using the auto-labeled data to assess end-to-end predictive performance.
  • Extend to real-time labeling scenarios (e.g., intraday data).
  • Incorporate multi-asset or portfolio-level objective functions.

Last Updated on 18/11/2025 by Jota Machinery

Scroll to Top