Algorithmic trading architecture designed by the Autonomous Intelligence Network (AIN).
Project description
Sagan Trade
High-fidelity symbolic mathematical engine and quantitative architecture for institutional alpha generation.
Sagan Trade replaces black-box neural networks with transparent, human-readable mathematical equations discovered via FunctionGemma. It combines the precision of Symbolic Regression with the robustness of Asymmetric Convexity risk management.
As of v0.8.4+, the library natively incorporates mathematical discoveries autonomously generated by the Autonomous Intelligence Network (AIN).
🏛️ Institutional Benchmarking
Sagan Trade has been rigorously tested across 5 years of historical market regimes, accounting for institutional trading fees and liquidity constraints.
Long-Term Resilience (5-Year Rolling Audit)
Benchmark: 20-Ticker Diversified Portfolio (Tech, Finance, Energy, Consumer).
| 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% |
[!IMPORTANT] Statistical Significance: The symbolic engine achieves a p-value of 0.0182, indicating that its outperformance against legacy TFT-PINN and LSTM models is statistically significant at the 98% confidence level.
🔬 Core Architecture
1. Symbolic Discovery (FunctionGemma & TCN)
Instead of weight matrices, Sagan discovers market invariants in the form of mathematical expressions using an ultra-fast Temporal Convolutional Network (TCN).
- 30x Faster Inference: Completely replaced legacy LSTMs with dilated causal convolutions, breaking the sequential bottleneck and achieving $O(1)$ hardware-parallel sequences.
- Precision: Fits variables to $R^2 > 0.95$ using basis functions (Polynomial, Fourier).
- Explainability: Every trade is backed by a human-readable formula, e.g.,
(Close * 0.5) + log(Volume).
2. Asymmetric Convexity Engine
Sagan utilizes a non-linear risk management framework inspired by high-frequency market makers:
- Downside Convexity: Exponentially scales exposure based on momentum-volatility asymmetry.
- Adaptive Kelly Sizing: Drawdown-aware fractional Kelly scaling to ensure capital preservation.
- Asymptotic Shield: Quadratic drawdown protection creates a hard floor on portfolio risk.
3. AIN Volatility Regime Filter (New in 0.8.4+)
Autonomously discovered through the AIN's Grand Synthesis sprint, the Hawkes-Bates Volatility Regime Filter acts as a macroeconomic sidecar that shifts portfolios to cash during contagion regimes by dynamically analyzing the Volatility Risk Premium (VRP). It achieved a validated 1.09 Sharpe Ratio in isolated NIFTY 50 backtests.
🚀 Quick Start
Installation
pip install sagan-trade
Alpha Generation, Risk Modeling, & Backtesting
This comprehensive quickstart demonstrates the full lifecycle: Symbolic Discovery, Volatility Filtering, Risk Management, and Backtest Execution.
import pandas as pd
from sagan_trade import (
SymbolicRegressor,
AsymmetricRiskEngine,
VolatilityRegimeFilter,
BacktestEngine
)
# 1. Fetch Market Data
data = pd.DataFrame({
'Close': [...],
'Volume': [...],
'RSI': [...]
})
# 2. Symbolic Discovery (FunctionGemma & TCN)
regressor = SymbolicRegressor(basis_functions=['poly', 'fourier'])
model_id = regressor.train(target="AAPL", signals=["Close", "RSI", "Volume"])
predicted_signal, formula = regressor.predict()
print(f"Discovered Alpha: {formula}")
# 3. Macro Regime Filtering (Hawkes-Bates VRP Proxy)
vol_filter = VolatilityRegimeFilter(vol_window=20, ma_window=120)
regime_signals = vol_filter.generate_signals(data['Close'])
print(f"Current Market Regime (1=Risk-On, 0=Cash): {regime_signals.iloc[-1]}")
# 4. Initialize Asymmetric Convexity Risk Engine
risk_engine = AsymmetricRiskEngine(target_vol=0.15, max_drawdown_limit=0.075)
# 5. Execute End-to-End Backtest
backtester = BacktestEngine(
initial_capital=1000000,
maker_fee=0.0001,
taker_fee=-0.0003
)
results = backtester.run(
prices=data['Close'],
alpha_signals=predicted_signal,
regime_filter=regime_signals,
risk_model=risk_engine
)
print(f"Backtest Sharpe: {results.sharpe_ratio}")
print(f"Backtest Max Drawdown: {results.max_drawdown}")
🛠️ Components
| Component | Responsibility |
|---|---|
| SymbolicRegressor | High-precision math fitting with iterative $R^2$ optimization. |
| AsymmetricRiskEngine | Rides upside volatility while aggressively cutting downside tail risk. |
| VolatilityRegimeFilter | Avoids structural drawdowns via variance targeting and VRP analysis. |
| BacktestEngine | Rigorous walk-forward evaluation with fee-modeling support. |
| SaganConfig | OS-level optimization for Turbo/Eco compute profiles. |
License
MIT © 2024 Sagan Labs / Sambit Mishra
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sagan_trade-0.8.7.tar.gz.
File metadata
- Download URL: sagan_trade-0.8.7.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bc1a147d5fe77e871f5be3e457d841b75ffd4395310bd058fdf5a057d354622
|
|
| MD5 |
4146fb6ecdba1e73a923dc2449394a7d
|
|
| BLAKE2b-256 |
45dd08ccf37cd31bb3ecb139715aff0beff6e4164d2c6c161810bd08dc572502
|
File details
Details for the file sagan_trade-0.8.7-py3-none-any.whl.
File metadata
- Download URL: sagan_trade-0.8.7-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef8ca2c6553c5fbf5b680d52959f8a5416a22a3c39805db50c9931fdc8870054
|
|
| MD5 |
f758604ecf80b5f490c2691e27568f30
|
|
| BLAKE2b-256 |
ce6939c85f2ca44e8fa867805bb0f4881047dd538784aa9b7026d7c2f1ff7b9f
|