Skip to main content

AI-Powered Financial Intelligence Engine - Realistic Backtesting, TCA, Strategy Comparison, ML, 8 Strategies.

Project description

๐Ÿฆ€ FinClaw

CI PyPI License: AGPL v3 Python 3.9+ GitHub Stars

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


Download files

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

Source Distribution

finclaw_ai-2.3.0.tar.gz (235.6 kB view details)

Uploaded Source

Built Distribution

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

finclaw_ai-2.3.0-py3-none-any.whl (212.0 kB view details)

Uploaded Python 3

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

Hashes for finclaw_ai-2.3.0.tar.gz
Algorithm Hash digest
SHA256 52f8dbf84271a918a101a24ffdae72d3ffb2443128a7457135dfed9f8124597e
MD5 b780257428bf89cc488176e8f97a5898
BLAKE2b-256 d6f7d82f69be1b8fb1795a00f8772db26ea79fdf4112b5a25c42fc029e95880a

See more details on using hashes here.

Provenance

The following attestation bundles were made for finclaw_ai-2.3.0.tar.gz:

Publisher: publish.yml on NeuZhou/finclaw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for finclaw_ai-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 999212f7be0a741f26284cd6c34ff7b432058c6881f329d4d17c39009d11b0b5
MD5 e9e89aad99f8f6ef1d25af55453d6998
BLAKE2b-256 4efece29486a810b9918eaabfbda8168865332985e998f234645801167f610cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for finclaw_ai-2.3.0-py3-none-any.whl:

Publisher: publish.yml on NeuZhou/finclaw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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