Skip to main content

Strategic High-Throughput Symbolic Trading Engine with iterative R2 fitting, FunctionGemma discovery, and specialized LSTM controllers.

Project description

Sagan Trade

High-throughput symbolic mathematical trading engine

Python License: MIT PyPI

Sagan Trade replaces black-box neural networks with transparent, human-readable mathematical equations discovered via FunctionGemma (via Ollama).

Component Role
Symbolic Regressor Fits variables to R2 > 0.95 using Polynomial and Fourier basis functions.
FunctionGemma AI architect that suggests optimal mathematical compositions of signals.
Power Hub OS-level optimization for maximum throughput (Eco, Balanced, Turbo).

Installation

pip install sagan-trade

Or in editable mode from source:

git clone https://github.com/That-Tech-Geek/sagan-trade
cd sagan-trade
pip install -e ".[dev]"

📊 Conclusive Research & Benchmarking

Sagan Trade has been rigorously benchmarked against initial Deep Learning architectures (TFT-PINN). The results prove that Symbolic Regression provides superior risk-adjusted returns and institutional-grade transparency.

Institutional-Grade Performance (20-Ticker Portfolio Audit)

Benchmark conducted on a diversified institutional-grade basket: AAPL, NVDA, TSLA, MSFT, GOOGL, META, AMD, GS, JPM, XOM, UNH, V, MA, PG, JNJ, HD, ABBV, COST, LLY, CRM.

Metric Symbolic (SOTA) TFT-PINN (Initial) Buy & Hold
OOS Return (6mo) 33.60% -37.52% 52.19%
Sharpe Ratio 4.41 -2.47 2.39
Max Drawdown -2.92% -35.10% -12.06%
Win Rate 61.45% 42.22% N/A

🏛️ Long-Term Institutional Resilience (5-Year Audit)

A rigorous 5-year rolling walk-forward audit was conducted to evaluate the engine's performance across multiple market regimes, including the impact of institutional trading fees.

Metric Gross of Fees Net of Fees (5bps) S&P 500 (B&H)
Annualized Return 33.27% 12.98% 14.50%
Sharpe Ratio 2.11 1.06 0.85
Max Drawdown -6.91% -7.30% -23.90%
Total Cumulative 426.11% 102.46% 96.80%

[!NOTE] Even after aggressive institutional fees (5bps per trade), the Symbolic SOTA engine maintains a superior Sharpe Ratio (1.06) compared to the S&P 500 benchmark, while significantly reducing tail risk (MDD -7.30% vs -23.90%).

Statistical Significance

  • P-Value: 0.0182 ($p < 0.05$)
  • Verdict: The Symbolic Engine is statistically outperforming legacy black-box ML models with high institutional confidence.

[!TIP] Why the Math Model is safer: As the number of assets increases, Sagan's AsymmetricRiskEngine applies strict exposure scaling (capped at 3.0x - 4.0x). This results in a higher Sharpe Ratio (4.41) and significantly lower drawdown compared to standard equity portfolios, prioritizing capital preservation and asymmetric convexity.

Signal Fidelity & The "Fidelity Gap"

The engine utilizes a "Minimal Complexity First" principle to discover market invariants:

  • Price Signals: Consistently achieve $R^2 > 0.90$ using 5th-degree polynomials.
  • Volume Signals: Require Fourier series to capture structural cyclicality ($R^2 \approx 0.41$).

Quick Start

Python API

import sagan

# Train a symbolic ensemble with high-accuracy math fitting
model_id = sagan.train(
    ["AAPL"], 
    signals=["Close", "Volume", "RSI"], 
    profile="turbo"
)

# Predict using the latest symbolic expression
result = sagan.predict()
print(result["signal"])     # "LONG" | "SHORT"
print(result["formula"])    # e.g. "(Close * 0.5) + log(Volume)"

Command-Line Interface

# List available math signals for a ticker
sagan vars AAPL

# Train symbolic model
sagan train AAPL --signals Close,Volume --profile turbo

# Get Trading Signal
sagan predict

Architecture

yfinance Data
       │
       ▼
[Parallel Fitting] → Each variable fitted to R2 > 0.95
       │
       ▼
[FunctionGemma]   → Suggests composite math formula
       │
       ▼
[Evaluation]      → Trend-based signal generation

Configuration

All defaults live in sagan.config:

from sagan import config

config.models_dir = "~/.sagan/models/"

License

MIT © 2024 Sagan Labs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sagan_trade-0.7.2.tar.gz (101.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sagan_trade-0.7.2-py3-none-any.whl (99.7 kB view details)

Uploaded Python 3

File details

Details for the file sagan_trade-0.7.2.tar.gz.

File metadata

  • Download URL: sagan_trade-0.7.2.tar.gz
  • Upload date:
  • Size: 101.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for sagan_trade-0.7.2.tar.gz
Algorithm Hash digest
SHA256 a871bd9ac35c110771b8953f88449231a445a52652c1509022c29f3d9b4ca30c
MD5 8e99e22e13c75f5f6fc362d7504a107c
BLAKE2b-256 db10f6d2d86b8ffa5c108093841bd805607db6a27771f38b010dfde7e61bdd45

See more details on using hashes here.

File details

Details for the file sagan_trade-0.7.2-py3-none-any.whl.

File metadata

  • Download URL: sagan_trade-0.7.2-py3-none-any.whl
  • Upload date:
  • Size: 99.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for sagan_trade-0.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 844c67d950f8f97f770d7bc92003cc4f3a3457961c8351ca1e212ec533cc3fe9
MD5 45d4be257b0499b5791a077f3ec74156
BLAKE2b-256 dda22cb7cbd20153fa3855ea3f935759df51daabf5d68c30a48442374911233e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page