- Install dependencies:
pip install -r requirements.txt- Run the backtest:
python backtest.py- Backtester: Framework to test strategies on historical data
- SMA Crossover Strategy: Simple moving average crossover (buy when 10-day MA crosses above 30-day MA)
Modify sma_crossover_strategy() or create new strategy functions:
- RSI (Relative Strength Index)
- MACD (Moving Average Convergence Divergence)
- Bollinger Bands
- ML-based predictions
def ml_strategy(data):
# Load your trained model
# features = extract_features(data)
# prediction = model.predict(features)
# return 'BUY' if prediction > threshold else 'SELL'
passUse broker APIs:
- Alpaca (free paper trading):
pip install alpaca-trade-api - Interactive Brokers:
pip install ib_insync - TD Ameritrade:
pip install tda-api
Add to your strategy:
- Stop-loss orders
- Position sizing (don't use all capital at once)
- Maximum drawdown limits
- Diversification across multiple stocks
- Backtest on multiple years of data
- Test in paper trading for weeks/months
- Understand that past performance ≠ future results