WA

whchien/ai-trader

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

1131 stars 144 forks 质量 72 趋势 25GPL-3.0

whchien/ai-trader 是从 https://github.com/whchien/ai-trader. 导入的 MCP 服务器候选服务器。

概览

whchien/ai-trader 是从 https://github.com/whchien/ai-trader. 导入的 MCP 服务器候选服务器。

概述(AI 翻译)

中文版說明(中文字幕页)

一个基于Backtrader的专业配置驱动算法交易回测框架。跨股票、加密货币和外汇市场无缝测试、优化并整合大型语言模型(LLM)交易策略。

主要特色

  • 配置驱动工作流:定义和管理可版本控制的YAML文件回测,以实现可复现的结果。
  • 无缝大型语言模型集成:内置MCP(模型上下文协议)服务器允许像Claude这样的AI助手进行回测、获取数据和分析策略。
  • 多市场支持:测试美股、台湾股票、加密货币和外汇策略。
  • 丰富的策略库:内置20多种策略,从经典指标到高级自适应模型。
  • 强大的CLI:丰富的命令行界面,用于运行回测、获取市场数据和列出策略。
  • 开发者友好:通过简单的辅助工具和清晰的结构轻松创建和测试自定义策略。

快速启动

1.安装

选项A:从PyPI安装(推荐使用CLI)

如果你想用,可以用这个:

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

AI-Trader

中文版說明 (Chinese Subpage)

A professional, config-driven backtesting framework for algorithmic trading, built on Backtrader. Seamlessly test, optimize, and integrate trading strategies with Large Language Models (LLMs) across stocks, crypto, and forex markets.

Key Features

  • Config-Driven Workflows: Define and manage backtests with version-controllable YAML files for reproducible results.
  • Seamless LLM Integration: Built-in MCP (Model Context Protocol) server allows AI assistants like Claude to run backtests, fetch data, and analyze strategies.
  • Multi-Market Support: Test strategies on US stocks, Taiwan stocks, cryptocurrencies, and forex.
  • Extensive Strategy Library: Comes with over 20 built-in strategies, from classic indicators to advanced adaptive models.
  • Powerful CLI: A rich command-line interface to run backtests, fetch market data, and list strategies.
  • Developer Friendly: Easily create and test custom strategies with simple helpers and a clear structure.

Quick Start

1. Installation

Option A: Install from PyPI (Recommended for using the CLI)

pip install ai-trader

Use this if you want to:

  • Use the CLI commands: ai-trader run, ai-trader fetch, ai-trader quick
  • Run backtests on your own data files
  • Use as a library in your Python projects

Option B: Install from Source (Recommended for examples and config templates)

git clone https://github.com/whchien/ai-trader.git
cd ai-trader

# Install dependencies (choose one method)
uv sync        # Recommended (fastest, modern tool)
# poetry install   # Or use Poetry
# pip install -e .  # Or traditional pip with editable install

Use this if you want to:

  • Run the config-based examples in config/backtest/
  • Use the example data files in data/
  • Run the example scripts in scripts/examples/
  • Contribute or customize strategies

2. Run a Backtest via CLI

If you cloned from source, run a predefined backtest using a configuration file:

# Run a backtest from a config file (requires source installation)
ai-trader run config/backtest/classic/sma_example.yaml

Or, run a quick backtest on any data file (works with both pip and source installation):

# Quick backtest on your own data file
ai-trader quick CrossSMAStrategy your_data.csv --cash 100000

3. Fetch Market Data

Download historical data for any supported market:

# US Stock (default: saves to CSV)
ai-trader fetch TSM --market us_stock --start-date 2020-01-01

# Taiwan Stock (台灣股票)
ai-trader fetch 2330 --market tw_stock --start-date 2020-01-01

# Cryptocurrency
ai-trader fetch BTC-USD --market crypto --start-date 2020-01-01

# With SQLite persistent caching (NEW!)
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "ai-trader": { "command": "python3", "args": ["-m", "ai_trader.mcp"], "cwd": "/path/to/ai-trader" } } }