📈 Building a Robust Time-Series Trend Classification Engine using Darts and ARIMA
I. The Edge in Financial Forecasting
In the world of quantitative finance, the ability to accurately predict the direction of an asset’s price—its trend—is the holy grail. Whether a price will Increase, Decrease, or remain Flat over a specific horizon is the core signal driving investment decisions and algorithmic trading strategies. This challenge requires a robust system capable of handling the inherent noise and complexity of financial time series data.
This article details the time-series-trend-classification-darts project, an initiative aimed at developing a stable, validated, and reliable engine for automated trend classification.
The project achieves its goal by leveraging two powerful tools in the Python ecosystem:
- Darts: A unified library that simplifies the integration and evaluation of various time series models.
- ARIMA: A classic, proven statistical model used here to establish a dependable baseline predictor.
The primary objective was successfully met: establishing a system baseline with validated stability and classification logic. This initial validation was achieved with near-perfect accuracy on a specific low-volatility asset, providing a confirmed platform for testing against more volatile markets.
II. The Technological Foundation: Darts and ARIMA
A. Darts: The Unified Time Series Library
Darts is a powerful Python library that dramatically simplifies the process of working with time series data. It serves as a comprehensive wrapper, providing a unified API for a vast array of models, from traditional statistical methods (like ARIMA) to advanced deep learning architectures.
Using Darts was a crucial design decision for this project because it:
- Standardizes Data: It uses the
TimeSeriesobject, abstracting away complex data handling and preprocessing. - Simplifies Modeling: It allows for seamless switching between models, enabling rapid prototyping and evaluation.
- Streamlines Evaluation: It provides built-in tools for robust evaluation techniques like the Rolling Origin Backtest, which is essential for simulating real-world performance.
B. The ARIMA Model
The Autoregressive Integrated Moving Average (ARIMA) model was chosen as the baseline predictor. While more complex deep learning models exist, starting with ARIMA offers clear advantages:
- Interpretability: Its parameters are easier to understand and tune.
- Proven Stability: It is a time-tested method for handling non-stationary time series data.
The specific configuration selected and validated for stability within the system was ARIMA(p=15, d=1, q=0).
III. Methodology: Defining and Validating Trends
The core of the system lies in its ability to translate a raw price forecast into a discrete trend classification based on defined rules.
A. Data and Context
To ensure the classification logic and backtesting mechanism were fundamentally sound, the system was initially tested on the FNCL 6.5 Bond Price data. This asset was deliberately chosen for its low volatility. The goal was to confirm system stability under ideal conditions, where price movements are predictable and flat.
B. The Core Classification Logic
The system classifies the forecast into one of three mutually exclusive classes based on the percentage change between the start and end of the forecast horizon:
| Class | Trend Description | Condition |
|-------|------------------------|----------------------------------------------------------------|
| 0 | Flat/Neutral | Price change is within the threshold (e.g., -1.0% to +1.0%). |
| 1 | Increase (Bullish) | Forecasted price exceeds the positive threshold. |
| 2 | Decrease (Bearish) | Forecasted price falls below the negative threshold. |The two critical configuration parameters determining the trend classification are:
| Parameter | Value | Purpose |
|------------------------|----------------|----------------------------------------------------------------------|
| Forecast Horizon | 90 Days | The number of days the model predicts into the future. |
| Classification Threshold | 1.0% (0.01) | The minimum percentage change required to classify the trend as Increase or Decrease. |C. Robust Evaluation: Rolling Origin Backtest
To simulate real-world trading conditions and ensure robustness, the project uses a Rolling Origin Backtest.
Get Henry Chukwunwike Morgan-Dibie’s stories in your inbox
Join Medium for free to get updates from this writer.
The Process:
- The ARIMA model is trained on a defined history window.
- It makes a 90-day forecast.
- The predicted trend is classified and compared against the true 90-day movement (the ground truth).
- A STEP_SIZE then advances the entire training window (origin).
- This process is repeated until the end of the available data, producing a large sample of predictions and a final, robust accuracy metric.
Key Optimization
| Parameter | Value | Purpose |
|------------|----------|--------------------------------------------------------------------------------------------------------------------------------------|
| STEP_SIZE | 90 Days | Optimization: The number of days the training window advances. Setting `STEP_SIZE = 90` ensures efficient evaluation by running the rolling forecast only at non-overlapping intervals. |IV. Results & Analysis: A Stable Baseline
The final evaluation, conducted using the robust rolling origin backtest methodology on the low-volatility bond data, produced the following conclusive metric:
| Metric | Value |
|----------------------|---------------------|
| Asset Analyzed | FNCL 6.5 Bond Price |
| Model Used | ARIMA(15, 1, 0) |
| Final Robust Accuracy| ~100% |Interpretation of Near-100% Accuracy
This result does not indicate a perfect market-beating model. Instead, it serves as a powerful validation of two core tenets:
- Data Validation: The bond data exhibits extreme stability and low volatility over the testing period, meaning the true price movement almost always fell within the “Flat” (Class 0) classification threshold.
- System Validation: The Darts/ARIMA system is confirmed to be stable and correctly implemented. The logic for data transformation, ARIMA fitting, forecasting, and classification is sound, and it correctly identified the prevailing market state.
The system is therefore confirmed as a stable, validated baseline ready for deployment against more challenging assets.
V. Implementation Deep Dive
The project is structured logically for reproducibility and modularity:
| Folder/File | Description |
|-----------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `src/train_model.py` | ➡️ The Core Engine. Contains all data loading, classification logic, ARIMA training, and the robust rolling backtest execution. |
| `notebooks/` | Exploratory notebooks detailing the analytical workflow and methodology (`1_New_Data_Exploration.ipynb` and `2_Classification_Test.ipynb`). |
| `models/arima_trend_predictor_90d_1pct` | The serialized ARIMA(15, 1, 0) model file used for the final classification. |
| `results/classification_report_90d_1pct.txt` | Stores the final classification accuracy report and prediction logs. |
| `requirements.txt` | Lists all necessary Python dependencies. |How to Reproduce the Classification Test
The entire training, evaluation, and reporting process is initiated with a single command:
- Prerequisites: Python 3.8+ and the necessary dependencies (listed in
requirements.txt). - Clone the Repository:
git clone https://github.com/HenryMorganDibie/time-series-trend-classification-darts.git
cd time-series-trend-classification-darts3. Install Dependencies:
pip install -r requirements.txt4. Run the Test:
python src/train_model.pyThis script will execute the rolling backtest, print the final accuracy to the console, and save a detailed report to the results/ folder.
VI. Conclusion and Future Work
The time-series-trend-classification-darts project successfully delivered a stable and robust Darts/ARIMA system for trend classification, validated on low-volatility financial data. This baseline is now a solid foundation for more advanced research.
The logical next steps focus on escalating the challenge:
- The Volatility Test: The most critical next phase is testing the system on highly volatile assets (e.g., individual equities or digital currencies). The true test of the classification engine’s predictive power will be its performance when the trend class is genuinely expected to change often.
- Model Expansion: If ARIMA’s performance degrades on volatile assets, the modularity of Darts allows for seamless integration of sophisticated machine learning and deep learning models (such as N-BEATS or LSTMs) for comparative analysis.
By building on a stable foundation and systematically increasing complexity, this system is positioned to evolve into a powerful, data-driven tool for identifying high-probability trends in a variety of financial markets.










