Skip to content

FeiCoder/BreadFree-Simu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BreadFree - Flexible A-Share Quant Research Platform

BreadFree is a modular, event-driven quantitative trading research platform designed for the A-share market. It separates the execution engine from strategy logic, allowing researchers to flexibly switch between classic algorithmic strategies, simple rotation models, and complex LLM-driven agent systems.

1. Project Architecture (核心架构)

The system is built around a central event loop in main.py -> breadfree/engine/backtest_engine.py that feeds data to pluggable strategy modules.

graph TD
    CLI["main.py CLI / config.yaml"] --> Engine[BacktestEngine]
    Data["DataFetcher (AkShare)"] -->|"Cache & Warmup"| Engine
    
    Engine -->|"On Bar (Daily)"| Strategy[Strategy Interface]
    
    subgraph Pluggable Strategies
        Strategy --> Rotation[RotationStrategy]
        Strategy --> Agent["AgentStrategy (LLM)"]
        Strategy --> DMA[DoubleMAStrategy]
        Strategy --> Bench[BenchmarkStrategy]
    end
    
    Rotation -->|"Signals"| Broker["Broker & Execution"]
    Agent -->|"Signals"| Broker
    DMA -->|"Signals"| Broker
    
    Broker -->|"Account State"| Engine
    Engine -->|"Logs & Metrics"| Output["Visualization & Reports"]
Loading

Core Components used in main.py

  • Engine (breadfree/engine): Handles data feeding, time-stepping, and interaction between strategy and broker.
  • Strategies (breadfree/strategies): Contains logic implementations. All inherit from BaseStrategy.
  • Data (breadfree/data): Wraps AkShare for fetching and caching local CSVs to speed up backtests.
  • Utils: Configuration, logging, and plotting (Pyecharts).

2. Supported Strategies (支持的策略)

You can switch strategies using the --strategy flag in main.py.

A. RotationStrategy (Core Focus)

A momentum and efficiency-based rotation strategy for ETFs or stocks.

  • Logic: Selects top_n assets based on recent returns (lookback_period) and holds them for hold_period.
  • Key Params: --lookback_period, --hold_period, --top_n, --use_efficiency.
  • Use Case: Sector rotation, ETF momentum.

B. AgentStrategy (LLM Powered)

A multi-agent system simulating an investment committee using LangGraph.

  • Roles: Analyst -> Risk Manager -> Fund Manager.
  • Features: Reads news, reasons about market sentiment, and adheres to distinct personas.
  • Configuration: Requires LLM API keys.

C. Classic Strategies

  • DoubleMAStrategy: Golden cross/Dead cross logic with short and long windows.
  • BenchmarkStrategy: Simple Buy-and-Hold on a target asset (e.g., HS300) to baseline performance.

3. Workflow & Usage (使用流程)

1. Installation

pip install uv
uv sync
source .venv/bin/activate

2. Configuration

Configure global settings in breadfree/config.yaml (e.g., initial cash, default stock pool).

3. Running Backtests

The entry point main.py unifies the execution.

Run Rotation Strategy (Example):

python main.py --strategy RotationStrategy \
    --lookback_period 20 --hold_period 20 --top_n 3 \
    --output_file output/rotation_result.png

Run Benchmark (Buy & Hold):

python main.py --strategy BenchmarkStrategy --output_file output/benchmark_result.png

Run LLM Agent Strategy:

python main.py --strategy AgentStrategy

4. Analysis

  • HTML Reports: Interactive charts generated in the root directory (e.g., backtest_result.html).
  • Logs: Detailed execution logs in logs/.
  • Grid Search: Use grid_search.sh to optimize parameters for RotationStrategy.

4. Development Status

  • Completed:

    • Unified BacktestEngine supporting T+1 simulation.
    • Modular Strategy Interface (BaseStrategy).
    • Robust Data Fetching with caching (AkShare).
    • Strategy Implementations: Rotation, MA, Agent (LLM).
    • Visualization with Pyecharts.
  • Roadmap:

    • Real-time data integration (Tick/Min bars).
    • Notification system (Push messages).
    • Vector DB for news-based historical analogy.
    • Web Dashboard.

5. Disclaimer

This project is for simulation and research purposes only. It does not constitute financial advice.

About

BreadFree-Simu 是一个基于大语言模型(LLM)的 A 股智能量化回测系统。它利用多智能体协作(Multi-Agent)架构,模拟机构投资者的决策流程(分析-风控-决策),旨在探索 AI 在中国特色金融市场(T+1、涨跌停板)中的应用潜力。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors