Skip to content

add quant alpha backtest workflow for better accuracy including an initialization of a quantitative trading algorithm#3

Open
ITheClixs wants to merge 1 commit into
saidsurucu:masterfrom
ITheClixs:quant-alpha-backtest
Open

add quant alpha backtest workflow for better accuracy including an initialization of a quantitative trading algorithm#3
ITheClixs wants to merge 1 commit into
saidsurucu:masterfrom
ITheClixs:quant-alpha-backtest

Conversation

@ITheClixs

@ITheClixs ITheClixs commented Apr 25, 2026

Copy link
Copy Markdown

Özet

Bu PR, mevcut MCP veya ajan mimarisini değiştirmeden BorsaCI’ye küçük, deterministik bir quant alpha iş akışı ekler.

Değişenler:

  • BIST OHLCV verileri için bağımlılıksız bir alpha/backtest modülü olan borsaci.quant_alpha eklendi.
  • get_historical_data OHLCV döndürdükten sonra alpha/backtest/ICT/tahmin istekleri mevcut ajan cevap akışına bağlandı.
  • Mevcut plotext bağımlılığı kullanılarak alpha ile al ve tut stratejisini karşılaştıran bir equity-curve görselleştirmesi eklendi.
  • Planner/action ajanlarının alpha, ICT, algoritmik trading ve backtest istekleri için tarihsel OHLCV çekmesini sağlayacak şekilde promptlar güncellendi.
  • README’de kullanım dokümante edildi ve gerçek MCP destekli örnek sonuçlarla docs/quant_alpha_backtest.md eklendi.
  • Ayrıştırma, rapor üretimi ve backtest davranışı için odaklanmış unit testler eklendi.

Neden

BorsaCI zaten BIST tarihsel fiyatlarını çekiyor ve terminal grafikleri render ediyor. Bu değişiklik bu akışı olduğu gibi korur, ancak LLM nihai cevabı yazmadan önce yeniden üretilebilir bir yerel hesaplama katmanı ekler. Bu da kullanıcılara algoritmik/quantitative trading analizi sorduklarında doğrulanmamış bir anlatı yerine şeffaf metrikler verir.

Alpha skoru trend, momentum breakout, RSI bağlamı, volatilite/hacim displacement, ICT tarzı likidite sweep tespiti ve ICT tarzı fair value gap tespitini birleştirir.

Backtest, BIST nakit hisse senetleri için bilinçli olarak konservatiftir: long-only çalışır, negatif sinyallerde nakde çıkar ve her pozisyon değişiminde %0,20 ücret uygular.

Backtest kanıtı

Yeni motoru 2026-04-25 tarihinde güncel BorsaMCP.get_historical_data(symbol, market="bist", period="5y") çıktıları üzerinde çalıştırdım. MCP şu anda bu 5 yıllık örnekler için 30 kaba OHLCV barı döndürüyor, bu yüzden motor lookback pencerelerini mevcut bar sayısına uyarlar ve kanıt, bağımsız bir trading sistemi olarak abartılmak yerine al ve tut ile yan yana gösterilir.

Sembol Barlar Son Sinyal Alpha Getirisi Al-Tut Getirisi Sharpe Maksimum Düşüş Yön Doğruluğu İşlemler
ASELS 30 YUKARI, skor 0.75 1108.04% 2489.17% 1.11 -34.48% 73.33% 3
THYAO 30 NOTR, skor 0.10 1818.20% 2229.75% 1.28 -15.90% 62.50% 2
GARAN 30 NOTR, skor -0.05 1018.13% 1393.51% 1.33 -12.02% 80.00% 2

Varsayımların tamamı docs/quant_alpha_backtest.md içinde dokümante edilmiştir.

Doğrulama

  • uv run python -m unittest discover -s tests
  • ASELS, THYAO ve GARAN için period="5y" ile get_historical_data kullanan gerçek MCP smoke run

Notlar

Bu yalnızca araştırma amaçlı bir araçtır ve oluşturulan rapor bunun yatırım tavsiyesi olmadığını açıkça belirtir. Özellik özellikle yerel sinyal üretimi ve backtest metrikleriyle sınırlandırılmıştır, böylece incelenmesi ve bakımı kolay kalır.


Summary

This PR adds a small, deterministic quant alpha workflow to BorsaCI without changing the existing MCP or agent architecture.

What changed:

  • Added borsaci.quant_alpha, a dependency-free alpha/backtest module for BIST OHLCV data.
  • Wired alpha/backtest/ICT/prediction requests into the existing agent answer flow after get_historical_data returns OHLCV.
  • Added an equity-curve visualization for alpha vs buy-and-hold using the existing plotext dependency.
  • Updated prompts so the planner/action agents fetch historical OHLCV for alpha, ICT, algorithmic trading, and backtest requests.
  • Documented usage in the README and added docs/quant_alpha_backtest.md with real MCP-backed sample results.
  • Added focused unit tests for parsing, report generation, and backtest behavior.

Why

BorsaCI already retrieves BIST historical prices and renders terminal charts. This change keeps that flow intact, but adds a reproducible local calculation layer before the LLM writes the final response. That gives users transparent metrics instead of an unverified narrative when they ask for algorithmic/quantitative trading analysis.

The alpha score combines trend, momentum breakout, RSI context, volatility/volume displacement, ICT-style liquidity sweep detection, and ICT-style fair value gap detection.

The backtest is intentionally conservative for BIST cash equities: it is long-only, exits to cash on negative signals, and charges 0.20% on each position change.

Backtest evidence

I ran the new engine on current BorsaMCP.get_historical_data(symbol, market="bist", period="5y") outputs on 2026-04-25. The MCP currently returns 30 coarse OHLCV bars for these 5-year samples, so the engine adapts lookback windows to the available bar count and the evidence is shown beside buy-and-hold rather than overstated as a standalone trading system.

Symbol Bars Last Signal Alpha Return Buy-Hold Return Sharpe Max Drawdown Direction Accuracy Trades
ASELS 30 YUKARI, score 0.75 1108.04% 2489.17% 1.11 -34.48% 73.33% 3
THYAO 30 NOTR, score 0.10 1818.20% 2229.75% 1.28 -15.90% 62.50% 2
GARAN 30 NOTR, score -0.05 1018.13% 1393.51% 1.33 -12.02% 80.00% 2

The full assumptions are documented in docs/quant_alpha_backtest.md.

Validation

  • uv run python -m unittest discover -s tests
  • Real MCP smoke run using get_historical_data for ASELS, THYAO, and GARAN with period="5y"

Notes

This is research tooling only and the generated report explicitly states that it is not investment advice. The feature is intentionally scoped to local signal generation and backtest metrics so it remains easy to review and maintain.

@ITheClixs ITheClixs changed the title [codex] add quant alpha backtest workflow add quant alpha backtest workflow for better accuracy including an initialization of a quantitative trading algorithm Apr 25, 2026
@ITheClixs ITheClixs marked this pull request as ready for review April 28, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant