alphakiln

mcp
Guvenlik Denetimi
Basarisiz
Health Gecti
  • License — License: Apache-2.0
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Community trust — 22 GitHub stars
Code Basarisiz
  • rm -rf — Recursive force deletion command in .github/workflows/ci.yml
Permissions Gecti
  • Permissions — No dangerous permissions requested

Bu listing icin henuz AI raporu yok.

SUMMARY

AI-native, 100% local quantitative research harness — end-to-end factor mining, causal evaluation, synthesis & backtest via CLI and MCP.

README.md

AlphaKiln

An AI-native, end-to-end quantitative research harness — one closed loop from Factor Mining → Factor Evaluation → Factor Synthesis → Local Backtest via CLI and MCP.

100% Local & Offline · Zero Telemetry / Zero Data Upload · Once dependencies are installed, the full workflow runs air-gapped (network access occurs only when you opt in to fetch optional public market benchmarks)

English · 简体中文

CI
Version
Python 3.11–3.12
Apache-2.0

AlphaKiln architecture from AI agents through the CLI and quantitative core to local evidence and a read-only dashboard

End-to-End Quantitative Workflow

1. Factor Mining

Automated search without brittle manual formulas.

  • PyTorch DSO (policy search with structural priors) + DEAP GP (genetic programming meld) + QuantaAlpha proposal gate
  • Compiles passing candidates into standalone, auditable FactorBase modules
  • Extra: [mining] (torch, deap) · Entry: symbolic-factor-mining · run_symbolic_factor_mining.py

2. Factor Evaluation & Anti-Overfitting

Blocks lookahead bias and lucky-trial inflation.

  • Unified daily cross-section & minute-Bar evaluation: Rank IC / ICIR, quantile long-short, directional hit rate
  • Causal Gate (lookahead rejection) + Purged OOS + Rank IC / ICIR + Adaptive HAC + Moving-Block Bootstrap v2 + TrialLedger (Holm / BH) + calibration_status
  • Extra: Core · Entry: single-factor-analysis / time-series-analysis · Evaluation policy · Evaluation engine

3. Factor Synthesis

Controls collinearity and signal-to-execution drift.

  • Weighted Sum · LASSO · ElasticNet · LightGBM (plus Ridge / PCA / Dynamic Blend / Size-Conditional)
  • Purged rolling splits + approximate DSR / correlation pre-screening → immutable SHA-256 StrategyBundle
  • Extra: [synthesis] · Entry: factor-synthesis · Synthesis guide

4. Local Backtest

Bridges factor metrics to local portfolio execution.

  • VectorBT + DuckDB local backtest engine sharing the unified ExecutionScheduler clock
  • Supports equity cross-sections and single-account futures (session rolls, margin caps, lot rounding), with cross-market signal_export / jq_cloud export & offline alignment verification
  • Extra: [backtest] · Entry: export-strategy / verify-target-alignment · Custom market & deploy guide · JoinQuant adapter

Why AlphaKiln?

Most open-source quant projects excel at one isolated layer while leaving three recurring gaps in day-to-day factor research:

  1. Fragmented toolchains & signal-to-execution clock drift: Mining scripts, research notebooks, and backtesters often assume different timestamps or return conventions. AlphaKiln aligns them through one ExecutionScheduler clock and local DuckDB contracts across daily cross-sections and intraday Bars.
  2. Hidden lookahead & multiple-testing significance inflation: Unverified feature engineering leaks future prices, while repeated screening inflates naive p-values. Built-in Causal Gate, Purged OOS, Adaptive HAC, Moving-Block Bootstrap v2, TrialLedger (Holm / BH), and explicit calibration_status gates filter fragile candidates before synthesis.
  3. No auditable, deterministic execution surface for AI agents: Interactive notebooks are hard for autonomous agents to verify reliably. Every command exposes strict JSON output, --dry-run preflight plans, deterministic exit codes, and a local stdio MCP server.

How AlphaKiln Fits the Ecosystem

