Stock-Market-Prediction · time series · finance

Financial time series
evaluated honestly.

Directional price movement prediction in a non-stationary, low signal-to-noise domain, where the stated goal is not profitability but facing overfitting and data leakage rigorously. Walk-forward validation, out-of-sample backtest with costs, hybrid per-ticker routing and real news sentiment.

«Existen numerosas formas de arruinarte. De entre ellas, crear un algoritmo de machine learning que trate de predecir el valor de las acciones en bolsa para luego invertir tu dinero, es una de las más rápidas y efectivas.»

Exploración técnica de Machine Learning aplicado a series temporales financieras. El objetivo no fue buscar rentabilidad, sino enfrentarse a un problema real con alta incertidumbre y aprender de los errores — especialmente del overfitting y del data leakage.

01
problem

What it solves

Predict whether an asset rises more than 2% in 5 days using Random Forest over multi-ticker data plus sentiment features. The honest framing is explicit: most published results in this domain fail out-of-sample, and this project treats that as the problem to solve: not a model to squeeze.
Task
Binary classification, 7 tickers · RF + VADER sentiment + NewsAPI.ai real news
Rigour
175 tests · mypy strict · walk-forward 3-fold · Optuna tuning · anti-leakage in code
Ops
FastAPI · PSI drift monitoring · hybrid per-ticker routing · ONNX-ready
02
decisions

Engineering decisions

→ Walk-forward is the only honest evaluation: 3-fold expanding window. The single 80/20 split inflated accuracy from 54.1% to 57.7% — discovered and corrected.
→ Scaler fitted on train only: the test set never touches the scaler.
→ Target built with shift(-5): the future only labels, never leaks into features.
→ RandomForest over HistGradientBoosting: RF wins AUC in 7/7 tickers (+0.028 avg). Calibrated probabilities rejected by predefined criterion.
→ Hybrid routing: pool as fallback: NVDA routes to a global model (pool AUC 0.539 vs individual 0.501). Others stay individual — TSLA is too idiosyncratic for pooling.
→ Real sentiment via NewsAPI.ai: 4,303 articles fetched, VADER-scored and aggregated daily. GDELT blocked from this network; free plan archives ~60 days.
→ Leakage tests in CI: tests verify no feature correlates ≥0.95 with the target.
03
results

The honest outcome

Walk-forward per ticker GOOGL 64.5% / 0.626 AUC · MSFT 55.8% / 0.580 · AMZN 58.2% / 0.575 · AAPL 56.4% / 0.559 · META 53.4% / 0.564 · TSLA 55.0% / 0.530 · NVDA routed to global pool (0.539 AUC).
Model comparison RandomForest wins AUC in 7/7 tickers over HistGradientBoosting (+0.028 avg). Accuracy improved from 54.1% → 57.7% after tuning Optuna with walk-forward as the objective.
The value is the evaluation rigour, not the model performance: knowing when a model does not work is precisely what protects real capital. The single-split evaluation inflated results by +3.6pp — only walk-forward revealed the true picture. This is the foundation for the portfolio manager system in development.