AI-powered CLI for generating QuantConnect trading algorithms from research articles
This is QuantCoder 2.0 (GAMMA) - The primary development branch with autonomous mode & library builder
Want the original stable version? β QuantCoder 1.0 (main branch)
π Version Comparison Guide | Branch Map
QuantCoder is a command-line tool that allows users to generate QuantConnect trading algorithms from research articles using natural language processing and large language models (LLMs). It was initiated in November 2023 and based on a cognitive architecture inspired by the article "Dual Agent Chatbots and Expert Systems Design"
The initial version successfully coded a blended momentum and mean-reversion strategy as described in "Outperforming the Market (1000% in 10 years)", which received over 10,000 impressions on LinkedIn.
Refactored in December 2025 - Inspired by Mistral's Vibe CLI architecture.
- π€ Interactive Chat Interface with conversational AI
- π οΈ Tool-Based Architecture for modularity and extensibility
- βοΈ Configuration System with TOML support
- π¨ Modern Terminal UI with Rich library
- π Programmable Mode via
--promptflag - πΎ Persistent Context and conversation history
π See full v2.0 documentation β
β Requires Python 3.10 or later
# Clone the repository
git clone https://github.com/SL-Mar/quantcoder-cli.git
cd quantcoder-cli
# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install the package
pip install -e .
# Download SpaCy model
python -m spacy download en_core_web_sm# Launch interactive mode
quantcoder
# Or use the short alias
qcOn first run, you'll be prompted for your OpenAI API key.
QuantCoder offers multiple modes of operation to suit different workflows.
Launch the interactive chat interface for a conversational experience:
# Start interactive mode
quantcoder
# Or use the short alias
qcIn interactive mode, you can use natural language or direct commands:
quantcoder> search "momentum trading strategies"
quantcoder> download 1
quantcoder> summarize 1
quantcoder> generate 1Run commands non-interactively using the --prompt flag:
quantcoder --prompt "Find articles about mean reversion"Search for research articles on CrossRef using keywords.
quantcoder search "algorithmic trading" --num 5Arguments:
query- Search query string (required)
Options:
--num- Number of results to return (default: 5)
Example:
quantcoder search "momentum trading strategies" --num 10Download a research article PDF by its ID from the search results.
quantcoder download 1Arguments:
article_id- ID of the article from search results (required)
Example:
quantcoder download 3Analyze and summarize a downloaded article using AI.
quantcoder summarize 1Arguments:
article_id- ID of the downloaded article (required)
Example:
quantcoder summarize 1Generate trading algorithm code from a research article.
quantcoder generate 1
quantcoder generate 1 --open-in-editor
quantcoder generate 1 --open-in-editor --editor codeArguments:
article_id- ID of the article to generate code from (required)
Options:
--max-attempts- Maximum refinement attempts (default: 6)--open-in-editor- Open generated code in editor (default: false)--editor- Editor to use (e.g., zed, code, vim)
Example:
quantcoder generate 2 --open-in-editor --editor zedValidate algorithm code locally and optionally on QuantConnect.
quantcoder validate generated_code/algorithm_1.py
quantcoder validate my_algo.py --local-onlyArguments:
file_path- Path to the algorithm file (required)
Options:
--local-only- Only run local syntax check, skip QuantConnect validation
Example:
quantcoder validate generated_code/algorithm_1.pyExecute a backtest on QuantConnect with the specified algorithm.
Requirements: Set QUANTCONNECT_API_KEY and QUANTCONNECT_USER_ID in ~/.quantcoder/.env
quantcoder backtest generated_code/algorithm_1.py
quantcoder backtest my_algo.py --start 2022-01-01 --end 2024-01-01Arguments:
file_path- Path to the algorithm file (required)
Options:
--start- Backtest start date in YYYY-MM-DD format (default: 2020-01-01)--end- Backtest end date in YYYY-MM-DD format (default: 2024-01-01)--name- Name for the backtest
Example:
quantcoder backtest my_algo.py --start 2023-01-01 --end 2024-01-01 --name "My Strategy v1"Autonomous mode runs continuously, learning from errors and self-improving strategies over time.
quantcoder auto start --query "momentum trading" --max-iterations 50Options:
--query- Strategy query (e.g., "momentum trading") (required)--max-iterations- Maximum iterations to run (default: 50)--min-sharpe- Minimum Sharpe ratio threshold (default: 0.5)--output- Output directory for strategies--demo- Run in demo mode (no real API calls)
Example:
quantcoder auto start --query "mean reversion" --max-iterations 100 --min-sharpe 1.0Display statistics and learning progress from autonomous mode.
quantcoder auto statusShows:
- Total strategies generated
- Success rate
- Average Sharpe ratio
- Common errors and fix rates
Generate a comprehensive report from autonomous mode runs.
quantcoder auto report --format text
quantcoder auto report --format jsonOptions:
--format- Report format: text or json (default: text)
Library builder mode systematically generates strategies across all major categories.
Build a comprehensive library of trading strategies.
quantcoder library build --comprehensive --max-hours 24
quantcoder library build --categories momentum,mean_reversionOptions:
--comprehensive- Build all categories--max-hours- Maximum build time in hours (default: 24)--output- Output directory for library--min-sharpe- Minimum Sharpe ratio threshold (default: 0.5)--categories- Comma-separated list of categories to build--demo- Run in demo mode (no real API calls)
Example:
quantcoder library build --categories momentum,arbitrage --max-hours 12Display the current progress of library building.
quantcoder library statusResume an interrupted library build from checkpoint.
quantcoder library resumeExport the completed strategy library.
quantcoder library export --format zip --output library.zip
quantcoder library export --format json --output library.jsonOptions:
--format- Export format: zip or json (default: zip)--output- Output file path
Evolution mode uses LLM-generated variations to optimize trading algorithms through structural changes.
Evolve a trading algorithm through multiple generations of variations.
quantcoder evolve start 1
quantcoder evolve start 1 --gens 5
quantcoder evolve start --code algo.py
quantcoder evolve start --resume abc123Arguments:
article_id- Article number to evolve (optional if using --code or --resume)
Options:
--code- Path to algorithm file to evolve--resume- Resume a previous evolution by ID--gens- Maximum generations to run (default: 10)--variants- Variants per generation (default: 5)--elite- Elite pool size (default: 3)--patience- Stop after N generations without improvement (default: 3)--qc-user- QuantConnect user ID (or set QC_USER_ID env var)--qc-token- QuantConnect API token (or set QC_API_TOKEN env var)--qc-project- QuantConnect project ID (or set QC_PROJECT_ID env var)
Example:
quantcoder evolve start 1 --gens 20 --variants 10 --qc-user 123456 --qc-token abc123 --qc-project 789Note: Evolution explores structural variations like:
- Indicator changes (SMA β EMA, adding RSI, etc.)
- Risk management modifications
- Entry/exit logic changes
- Universe selection tweaks
Show all saved evolution runs with their status and performance.
quantcoder evolve listDisplay detailed information about a specific evolution.
quantcoder evolve show abc123Arguments:
evolution_id- The evolution ID to show (required)
Export the best algorithm from an evolution run.
quantcoder evolve export abc123
quantcoder evolve export abc123 --output my_best_algo.pyArguments:
evolution_id- The evolution ID to export from (required)
Options:
--output- Output file path
Display the current QuantCoder configuration.
quantcoder config-showShows:
- Model configuration (provider, model, temperature, max tokens)
- UI configuration (theme, auto-approve, token usage display)
- Tools configuration (directories, enabled tools)
- Paths (home directory, config file)
Display the current version of QuantCoder.
quantcoder versionThese options can be used with any command:
--verboseor-v- Enable verbose logging--config- Path to custom config file--promptor-p- Run in non-interactive mode with a prompt
Example:
quantcoder --verbose search "algorithmic trading"
quantcoder --config my_config.toml generate 1The folder 'Strategies and publications' contains articles and trading strategies generated using this CLI tool. These strategies may have been manually refined or enhanced using LLM-based methods. Use them at your own discretion β conduct thorough research and validate before live use.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.