AlphaKiln is built to complement existing open-source quant tools rather than replace them—supplying the shared execution clock, causal and calibration-aware evaluation engine, and deterministic CLI/MCP layer around them.

Ecosystem Tool Integration How They Work Together
VectorBT Built-in ([backtest]) Runs underneath our local backtester on one ExecutionScheduler clock and DuckDB contract
Alphalens Aligned & extended Keeps daily tear-sheet semantics while adding lookahead, bootstrap, and multiple-testing gates
Qlib Adapter ([qlib]) Connects Qlib models and datasets to our causal and calibration-aware evaluation gates
RD-Agent Paired harness RD-Agent drives hypothesis evolution; AlphaKiln executes deterministic JSON CLI & MCP checks
TradingAgents Orthogonal signals Pairs LLM textual/fundamental signals with local PIT numerical factor pipelines

60-Second Quickstart

100% local & offline (zero telemetry): All core workflows — synthetic demos, DuckDB storage, Causal Gate, evaluation, synthesis, local backtesting, CLI, and the stdio MCP server — run completely offline on your machine with zero telemetry and zero data upload (network access is used only if you explicitly download optional [markets] datasets).

Environment: Python 3.11–3.12 (Python 3.13 is not yet supported). Install inside an isolated virtual environment — uv venv --python 3.12 --seed is recommended (~4s install). See the English Getting Started guide for connecting your own CSV/DuckDB data and custom factors.

Platform support: macOS and Linux (Python 3.11–3.12) pass CI; on Windows, the core CLI and cross-platform file locking (utils/file_lock.py via msvcrt.locking) are implemented and verified under fcntl-disabled simulation tests, while native Windows end-to-end CI validation is still in progress. For the full CI-verified experience on Windows, we recommend running under WSL2 with Python 3.11–3.12.

Clone the repository on macOS or Linux, then choose uv (recommended) or pip.

git clone https://github.com/GSX-Eis/alphakiln.git
cd alphakiln

uv (recommended, ~4s install)

uv venv --python 3.12 --seed
source .venv/bin/activate
uv pip install '.[synthesis,backtest,viz]'

pip

python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install '.[synthesis,backtest,viz]'

When the distribution is available on PyPI, use python3 -m pip install 'alphakiln[synthesis,backtest,viz]' or uv pip install 'alphakiln[synthesis,backtest,viz]'.

Optional extras reference

Install only the extras your workflow needs (python3 -m pip install '.[<extra>]', or 'alphakiln[<extra>]' once published on PyPI):

Extra Enables Install command
Core Daily & minute-Bar evaluation, Causal Gate, import-demo, mining-demo, read-bar-evaluations, DuckDB store python3 -m pip install '.'
[mining] PyTorch DSO policy search & DEAP GP symbolic mining (symbolic-factor-mining) python3 -m pip install '.[mining]'
[synthesis] LASSO, ElasticNet, LightGBM, PCA, Dynamic Blend & factor-synthesis-demo python3 -m pip install '.[synthesis]'
[backtest] VectorBT local portfolio backtest engine & backtest-demo python3 -m pip install '.[backtest]'
[markets] Public market extractors (Kenneth French, Binance Vision, AKShare) python3 -m pip install '.[markets]'
[viz,mcp] Read-only Streamlit dashboard (dashboard) & stdio MCP server (alphakiln-mcp) python3 -m pip install '.[viz,mcp]'
[qlib] Qlib adapter (pyqlib, filelock) python3 -m pip install '.[qlib]'
[acceleration] Numba kernel acceleration python3 -m pip install '.[acceleration]'
[dev] Pytest suite (pytest, pytest-xdist, alphalens-reloaded) python3 -m pip install '.[dev]'
[all] All optional extras (subject to platform Torch/Qlib wheel availability) python3 -m pip install '.[all]'

