Skip to content

Kaynetic/omni-quant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Omni-Quant — Self-Evolving Quantitative Trading System

Codename "Quant God" / Project Apeiron

A research-grade, self-improving algorithmic trading platform in Python: a Bayesian meta-learner that allocates capital across strategy specialists, wrapped in a hard-limit risk governor the AI cannot override, with optimal execution, causal inference, and adversarial stress-testing — deployable on AWS and wired to a live broker via the IC Markets cTrader Open API.

About this repo. Case study of a personal quantitative-engineering project. Strategy logic, signal parameters, broker internals, configuration, and live trade data are deliberately withheld — the one code file here (excerpts/risk_governor.py) is a hand-written, sanitized illustration of the safety-limit pattern, not the production implementation, and contains no trading edge. Credentials and account data are not included and never will be. This is an engineering showcase, published for research and educational purposes — it is not financial advice, a solicitation, or a claim of trading returns. Algorithmic trading carries substantial risk of loss. All rights reserved — see the copyright notice below.


Why this project

Most "trading bots" are a single strategy hard-coded by hope. I wanted to build the opposite: a system that treats trading as a research problem — allocating between competing strategies by evidence, governing itself with risk limits that no model output can breach, executing to minimize market impact, and improving itself over time. The engineering that makes that safe and reliable is the point; profit is not claimed.

Architecture

flowchart TB
    subgraph Research["Research layer"]
        AUTO["Auto-Researcher<br/>anomaly to hypothesis to test to feature"]
        CAUSAL["Causal Inference<br/>Granger, DAG discovery, counterfactuals"]
    end

    subgraph Brain["Meta-learning orchestrator (Thompson Sampling)"]
        M1["Momentum<br/>specialist"]
        M2["Mean-Reversion<br/>specialist"]
        M3["Volatility<br/>harvester"]
        M4["Black-Swan<br/>detector"]
    end

    subgraph Safety["Risk Governor (hard interlock)"]
        RG["2% daily loss, 10% max drawdown<br/>2x leverage, 10% position, 30% sector<br/>forbidden symbols, market-hours only, auto-halt"]
    end

    subgraph Exec["Execution"]
        EA["Almgren-Chriss optimal execution<br/>market-impact model, TWAP / VWAP"]
        BR["IC Markets cTrader Open API<br/>Twisted / Protobuf client"]
    end

    subgraph Test["Adversarial testing"]
        ST["Stress chamber<br/>flash crash, correlation breakdown, black swan, gamma squeeze"]
    end

    Research --> Brain
    Brain --> Safety
    Safety --> Exec
    EA --> BR
    ST -.->|survival rate| Brain

    subgraph Cloud["AWS infrastructure (CDK)"]
        AWS["Kinesis, SageMaker, Lambda, DynamoDB, S3 data lake, EventBridge nightly retrain, CloudWatch"]
    end
    Brain --- Cloud
Loading

The seven layers

  1. Meta-learning orchestrator (Thompson Sampling). Rather than betting on one strategy, four specialists — momentum (EMA-crossover), mean-reversion (z-score), a volatility harvester, and a black-swan/tail-risk detector — compete for capital. Thompson Sampling balances exploration and exploitation, updating its beliefs about each specialist from realized PnL and Sharpe changes. ~690 lines.

  2. Risk Governor — the safety interlock. A set of hard constraints that the model cannot override: 2% daily-loss halt, 10% max-drawdown halt, 2× gross-leverage ceiling, 10% single-position and 30% sector caps, a forbidden-symbols list (leveraged ETFs), and market-hours-only trading with an auto-halt. Every proposed trade passes through validate_trade() before it can reach the broker. This is the trading analogue of the fail-safe, human-in-the-loop guardrails I build into AI systems elsewhere: the AI can propose; it can never breach the limits. ~590 lines. See excerpts/risk_governor.py.

  3. Optimal execution (Almgren-Chriss). Large orders aren't dumped at market — an execution layer models permanent and temporary market impact and solves for a trajectory that minimizes E[cost] + λ·Var[cost], with TWAP/VWAP scheduling and an urgency parameter. ~570 lines.

  4. Causal inference. Markets are full of spurious correlation, so the research layer runs Granger-causality tests, learns causal-graph (DAG) structure, and answers counterfactuals ("what would SPY have done if the Fed hadn't hiked?") — so features are chosen for causal signal, not curve-fit correlation. ~650 lines.

  5. Adversarial stress-testing. Before trusting a configuration, a market simulator tries to break it: 2010-style flash crashes, 2008/2020 correlation breakdowns, 10-sigma black-swan moves, and 2021 gamma-squeeze dynamics — reporting a survival rate. ~650 lines.

  6. Self-improvement loop (Auto-Researcher). The system watches its own performance for anomalies ("loses money on Mondays"), generates a hypothesis, runs the statistical test, validates any new feature, and folds it back in on the next retrain — closing the research loop autonomously. ~680 lines.

  7. Live broker integration. A high-performance event-driven client (Twisted + Protobuf over SSL) for the IC Markets cTrader Open API — heartbeat management, tick validation, and information-threshold filtering. ~3,300 lines.

Cloud: the whole thing is defined as AWS CDK stacks — Kinesis streaming, an S3 data lake, SageMaker inference endpoints, Lambda, DynamoDB, CloudWatch dashboards/alarms, and EventBridge-scheduled nightly retraining.

What it demonstrates

  • Safety engineering under adversarial conditions — the same instinct as my production AI work: hard guardrails that a model output can never override, and systems designed to halt safely rather than fail open.
  • Applied ML beyond a single model — Bayesian model selection (Thompson Sampling), causal inference over correlation, and self-supervised research loops.
  • Quant depth — Almgren-Chriss execution, market-impact modeling, VaR/drawdown governance, and crisis-scenario stress testing.
  • Real systems plumbing — a 3,300-line event-driven Protobuf broker client, AWS CDK infrastructure-as-code, and a backtesting harness.

Research direction (Project Apeiron)

The system is evolving toward a physics-inspired successor — "topology over trend": geometric intelligence over the data (Fisher-information / topological data-analysis features) and a verification ledger that must approve every trade. This is experimental research, included here for transparency about where the work is heading.

Sanitized excerpt

File Pattern it demonstrates
excerpts/risk_governor.py Hard, non-overridable risk limits — the circuit breaker every AI-driven trade must pass

Built by Kamogelo Mahlasela.

Copyright & permitted use

© 2026 Kamogelo Mahlasela. All rights reserved.

This repository is published for viewing only, so prospective employers and collaborators can evaluate my work. No license is granted. Beyond viewing on GitHub (and the limited on-platform rights GitHub's Terms of Service provide), no part of this repository — text, architecture diagrams, or code excerpts — may be copied, reproduced, modified, distributed, or used to create derivative works without my prior written permission. Nothing here is financial advice or an offer to trade.

About

Case study: a self-evolving quantitative trading system - Thompson-sampling orchestrator, a hard-limit risk governor the AI cannot override, Almgren-Chriss execution, causal inference, adversarial stress-testing

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages