Event-Driven Algorithmic Trading System
PyMAC is an extensible, production-ready algorithmic trading framework designed for the Moomoo platform. The architecture ensures that the same strategy code runs for both 10-year historical backtests and live trading.
- ✅ Unified Strategy Interface: Write once, run in backtest or live
- ✅ Parquet-Based Storage: Efficient handling of 10+ years of 1-minute data
- ✅ Dual Data Sources: Yahoo Finance (free) or Moomoo API (premium)
- ✅ Full Backtesting Engine: Realistic order simulation with slippage and commissions
- ✅ Event-Driven Architecture: Real-time market data processing
- ✅ Risk Management: Built-in position limits and safeguards
- ✅ Type-Safe: Full Python type hints for reliability
- ✅ Performance Metrics: Sharpe, Sortino, Max Drawdown, Win Rate
# Install dependencies
pip install -r requirements.txt# From Yahoo Finance (free, no setup)
python download_data_v2.py AAPL --source yahoo --period 5y
# Or from Moomoo (requires OpenD running)
python download_data_v2.py US.AAPL --source moomoo --start 2020-01-01python main.py --mode backtest \
--strategy SimplePriceStrategy \
--symbol US.AAPL \
--start 2020-01-01 \
--end 2023-12-31 \
--capital 10000The engine displays:
- 📊 Returns and P&L
- 📈 Sharpe and Sortino ratios
- 📉 Maximum drawdown
- 💼 Trade statistics and detailed trade log
# Paper trading (safe - simulated money)
python main.py --mode live \
--strategy SimplePriceStrategy \
--symbol US.AAPL \
--paper
# Live trading (⚠️ real money!)
python main.py --mode live \
--strategy SimplePriceStrategy \
--symbol US.AAPL--paper mode! See docs/live_trading_guide.md for safety information.
PyMAC/
├── src/
│ ├── core/ # Abstract interfaces (BaseStrategy, DataProvider)
│ ├── adapters/ # Concrete implementations (Backtester, MoomooLive)
│ ├── strategies/ # Your trading strategies
│ └── utils/ # Logging, metrics
├── configs/ # YAML configuration files
├── data/ # Parquet files (gitignored)
├── logs/ # Execution logs (gitignored)
└── main.py # CLI entry point
- Create a new file in
src/strategies/ - Inherit from
BaseStrategy - Implement
on_bar()method - Add configuration to
configs/strategies.yaml
pytest tests/- Start with paper trading
- Set strict
max_position_sizelimits - Keep
require_confirmation: trueuntil fully tested - Never commit API keys to git
MIT License - See LICENSE file for details