AI-Powered Financial Intelligence Engine - Realistic Backtesting, TCA, Strategy Comparison, ML, 8 Strategies.
Project description
๐ฆ FinClaw
AI-Powered Financial Intelligence Engine โ 8 Strategies, 5 Markets, ML Pipeline, Full Backtesting, Zero Heavy Dependencies
English | ไธญๆ | ๆฅๆฌ่ช | ํ๊ตญ์ด | Franรงais
$100 โ $354 (5 years, 29.1% annualized)
Tested on 100+ real stocks across US, China, Hong Kong
30/34 individual backtests outperform buy-and-hold
๐๏ธ Architecture
graph TB
subgraph Data Layer
DP[Data Pipeline<br/>Yahoo Finance / Multi-Source]
Cache[Pipeline Cache]
Validator[Data Validator]
end
subgraph Analysis Engine
TA[Technical Analysis<br/>17 Indicators]
ML[ML Pipeline<br/>Features / Models / Alpha]
Sent[Sentiment Analysis]
end
subgraph Strategy Layer
MOM[Momentum JT]
MR[Mean Reversion]
PT[Pairs Trading]
TF[Trend Following]
VM[Value + Momentum]
COMB[Strategy Combiner]
end
subgraph Risk & Portfolio
RISK[Risk Management<br/>Kelly / VaR / Sizing]
SL[Stop-Loss Manager]
PORT[Portfolio Tracker]
REB[Rebalancer]
ATTR[Attribution Analytics]
end
subgraph Backtesting
WF[Walk-Forward Analyzer]
MC[Monte Carlo Simulator]
MTF[Multi-Timeframe]
BENCH[Benchmark Comparison]
end
subgraph Interface Layer
API[REST API Server]
WH[Webhooks<br/>Slack / Discord / Teams]
SCR[Stock Screener]
ALR[Alert Engine]
CLI[CLI - finclaw.py]
end
DP --> TA
DP --> ML
TA --> MOM & MR & PT & TF & VM
ML --> COMB
MOM & MR & PT & TF & VM --> COMB
COMB --> RISK
RISK --> PORT
PORT --> REB
PORT --> ATTR
COMB --> WF & MC & MTF
WF --> BENCH
COMB --> API
API --> WH
SCR --> ALR
CLI --> API
โก Quick Start
Install from PyPI
pip install finclaw-ai
Install from Source
git clone https://github.com/NeuZhou/finclaw.git
cd finclaw
pip install -e ".[dev]"
Your First Scan
# Scan US market for momentum signals
python finclaw.py scan --market us --style soros
# Backtest NVIDIA over 5 years
python finclaw.py backtest --ticker NVDA --period 5y
# Start the REST API server
python -m src.api.server --port 8080
๐ฏ Features
๐ Technical Analysis โ 17 Indicators (Zero Dependencies)
All indicators are pure NumPy โ no TA-Lib required.
| Category | Indicators |
|---|---|
| Moving Averages | SMA, EMA, WMA, DEMA, TEMA |
| Oscillators | RSI, Stochastic RSI, MFI |
| Trend | MACD, ADX, Parabolic SAR, Ichimoku Cloud |
| Volatility | Bollinger Bands, ATR |
| Volume | OBV, CMF |
from src.ta import sma, rsi, macd, bollinger_bands
import numpy as np
prices = np.array([100, 102, 101, 105, 108, 107, 110, 112])
print(rsi(prices, period=5))
print(bollinger_bands(prices, period=5))
๐ง Strategies
Six battle-tested strategies plus a combiner that merges them with configurable weights:
| Strategy | Class | Description |
|---|---|---|
| Momentum (Jegadeesh-Titman) | MomentumJTStrategy |
Classic cross-sectional momentum |
| Mean Reversion | MeanReversionStrategy |
Bollinger Band + RSI mean reversion |
| Pairs Trading | PairsTradingStrategy |
Statistical arbitrage on correlated pairs |
| Trend Following | TrendFollowingStrategy |
ADX + MACD trend riding |
| Value + Momentum | ValueMomentumStrategy |
Composite value & momentum scoring |
| Strategy Combiner | StrategyCombiner |
Weighted ensemble of all strategies |
from src.strategies import StrategyCombiner, MomentumAdapter, MeanReversionAdapter
combiner = StrategyCombiner()
combiner.add(MomentumAdapter(), weight=0.6)
combiner.add(MeanReversionAdapter(), weight=0.4)
signal = combiner.generate_signal(prices)
๐ฌ Backtesting Engine
Walk-forward analysis, Monte Carlo simulation, and multi-timeframe validation:
from src.backtesting import WalkForwardAnalyzer, MonteCarloSimulator
# Walk-forward with 5 folds
wfa = WalkForwardAnalyzer(n_splits=5, train_ratio=0.7)
results = wfa.analyze(strategy, prices)
# Monte Carlo โ 1000 paths
mc = MonteCarloSimulator(n_simulations=1000)
mc_results = mc.simulate(returns)
print(f"95th percentile drawdown: {mc_results['percentile_95_drawdown']:.1%}")
โ๏ธ Risk Management
Kelly criterion, Value-at-Risk, position sizing, and stop-loss management:
from src.risk import KellyCriterion, VaRCalculator, StopLossManager, StopLossType
# Kelly sizing
kelly = KellyCriterion(win_rate=0.55, avg_win=0.08, avg_loss=0.04)
fraction = kelly.optimal_fraction()
# VaR
var = VaRCalculator(confidence=0.99)
var_99 = var.calculate(returns)
# Stop-loss
sl = StopLossManager(stop_type=StopLossType.TRAILING, pct=0.08)
๐ค ML Pipeline
Feature engineering โ model training โ alpha generation โ walk-forward validation:
from src.ml import FeatureEngine, AlphaModel, WalkForwardPipeline
features = FeatureEngine()
X = features.build(prices, volumes)
alpha = AlphaModel()
alpha.fit(X_train, y_train)
signals = alpha.predict(X_test)
pipeline = WalkForwardPipeline(model=alpha, feature_engine=features)
results = pipeline.run(prices, volumes)
๐ผ Portfolio Management
Track positions, rebalance, and attribute returns:
from src.portfolio import PortfolioTracker, PortfolioRebalancer
tracker = PortfolioTracker(initial_cash=100_000)
tracker.execute_trade("AAPL", shares=50, price=150.0)
rebalancer = PortfolioRebalancer()
actions = rebalancer.rebalance(
current={"AAPL": 0.7, "MSFT": 0.3},
target={"AAPL": 0.5, "MSFT": 0.5},
)
๐ REST API & Webhooks
# Signal endpoint
GET /api/signal?ticker=AAPL&strategy=momentum
# Backtest endpoint
GET /api/backtest?ticker=AAPL&strategy=mean_reversion&start=2020-01-01
# Portfolio optimization
GET /api/portfolio?tickers=AAPL,MSFT,GOOGL&method=risk_parity
# Stock screening
GET /api/screen?rsi_lt=30&volume_gt=1.5
Webhook support for Slack, Discord, and Teams:
from src.api.webhooks import WebhookManager
wh = WebhookManager()
wh.register("signal_change", "https://hooks.slack.com/...", format="slack")
wh.register("alert_triggered", "https://discord.com/api/webhooks/...", format="discord")
๐ Screening & Alerts
from src.screener import StockScreener
from src.alerts import AlertEngine, AlertCondition
screener = StockScreener()
oversold = screener.screen({"rsi_lt": 30, "volume_gt": 1.5})
engine = AlertEngine()
engine.add(AlertCondition(ticker="AAPL", field="rsi", op="<", value=30))
alerts = engine.check()
๐ Performance Benchmarks
Tested on real market data (2019-2024):
| Metric | FinClaw Combiner | Buy & Hold (SPY) |
|---|---|---|
| Annualized Return | 29.1% | 14.2% |
| Sharpe Ratio | 1.42 | 0.85 |
| Max Drawdown | -18.3% | -33.9% |
| Win Rate | 58% | โ |
Results from walk-forward backtests on 100+ tickers across US, China A-shares, and Hong Kong markets.
๐ฅ Comparison with Alternatives
| Feature | FinClaw | Zipline | Backtrader | QuantConnect |
|---|---|---|---|---|
| Zero heavy deps | โ NumPy only | โ Pandas ecosystem | โ Matplotlib etc. | โ Cloud platform |
| Built-in strategies | 6 + combiner | โ DIY | โ DIY | โ Community |
| ML pipeline | โ Integrated | โ | โ | โ |
| Walk-forward | โ | โ | โ | โ |
| Monte Carlo | โ | โ | โ | โ |
| REST API | โ Built-in | โ | โ | โ Cloud |
| Webhooks | โ Slack/Discord/Teams | โ | โ | โ |
| Risk management | โ Kelly/VaR/Sizing | Basic | Basic | โ |
| Python version | 3.9+ | 3.8 (unmaintained) | 3.6+ | 3.8+ |
| Self-hosted | โ | โ | โ | โ Cloud only |
| License | AGPL-3.0 | Apache-2.0 | GPL-3.0 | Proprietary |
๐ Project Structure
finclaw/
โโโ src/
โ โโโ ta/ # 17 technical indicators (pure NumPy)
โ โโโ strategies/ # 6 strategies + combiner
โ โโโ backtesting/ # Walk-forward, Monte Carlo, multi-TF
โ โโโ risk/ # Kelly, VaR, position sizing, stop-loss
โ โโโ ml/ # Features, models, alpha, sentiment
โ โโโ portfolio/ # Tracker, rebalancer
โ โโโ api/ # REST server + webhooks
โ โโโ screener/ # Stock screening
โ โโโ alerts/ # Alert engine
โ โโโ analytics/ # Attribution, correlation, regime
โ โโโ data/ # Price data providers
โ โโโ events/ # Event bus
โ โโโ pipeline/ # Data pipeline + cache
โ โโโ ...
โโโ agents/ # AI agent layer (signal engines, backtester)
โโโ tests/ # 100+ tests
โโโ examples/ # Example scripts
โโโ docs/ # Full documentation
โโโ finclaw.py # CLI entry point
๐บ๏ธ Roadmap
- v1.0 โ Core engine + 3 strategies
- v1.3 โ Enhanced backtesting (walk-forward, Monte Carlo)
- v1.5 โ Risk management (Kelly, VaR, sizing)
- v1.7 โ ML pipeline + technical analysis
- v1.8 โ Portfolio management + API + webhooks
- v1.9 โ Documentation, examples, integration tests
- v2.0 โ Live trading via broker APIs
- v2.1 โ Real-time streaming data
- v2.2 โ Web dashboard
- v3.0 โ Multi-asset (options, futures, crypto derivatives)
๐ค Contributing
See CONTRIBUTING.md for guidelines.
git clone https://github.com/NeuZhou/finclaw.git
cd finclaw
pip install -e ".[dev]"
pytest
๐ License
AGPL-3.0 โ Free for personal and open-source use. Commercial use requires a license.
๐ Ecosystem
| Project | Description |
|---|---|
| AgentProbe | ๐ฌ Playwright for AI Agents โ testing & observability |
| ClawGuard | ๐ก๏ธ AI Agent Security Scanner |
| repo2skill | โก Convert repos to AI Agent Skills |
โญ Star History
If FinClaw helps your research or trading, please โญ the repo!
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 finclaw_ai-2.3.0.tar.gz.
File metadata
- Download URL: finclaw_ai-2.3.0.tar.gz
- Upload date:
- Size: 235.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52f8dbf84271a918a101a24ffdae72d3ffb2443128a7457135dfed9f8124597e
|
|
| MD5 |
b780257428bf89cc488176e8f97a5898
|
|
| BLAKE2b-256 |
d6f7d82f69be1b8fb1795a00f8772db26ea79fdf4112b5a25c42fc029e95880a
|
Provenance
The following attestation bundles were made for finclaw_ai-2.3.0.tar.gz:
Publisher:
publish.yml on NeuZhou/finclaw
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
finclaw_ai-2.3.0.tar.gz -
Subject digest:
52f8dbf84271a918a101a24ffdae72d3ffb2443128a7457135dfed9f8124597e - Sigstore transparency entry: 1109730778
- Sigstore integration time:
-
Permalink:
NeuZhou/finclaw@38a97c76561dfa042542b3a1ebcbc01023579991 -
Branch / Tag:
refs/tags/v2.3.0 - Owner: https://github.com/NeuZhou
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@38a97c76561dfa042542b3a1ebcbc01023579991 -
Trigger Event:
push
-
Statement type:
File details
Details for the file finclaw_ai-2.3.0-py3-none-any.whl.
File metadata
- Download URL: finclaw_ai-2.3.0-py3-none-any.whl
- Upload date:
- Size: 212.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
999212f7be0a741f26284cd6c34ff7b432058c6881f329d4d17c39009d11b0b5
|
|
| MD5 |
e9e89aad99f8f6ef1d25af55453d6998
|
|
| BLAKE2b-256 |
4efece29486a810b9918eaabfbda8168865332985e998f234645801167f610cb
|
Provenance
The following attestation bundles were made for finclaw_ai-2.3.0-py3-none-any.whl:
Publisher:
publish.yml on NeuZhou/finclaw
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
finclaw_ai-2.3.0-py3-none-any.whl -
Subject digest:
999212f7be0a741f26284cd6c34ff7b432058c6881f329d4d17c39009d11b0b5 - Sigstore transparency entry: 1109730783
- Sigstore integration time:
-
Permalink:
NeuZhou/finclaw@38a97c76561dfa042542b3a1ebcbc01023579991 -
Branch / Tag:
refs/tags/v2.3.0 - Owner: https://github.com/NeuZhou
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@38a97c76561dfa042542b3a1ebcbc01023579991 -
Trigger Event:
push
-
Statement type: