Skip to content

vscode1111/algo-platform

Repository files navigation

algo-env

C++17 streaming backtesting engine and strategy optimizer. ~50K LOC, 59 technical indicators across 8 categories, 3 optimizer methods (random / grid / gradient-descent), 8 parallel workers. React + lightweight-charts dashboard.

Dashboard

Overview

Research environment for developing and evaluating quantitative trading strategies on historical OHLCV data. The engine processes candles one at a time in O(1) per candle (no buffer recomputation on each tick), which makes it fast enough to run thousands of optimizer trials in parallel without a GPU.

Alongside the C++ engine, the repo contains hand-rolled ML primitives (MLP, matrix library, feature engineering) and ports of the backtest/optimize core in Go, Rust, Node.js, and Python as a polyglot performance study.

Honest scope: candle-based backtester, not a live HFT engine. No order-book simulation, no slippage model, no latency modeling. Results are an upper bound on what a real execution environment would produce.

Architecture

Data sources (Binance, Bybit REST APIs)
  -> OHLCV downloader + PostgreSQL cache
  -> Streaming backtester (C++17)
      IStrategy interface <- strategy plugins (RSI, EMA cross, counter-trend, ...)
      Indicator library   <- 59 headers, O(1) update per candle
      BacktestResult      <- Sharpe, max drawdown, profit factor, win rate, equity curve
  -> Optimizer (C++17, 8 worker threads)
      RANDOM              <- Monte Carlo parameter search
      GRID                <- exhaustive grid over param ranges
      GRADIENT_DESCENT    <- finite-difference gradients, multi-start
  -> Crow REST API (C++)
  -> React frontend (Vite + TypeScript + lightweight-charts)
      Dashboard       <- candlestick chart, quick backtest runner
      Strategies      <- configure params, run, view results
      Optimization    <- launch optimizer, live progress, equity curves
      Data Cache      <- manage OHLCV subscriptions, sync status
      Research        <- AI-driven strategy iteration (experiment sessions)

ML layer: hand-rolled MLP with matrix library and feature engineering pipeline, exposed via the same REST API. Trains on indicator feature vectors, not raw prices.

Indicator library (59 headers)

Category Indicators
Trend (11) SMA, EMA, WMA, DEMA, TEMA, HMA, VWMA, KAMA, Ichimoku, Parabolic SAR, Supertrend
Oscillators (12) RSI, MACD, Stochastic, CCI, CMO, MFI, ROC, TSI, Williams %R, Awesome Oscillator, Ultimate Oscillator
Volatility (7) ATR, Bollinger Bands, Keltner Channels, Donchian Channels, Historical Volatility, Chaikin Volatility, Std Dev
Volume (8) OBV, VWAP, CMF, AD Line, PVT, VROC, Ease of Movement
Statistical (8) Sharpe Ratio, Max Drawdown, Hurst Exponent, Beta, Correlation, Linear Regression, R-Squared, Z-Score
Patterns (5) Doji, Engulfing, Hammer, Star Patterns, Three Soldiers/Crows
Support/Resistance (4) Pivot Points, Fibonacci Retracements, Fibonacci Pivots, Camarilla Pivots
Trend Strength (4) ADX, Aroon, DI, Vortex

Key decisions

C++17 over Python/pandas: the streaming model updates each indicator by one new candle in O(1), carrying state between ticks. A pandas-style vectorized backtester recomputes the full indicator array on each call, which makes per-candle O(n) and kills optimizer throughput. At 1,000 optimizer trials of 10,000 candles each, the difference is ~10x wall time.

Header-only indicator library: each indicator is a single .h file with no external dependencies. Adding a new indicator means adding one file; the compiler inlines everything. Zero-cost abstraction with no vtable overhead in the hot loop.

Gradient-descent + random, not grid: the strategy parameter space is non-convex and the objective (Sharpe ratio) has many local minima. Grid search is exponential in the number of parameters - impractical above 4. Pure random search misses fine structure near good solutions. Multi-start gradient-descent with finite-difference gradients escapes most local minima while being O(trials * params) in evaluations.

Setup & run

Backend (C++17)

# Linux / WSL
cd backend
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
./server
REM Windows
build.bat

Requires: CMake 3.16+, GCC 11+ or Clang 13+, PostgreSQL (for OHLCV cache), libpqxx.

Frontend (React + Vite)

cd frontend
npm install
npm run dev

Docker

docker-compose up

Configure .env (copy from .env.example) with PostgreSQL connection, Binance/Bybit API keys (read-only, data only), and JWT secret.

Polyglot cores

The experiments/ directory contains ports of the backtester/optimizer core:

Language Notes
Go goroutine-per-worker optimizer
Rust rayon parallel iterator
Node.js worker_threads
Python multiprocessing baseline

Written as a performance study; the C++ core is the production engine.

License

Proprietary.

About

C++17 strategy backtester + optimizer with React dashboard (57 indicators, Crow REST)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors