gribsons/quant-tradingbot
0
QuantBot V1
A Python algorithmic trading backtesting system that trades small-cap stocks using a momentum-pullback strategy.
What This Is
QuantBot V1 downloads real stock market data, identifies stocks with strong price momentum that have briefly pulled back, and simulates buying and selling them with realistic costs. It then tells you whether the strategy would have made money historically.
The Strategy (Plain English)
- Universe: 20 small-cap stocks
- Entry: Buy when a stock is in the top 20% for 20-day momentum AND has pulled back to just below its 5-day moving average AND volume is elevated
- Exit: Sell when price rises 3% above the 20-day MA (take profit) OR falls 8% from entry (stop loss)
- Sizing: Equal weight across up to 10 positions at once
Setup
pip install -r requirements.txtCreate a .env file (already provided) — the Alpaca keys are not needed for backtesting.
How to Run
Interactive menu (recommended):
python main.pyIndividual components:
python data/fetch.py # Download and clean price data
python strategies/momentum.py # Generate buy/sell signals
python backtest/run.py # Run the historical backtest
python simulator/sim.py # Run the market simulator
python backtest/walk_forward.py # Validate the edge
python results/charts.py # Generate performance chartsWhat Each Component Does
How to Read the Results
After running the backtest, check results/metrics.json for:
Walk-Forward Verdicts
What to Do If Results Are Bad
- Sharpe < 0.4 on out-of-sample: The strategy is overfitted to the training period. Try loosening the momentum rank threshold or changing the pullback window.
- High max drawdown (>25%): The stop loss may be too wide. Try tightening
STOP_LOSS_PCTinbacktest/run.py. - Very few trades: Signal conditions are too strict. Try widening
PULLBACK_LOWfrom -3% to -5%. - Win rate < 40%: Exit conditions need tuning. Consider a tighter take-profit target.
- Large gap between training and out-of-sample: The strategy is curve-fitted. Use fewer parameters and simpler rules.
Output Files
results/
signals.csv -- All buy/exit signals with dates and prices
trade_log.csv -- Every completed trade with P&L
equity_curve.csv -- Daily portfolio value
metrics.json -- All performance statistics
simulation_results.csv -- Simulator output
walk_forward.json -- Walk-forward results and verdict
charts/
equity_curve.png -- Portfolio vs SPY over time
trade_distribution.png -- Histogram of individual trade returns
monthly_heatmap.png -- Monthly return calendar
signal_analysis.png -- Signal frequency and win rate per ticker