Overview
The Backtesting module provides comprehensive tools for evaluating machine learning model performance with advanced metrics and statistical analysis.Backtester Class
Constructor
Backtester instance
Example:
Methods
calculate_metrics
actual(np.ndarray): Array of actual/true valuespredicted(np.ndarray): Array of predicted values from the model
Dict containing the following metrics:
| Metric | Type | Description |
|---|---|---|
MAE | float | Mean Absolute Error |
RMSE | float | Root Mean Squared Error |
MAPE | float | Mean Absolute Percentage Error (%) |
Median_APE | float | Median Absolute Percentage Error (%) |
R2_Score | float | R-squared coefficient of determination |
Direction_Accuracy | float | Accuracy of predicted direction changes (%) |
Max_Error | float | Maximum absolute error |
Mean_Actual | float | Mean of actual values |
Mean_Predicted | float | Mean of predicted values |
Std_Actual | float | Standard deviation of actual values |
Std_Predicted | float | Standard deviation of predicted values |
format_metrics
metrics(Dict): Dictionary of metrics returned fromcalculate_metrics()
str: Formatted markdown string with key metrics
Example:
Complete Usage Example
Metrics Interpretation
Error Metrics
- MAE (Mean Absolute Error): Average absolute difference between predictions and actual values. Lower is better.
- RMSE (Root Mean Squared Error): Penalizes larger errors more heavily. Lower is better.
- MAPE (Mean Absolute Percentage Error): Error as a percentage. Values under 10% indicate good performance.
Model Quality
- R² Score: Ranges from -∞ to 1. Values closer to 1 indicate better fit.
- R² > 0.9: Excellent
- R² > 0.7: Good
- R² > 0.5: Moderate
- R² < 0.5: Poor
Directional Accuracy
- Direction Accuracy: Percentage of times the model correctly predicted price direction (up/down).
-
60%: Better than random
-
70%: Good for trading signals
-
80%: Excellent
-