Error Handling Reference
Data Fetching Errors
No Data Returned
Error: No data returned for {symbol}Causes:
- Invalid symbol format (use
BTC-USDnotBTC/USD) - Symbol not available on data provider
- Date range has no trading data
Solutions:
# Check valid symbol format for Yahoo Finance
python -c "import yfinance as yf; print(yf.Ticker('BTC-USD').info.get('symbol'))"
# Try CoinGecko for crypto
python scripts/fetch_data.py --symbol BTC --source coingeckoInsufficient Data
Error: Insufficient data. Got {n} bars, need at least 50.Cause: Date range too short or strategy lookback period exceeds data length.
Solution: Extend the period or reduce strategy lookback:
python scripts/backtest.py --strategy sma_crossover --period 1y # More datayfinance Not Installed
yfinance not installed. Install with: pip install yfinance pandasSolution:
pip install yfinance pandas numpy matplotlibStrategy Errors
Unknown Strategy
ValueError: Unknown strategy: {name}. Available: [...]Solution: Use --list to see available strategies:
python scripts/backtest.py --listInvalid Parameters JSON
json.decoder.JSONDecodeError: ...Cause: Malformed JSON in --params argument.
Solution: Ensure proper JSON format:
# Correct
--params '{"fast_period": 20, "slow_period": 50}'
# Wrong (single quotes inside)
--params "{'fast_period': 20}"Strategy Lookback Exceeded
Signal generation failed: insufficient data for lookback periodCause: Strategy needs more historical bars than available.
Solution: Fetch more data or use shorter lookback:
python scripts/fetch_data.py --symbol BTC-USD --period 2yCalculation Errors
Division by Zero in Metrics
RuntimeWarning: divide by zero encounteredCause: No trades generated, or all trades were losses.
Solution: This is informational. Check if strategy generates signals:
- Too few signals = parameters may be too restrictive
- No winning trades = strategy may not suit the asset/timeframe
NaN in Results
Sharpe Ratio: nanCause: Zero variance in returns (e.g., all flat periods).
Solution: Use longer test period or more volatile asset.
File/Directory Errors
Permission Denied
PermissionError: [Errno 13] Permission denied: 'reports/...'Solution:
chmod -R u+w /path/to/backtester/reports/Missing Directory
FileNotFoundError: [Errno 2] No such file or directory: 'data/...'Solution: Directories are auto-created, but ensure write permissions:
mkdir -p data reportsOptimization Errors
Memory Error During Grid Search
MemoryError: Unable to allocate arrayCause: Too many parameter combinations.
Solution: Reduce parameter grid:
# Instead of testing 10x10x10 = 1000 combinations
--param-grid '{"p1": [10,20,30], "p2": [50,100]}' # 6 combinationsOptimization Takes Too Long
Cause: Large grid + large dataset.
Solutions:
- Reduce parameter grid
- Use shorter test period for initial optimization
- Parallelize (not implemented in basic version)
Performance Warnings
Unrealistic Results
Symptoms:
- Sharpe ratio > 5
- Win rate > 80%
- No losing periods
Cause: Likely overfitting or look-ahead bias.
Solution:
- Test on out-of-sample data
- Add realistic commission/slippage
- Verify signal generation doesn't use future data
All Trades Are Losses
Cause:
- Commission/slippage too high
- Strategy not suited for asset
- Wrong direction (buying when should sell)
Solution:
- Reduce costs:
--commission 0.0005 --slippage 0.0002 - Try different strategy
- Check strategy logic