Skip to main content

📈 SimTradeLab

English | 中文 | Deutsch

Lightweight Quantitative Backtesting Framework — Local PTrade API Simulation

Python License License: Commercial Version PyPI PyPI - Downloads

Local compatibility for a tested subset of PTrade backtest APIs. Portability depends on the APIs and broker behavior a strategy uses; review the support matrix. See also: ptradeAPI


🎯 Why SimTradeLab?

SimTradeLab PTrade
Speed 100–160x faster Baseline
Startup Sub-second (data persists in memory) Minutes
API Coverage See the tested support matrix Full platform
Strategy Porting Depends on the tested API subset Native platform
Environment Local, free, open-source Cloud, licensed

Core capabilities:

  • ✅ Tested API classifications — current full, partial, pending, and unsupported behavior is tracked in the support matrix
  • ⚡ 100–160x faster than PTrade platform
  • 🚀 In-memory data persistence — singleton pattern, sub-second startup after first load
  • 💾 Multi-level caching — LRU caches for MA/VWAP/adjustment factors/history, >95% hit rate
  • 🧠 Smart data loading — AST analysis of strategy code, loads only required data
  • 🔧 Lifecycle control — 7 lifecycle phases, strict simulation of PTrade's API restrictions
  • 📊 Full stats reporting — returns, risk metrics (Sharpe/Sortino/Calmar), trade details, FIFO dividend tax, CSV export
  • 🔌 Multi-market — Built-in CN (A-shares) and US market profiles with automatic trading rule adaptation
  • 🌐 i18n — Backtest output in Chinese, English, or German

🚀 Need More? Try SimTradeDesk

SimTradeDesk is a professional desktop application built on SimTradeLab — no coding required.

Feature SimTradeLab (this repo) SimTradeDesk
Target users Developers & quant engineers All traders
Interface Python API Desktop GUI
Strategy editing Code editor Built-in editor with syntax highlighting
Visualization PNG charts Interactive real-time charts
Data management Manual setup One-click download & update
Parameter tuning Write code Visual optimizer

👉 Get SimTradeDesk →


📦 Quick Start

pip install simtradelab

# Optional: technical indicators (requires system ta-lib)
pip install simtradelab[indicators]

# Optional: parameter optimizer
pip install simtradelab[optimizer]

Verify the installed command-line entry point:

simtradelab --help
simtradelab --version

Data: Use SimTradeData to download China A-share and US stock historical data.

Strategy environment: Read the strategy runtime boundaries before using files, external datasets, or network libraries in strategy code.

Run a backtest:

from simtradelab.backtest.runner import BacktestRunner
from simtradelab.backtest.config import BacktestConfig

config = BacktestConfig(
    # --- Required ---
    strategy_name='my_strategy',       # Strategy folder name under strategies/
    start_date='2024-01-01',           # Backtest start date
    end_date='2024-12-31',             # Backtest end date

    # --- Capital & Market ---
    initial_capital=100000.0,          # Starting capital (must be > 0)
    market='CN',                       # Market: 'CN' (A-shares) | 'US'
    broker_profile='auto',             # Broker API profile: 'auto' | 'guosheng' | 'dongguan' | 'shanxi'
    t_plus_1=None,                     # T+1 override: None=market default (CN=True, US=False)
    benchmark_code='',                 # Benchmark code, empty=market default

    # --- Frequency ---
    frequency='1d',                    # Bar frequency: '1d' (daily) | '1m' (minute)

    # --- Paths ---
    data_path='~/.simtradelab/data',   # Market data directory
    strategies_path='./strategies',    # Strategies root directory

    # --- Performance ---
    enable_multiprocessing=True,       # Enable parallel data loading
    num_workers=None,                  # Worker count (None=auto, must be >= 1)
    use_data_server=True,              # Use in-memory data server (singleton)

    # --- Output ---
    enable_charts=True,                # Generate PNG chart
    enable_logging=True,               # Write log file
    enable_export=False,               # Export trade details to CSV

    # --- i18n ---
    locale='auto',                     # Log language: 'zh' | 'en' | 'de' (auto: CN market→zh, else system locale)
    optimization_mode=False,           # Optimization mode: skip validation/logging (managed by optimizer)

    # --- Entry file ---
    strategy_file='backtest.py',       # Entry file: 'backtest.py' | 'live.py'
)
runner = BacktestRunner()
report = runner.run(config=config)

📚 API Overview

See the tested PTrade backtest API support matrix for the current classifications and behavioral evidence.

Category APIs
Trading order, order_target, order_value, order_target_value, cancel_order, get_positions, get_trades
Data get_price, get_history, get_fundamentals, get_stock_info
Sector get_index_stocks, get_industry_stocks, get_stock_blocks
Indicators get_MACD, get_KDJ, get_RSI, get_CCI
Config set_benchmark, set_commission, set_slippage, set_universe, set_parameters
Lifecycle initialize, before_trading_start, handle_data, after_trading_end

📄 License

Dual license model:


🤝 Contributing

  • 🐛 Report issues
  • 💻 Implement missing API features
  • 📚 Improve documentation

See CONTRIBUTING.md for CLA details.


⚖️ Disclaimer

SimTradeLab is a community-developed, open-source backtesting framework inspired by PTrade's event-driven design. It does not contain PTrade's source code, trademarks, or any protected content. This project is not affiliated with or endorsed by PTrade. Users are responsible for compliance with local regulations and platform terms.


⭐ Star this project if you find it useful!

🐛 Report Issue | 💡 Feature Request | 🖥️ SimTradeDesk


💖 Sponsor

If this project helps you, consider sponsoring!

WeChat Pay Alipay

Metadata

Release files for simtradelab 2.13.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simtradelab 2.13.8
File Size Uploaded Provenance Actions
simtradelab-2.13.8.tar.gz 133.5 kB With provenance Details for simtradelab-2.13.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for simtradelab 2.13.8
File Interpreter ABI Platform Actions
simtradelab-2.13.8-py3-none-any.whl Python 3 none any Details for simtradelab-2.13.8-py3-none-any.whl

Total release size: 291.9 kB

Release files / simtradelab-2.13.8.tar.gz

Download URL simtradelab-2.13.8.tar.gz
Size 133.5 kB
Tags Source
SHA-256 checksum
How to use checksums
993c465664246e691deca46dc65d82e35a07dfa46953c2a3820e8024d1af5d9f
BLAKE2b-256 checksum
How to use checksums
8608b1f8c5a896d3e8aee05e374609010d12fa2f8c4d676c01ef7e61778a7db5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Release files / simtradelab-2.13.8-py3-none-any.whl

Download URL simtradelab-2.13.8-py3-none-any.whl
Size 158.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4cfd74dcb0df75b7d908d9bb6c1a83795110b13157143cff3266f02ec89ce41d
BLAKE2b-256 checksum
How to use checksums
cc666b5e5c2f50f7f13e06a76b819ac9d5c924742cc8dc74faee27393e4a8255
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Security for simtradelab 2.13.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for simtradelab-2.13.8.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.13.8 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page