Run these independent synthetic demos across all 5 workflow stages (data import, mining, evaluation, synthesis, and local backtest) from a writable directory. Each demo runs on self-contained synthetic fixtures and allocates fresh run directories (only read-bar-evaluations and dashboard consume bar-demo's DuckDB); backtest-demo requires [backtest] and compiles VectorBT/Numba caches once on its first cold run (~20–25s), while warm-cache core execution finishes in <1s.

alphakiln import-demo > import.json
alphakiln mining-demo > mining.json
alphakiln daily-demo > daily.json
alphakiln bar-demo > bar.json
alphakiln factor-synthesis-demo --method weighted_sum > synthesis.json
alphakiln backtest-demo > backtest.json
db="$(python3 -c 'import json; print(json.load(open("bar.json"))["metrics"]["results_db"]["path"])')"
alphakiln read-bar-evaluations --results-db "$db" > bar-read.json
alphakiln dashboard --results-db "$db" --dry-run
# Drop --dry-run to open the read-only dashboard at http://127.0.0.1:8501.

The Bar response includes this diagnostic for the 1-Bar horizon, excerpted from a synthetic run.

{
  "ok": true,
  "exit_code": 0,
  "metrics": {
    "diagnostics_report": {
      "schema": "time_series_diagnostics.v1",
      "horizons": [
        {
          "horizon_bars": 1,
          "ic": {"sample_count": 239, "spearman_ic": 0.5012956647093985, "reason": null},
          "bootstrap": {
            "block_length": 27,
            "n_boot": 999,
            "valid_replicates": 999,
            "lower": 0.46960199268106917,
            "upper": 0.5448401913479641,
            "reason": null
          },
          "interval_usability": {"descriptive_stats_usable": true}
        }
      ]
    }
  },
  "next_actions": ["Pass metrics.results_db.path to read-bar-evaluations --results-db."]
}

The AI workflow showcase follows several candidates through preflight, calibration and trial gates, synthesis, a toy backtest and DuckDB read-back.

For a self-contained intraday futures fixture (single-contract NQZ26 1m bars on CMEGlobex_Equity with ETH / RTH session views), see the NQ 1min ETH/RTH example:

python3 -m tools.agent_harness.cli time-series-analysis --config examples/nq_intraday_futures/eval_eth.json --output-dir work/nq-eth-eval
python3 -m tools.agent_harness.cli time-series-analysis --config examples/nq_intraday_futures/eval_rth.json --output-dir work/nq-rth-eval

AI Agent & CLI Interface

Agent Skill & Claude Code Plugin

Copy the entire Factor Research Skill directory, including its references, into your client's skills directory. With Claude Code, run claude --plugin-dir . from the checkout to load the plugin manifest and invoke /alphakiln:factor-research. See AGENTS.md or CLAUDE.md for project instructions.

Stdio MCP Server

With uvx on the MCP client's PATH, add this entry to mcpServers in Claude Desktop, Cursor, Claude Code or Windsurf, and replace /path/to/alphakiln with your local checkout path (once published on PyPI, replace it with alphakiln[mcp,synthesis,backtest]). The [synthesis] and [backtest] extras let the server run run_factor_synthesis_demo and run_backtest_demo.

{
  "mcpServers": {
    "alphakiln": {
      "command": "uvx",
      "args": ["--python", "3.12", "--from", "/path/to/alphakiln[mcp,synthesis,backtest]", "alphakiln-mcp"]
    }
  }
}

The server runs locally. Use absolute paths for tool inputs. See the CLI and MCP mapping.

Two-Tier CLI (alphakiln & Full Harness)

AlphaKiln exposes a two-tier CLI, with strict JSON output and --dry-run preflight across commands:

  • Public agent CLI (alphakiln): 10 focused commands covering end-to-end demos (import-demo, mining-demo, daily-demo, bar-demo, factor-synthesis-demo, backtest-demo), local evaluation (single-factor-analysis, time-series-analysis), DuckDB read-back (read-bar-evaluations), and the local viewer (dashboard), with --compact single-line JSON output. See the CLI and MCP mapping.
  • Full research harness (python3 -m tools.agent_harness.cli): 21 subcommands for external orchestrators and multi-market pipelines, alongside standalone research entry points (run_analysis_main.py, run_factor_synthesis.py, run_symbolic_factor_mining.py). See public scope.
Full Harness CLI command reference (21 commands)
Group Commands
Market DB & bar governance market-db (init / adopt / show / migrate-profile), import-bars, build-bars, audit-bars, build-roll-schedule
Factor value store write-factor-values, read-factor-values, verify-factor-values
Evaluation, causal gate & queries single-factor-analysis, time-series-analysis, verify-factor-causality, read-bar-evaluations
Symbolic mining & screening symbolic-factor-mining, quanta-alpha-realize, parent-factor-screen
Synthesis & deployment alignment factor-synthesis, export-strategy, verify-target-alignment, alignment-run
Monitoring & cleanup monitor-refresh, outputs-gc
# Export and verify portable cross-market target positions and orders from a StrategyBundle
python3 -m tools.agent_harness.cli export-strategy --target signal_export \
  --bundle-dir "$BUNDLE_DIR" --output-dir work/signal-candidate
python3 -m tools.agent_harness.cli verify-target-alignment --target signal_export \
  --bundle-dir "$BUNDLE_DIR" --artifact-dir work/signal-candidate
Copy a research prompt
Use the Factor Research Skill and run the AI workflow showcase in a fresh
writable directory. Freeze the hypothesis, candidates, split and screening
rule. Use only synthetic data. Preflight each evaluation, capture stdout and
stderr, and report the IC and sample count, null reasons, calibration status
and complete trial family. Combine only the candidates eligible for the
synthetic backtest. Verify the DuckDB and dashboard plan. Report rejected
candidates, artifact paths, and whether the evidence permits a significance claim.

Multi-Market Data & Public Benchmarks

Declarative Multi-Market Adapters (slot.yaml)

Connect local CSV, Parquet or DuckDB feeds without writing a custom Python adapter by declaring a versioned slot.yaml, or use built-in native market slots:

Market Coverage Adapter Guide
China A-shares (daily / minute) XSHG / XSHE with point-in-time adjustment and microstructure rules Native jq_ashare_local or CSV / DuckDB Local workflow · Stock pools
US equities & global indices XNYS / XNAS with verified PMC calendars and DST handling Declarative slot.yaml + MarketDB profile Market database guide · Config reference
Domestic & global futures CME / SHFE / INE / DCE / CZCE / CFFEX / GFEX (ETH/RTH & session rolls) Native cn_futures / global_futures or declarative slot.yaml NQ 1min ETH/RTH example · Trading calendar
24/7 crypto & custom markets Arbitrary timezones, 24/7 sessions, and auxiliary series such as funding rates Zero-code declarative slot.yaml Crypto example · Custom market & deploy guide

10-Minute Reproducible Public Benchmark ([markets], No AI Assistant Required)

Install .[markets] to download, SHA-256 freeze, and build three reproducible public market DuckDBs with versioned MarketDB profiles (enforcing single-market isolation against accidental cross-database mixing) — add [synthesis] (python3 -m pip install '.[markets,synthesis]') if you also want to render the evaluation plot with --plot-out:

  • Kenneth R. French: 49 industry portfolios + FF3 daily series (since 1963)
  • Binance Vision: 10 USDT spot pairs at 1min and derived 1d bars
  • AKShare: China broad-based indices and Shenwan Level-1 industry daily indices

Run the end-to-end Kenneth French 49-industry 12–1 month momentum evaluation directly from the CLI (~3 min to download & build DuckDB + ~15s for Causal Gate & cross-sectional evaluation), or open the step-by-step French quickstart notebook (also see Getting Started (EN)):

python3 -m pip install '.[markets,synthesis]'
python3 -m data_pipeline.extractors.public_markets.french \
  --work-dir work/french --db work/french/market.duckdb
python3 -m examples.french_industry_momentum \
  --work-dir work/french --plot-out work/french/evaluation-result.png

Real exploratory output from french_industry_momentum.py across default horizons (1d, 5d, 20d) on Kenneth R. French 49 US value-weighted industry portfolios (2022-01-03 to 2026-09-30; upstream Kenneth French ZIP snapshot date 2026-11-24 — upstream historical revisions may slightly shift trailing digits of the 1d metrics; Causal Gate passed, trial_selection={"method": "holm"} family complete). Per evaluation policy, causal_gate.ok establishes non-lookahead compliance rather than statistical significance: raw nw94_prewhitened Adaptive HAC p_value and Holm adjusted_p_value below are diagnostic (calibration_status: "uncalibrated", significance_interpretation_usable: false, significant: false, not calibrated_pass), and quintile curves in the chart are descriptive close-only uncosted buckets rather than a tradable backtest:

{
  "ok": true,
  "dataset": "kf_us_portfolios_v1",
  "evaluation_scope": "exploratory_diagnostic_uncalibrated",
  "factor": "industry_momentum_252_21",
  "start_date": "2022-01-03",
  "end_date": "2026-09-30",
  "instruments": 49,
  "causal_gate": {"ok": true, "status": "passed", "resolved_mode": "vectorized"},
  "horizons": [
    {
      "horizon_bars": 1,
      "valid_cross_sections": 1189,
      "mean_spearman_ic": 0.031506513858631645,
      "adaptive_hac": {"lag": 16, "t_stat": 4.3228540587243085, "p_value": 3.52900069524004e-05},
      "holm": {"method": "holm", "adjusted_p_value": 0.00010587002085720121, "significant": false},
      "interval_usability": {"calibration_status": "uncalibrated", "descriptive_stats_usable": true, "significance_interpretation_usable": false}
    },
    {
      "horizon_bars": 5,
      "valid_cross_sections": 1185,
      "mean_spearman_ic": 0.039823043141307156,
      "adaptive_hac": {"lag": 49, "t_stat": 2.8490549593115566, "p_value": 0.00728710591904723},
      "holm": {"method": "holm", "adjusted_p_value": 0.01457421183809446, "significant": false},
      "interval_usability": {"calibration_status": "uncalibrated", "descriptive_stats_usable": true, "significance_interpretation_usable": false}
    },
    {
      "horizon_bars": 20,
      "valid_cross_sections": 1170,
      "mean_spearman_ic": 0.03989647653933368,
      "adaptive_hac": {"lag": 33, "t_stat": 1.2695351729658155, "p_value": 0.21002508753263233},
      "holm": {"method": "holm", "adjusted_p_value": 0.21002508753263233, "significant": false},
      "interval_usability": {"calibration_status": "uncalibrated", "descriptive_stats_usable": true, "significance_interpretation_usable": false}
    }
  ]
}

Why is "significant": false shown even when 1d adjusted_p_value (0.000106) < 0.05? Because the 49-industry cross-section is outside the pre-registered simulation calibration grid, the gate conservatively outputs calibration_status: "uncalibrated" and suppresses significant: true rather than claiming calibrated significance—this is intentional gate conservatism, not a p-value calculation error.

Kenneth French 49 US Industry Portfolios 12-1 Month Momentum Evaluation

See public market databases for Binance / AKShare rebuild commands, snapshot verification, and upstream data terms.

Persistent Bar & Factor Storage

When scaling beyond single CSV runs, store validated bars and futures roll schedules in profile-checked DuckDB (import-bars, build-bars, audit-bars, build-roll-schedule), and persist cross-frequency factor values in MarketFactorValueStore (Hive-partitioned Parquet + append-only JSONL ledgers + read-only DuckDB views via write-factor-values / read-factor-values / verify-factor-values). See the Bar and storage contract, factor interface, factor template, data semantics, cache invalidation, and canonical data reads.

Feedback & Community

Open an issue to report a bug, request a market calendar or data contract, or share an AI workflow. Share synthetic or sanitized examples. See contributing, security, and the changelog.

Licensed under the Apache License 2.0. See NOTICE for attribution.

Yorumlar (0)

Sonuc bulunamadi