A comprehensive algorithmic trading system monorepo integrating QuantConnect Lean engine with AI-powered strategy generation and rebate optimization tools.
Trading-System-CI/
βββ docker-compose.yml # Orchestrates all services
βββ lean-core/ # QuantConnect Lean engine
β βββ Dockerfile
β βββ Lean/ # Lean engine submodule
βββ services/
β βββ rebate/ # Rebate optimization sandbox
β β βββ Dockerfile
β β βββ app.py # Streamlit UI with Optuna
β β βββ requirements.txt
β βββ strategy/ # AI strategy generator
β βββ Dockerfile
β βββ generate.py # AI code generation & validation
β βββ requirements.txt
βββ data/ # Shared data directory
The algorithmic trading engine that executes strategies.
- Technology: C# / .NET, Python support
- Purpose: Backtesting and live trading execution
- Base Image:
quantconnect/lean:foundation
Interactive UI for optimizing trading rebate parameters.
- Technology: Streamlit + Optuna
- Port:
8501 - Features:
- Hyperparameter optimization for rebate strategies
- Visual analysis of optimization results
- Parameter importance analysis
- Export optimization data
Generates and validates trading strategies using AI.
- Technology: Python + Anthropic Claude API
- Features:
- Natural language to trading strategy code
- Support for Python and C# strategies
- Automatic code validation
- QuantConnect Lean compatibility checks
- Docker & Docker Compose
- Git (with submodules initialized)
- (Optional) Anthropic API key for AI strategy generation
git clone <your-repo-url>
cd Trading-System-CI
# Initialize Lean submodule if needed
git submodule update --init --recursiveCreate a .env file in the root:
# Optional: For AI strategy generation
ANTHROPIC_API_KEY=your_api_key_here
# Lean engine configuration
LEAN_DATA_DIRECTORY=/Data# Build all services
docker-compose build
# Start all services
docker-compose up
# Or run specific service
docker-compose up rebate- Rebate Optimization UI: http://localhost:8501
- Lean Engine: Running in background (check logs:
docker-compose logs lean) - Strategy Generator: Run via
docker-compose run strategy
The repository includes helpful utility scripts in the scripts/ directory:
# Interactive menu to select and run algorithms
./scripts/backtest_menu.sh
# Or run a specific algorithm directly
./scripts/run_backtest.sh algorithms/SimpleBuyAndHold.py
# View backtest results
./scripts/view_results.sh
# Download sample market data
./scripts/download_sample_data.shThese scripts handle Docker exec commands and result parsing automatically.
Rebate Optimization:
cd services/rebate
pip install -r requirements.txt
streamlit run app.pyStrategy Generator:
cd services/strategy
pip install -r requirements.txt
python generate.pyLean Engine:
docker-compose up lean# Run the strategy generator
docker-compose run strategy
# Generated strategies saved to: services/strategy/generated/Edit parameters in the Streamlit UI:
- Go to http://localhost:8501
- Adjust parameters in the sidebar
- Click "Run Optimization"
- Download results as CSV
from generate import StrategyGenerator
generator = StrategyGenerator(api_key="your_key")
strategy = generator.generate_strategy(
prompt="Create a momentum strategy using RSI with 30/70 thresholds",
language="python"
)
validation = generator.validate_strategy(strategy["code"], "python")
if validation["valid"]:
filepath = generator.save_strategy(strategy, "my_rsi_strategy")
print(f"Strategy saved to: {filepath}")- Open http://localhost:8501
- Set your base trading volume and frequency
- Click "Run Optimization"
- Review best parameters and estimated savings
- Download trial data for further analysis
lean:
- Build context:
./lean-core - Volumes:
./data:/Data,./lean-core:/Lean - Interactive terminal enabled
rebate:
- Build context:
./services/rebate - Port:
8501:8501 - Volume mount for live code updates
strategy:
- Build context:
./services/strategy - Depends on:
lean - Volume mount for data sharing
# Test strategy generation
docker-compose run strategy python -m pytest
# Test rebate service (run in container)
docker-compose run rebate python -m pytest
# View lean logs
docker-compose logs -f leanThe interactive Streamlit interface allows you to optimize trading rebate parameters using Optuna hyperparameter optimization.
Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error',
'message': 'Your credit balance is too low to access the Anthropic API.'}}
Solution:
- Add credits to your Anthropic account at https://console.anthropic.com/
- Or set up a valid API key with available credits in your
.envfile - The strategy generator service requires API credits to function
PermissionError: [Errno 13] Permission denied: '/app/generated/strategy_1.py'
Solution:
- This was fixed in the latest Docker configuration
- The
services/strategy/Dockerfilenow creates thegenerated/directory with proper permissions - Rebuild the container:
docker-compose build strategy
UnhandledExceptionEventArgs: Unrecognized command or argument 'tail'
at QuantConnect.Configuration.ApplicationParser.ParseArguments
Solution:
- These errors occur when the Lean container uses
tail -f /dev/nullas a keep-alive command - This is intentional - the Lean engine is now designed to stay running so you can exec backtests into it
- To run a backtest, use:
docker-compose exec lean dotnet /Lean/Launcher/bin/Release/QuantConnect.Lean.Launcher.dll - Or use the provided utility scripts in
scripts/directory
Solution:
- Ensure the Lean submodule is initialized:
git submodule update --init --recursive - Rebuild the lean-core container:
docker-compose build lean --no-cache - The Dockerfile now includes proper build steps with
dotnet restoreanddotnet build
Solution:
- The docker-compose.yml now uses selective volume mounts
- If you need to develop Lean algorithms, uncomment the development volume mounts in docker-compose.yml
- For production use, keep the default configuration to preserve built DLLs
If you encounter other issues:
- Check the logs:
docker-compose logs -f [service-name] - Rebuild containers:
docker-compose build --no-cache - Check that all environment variables are set in
.env - Verify the Lean submodule is properly initialized
- β Monorepo structure with docker-compose orchestration
- β Lean engine Docker integration
- β AI-powered strategy generator with validation
- β Interactive rebate optimization UI with Optuna
- β CI/CD pipeline setup (GitHub Actions)
- π Strategy backtesting automation
- π Integration between strategy generator and Lean engine
- π Advanced validation and risk metrics
- π Live trading integration
- π Real-time performance monitoring dashboard
- π Multi-exchange rebate comparison
- π Automated strategy deployment
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Commit changes:
git commit -am 'Add my feature' - Push to branch:
git push origin feature/my-feature - Submit a pull request
[Add your license here]
For issues and questions:
- Open an issue on GitHub
- Check existing documentation
- Review QuantConnect forums
Built with: QuantConnect Lean, Python, Docker, Streamlit, Optuna, and Claude AI

