|
| 1 | +# Understanding the Results |
| 2 | + |
| 3 | +When a backtest finishes running on the command line, it prints a comprehensive summary directly to your console. This summary is designed to give you an immediate, high-level overview of your strategy's performance, followed by a detailed log of its activity. |
| 4 | + |
| 5 | +## Sample Command-Line Output |
| 6 | + |
| 7 | +Here is a sample output from a completed backtest run, which we will break down in the following sections. |
| 8 | + |
| 9 | +```bash |
| 10 | +➜ make sf c='stochastix:backtesting sample_strategy -t 5m' |
| 11 | + |
| 12 | +🚀 Stochastix Backtester Initializing: sample_strategy 🚀 |
| 13 | +========================================================= |
| 14 | + |
| 15 | + Resolving configuration... |
| 16 | + Configuration resolved. |
| 17 | + |
| 18 | +Final Backtest Configuration |
| 19 | +---------------------------- |
| 20 | + |
| 21 | + ---------------------- ----------------------------- |
| 22 | + Strategy Alias sample_strategy |
| 23 | + Strategy Class App\Strategy\SampleStrategy |
| 24 | + Symbols ETH/USDT |
| 25 | + Timeframe 5m |
| 26 | + Start Date Full History (Start) |
| 27 | + End Date Full History (End) |
| 28 | + Initial Capital 10000.00 |
| 29 | + Stake Amount 2% |
| 30 | + Exchange okx |
| 31 | + ---------------------- ----------------------------- |
| 32 | + Strategy Inputs |
| 33 | + emaFastPeriod 12 |
| 34 | + emaSlowPeriod 26 |
| 35 | + stopLossPercentage 0.02 |
| 36 | + stakeAmount 0.02 |
| 37 | + ---------------------- ----------------------------- |
| 38 | + |
| 39 | +Starting Backtest Run... |
| 40 | +------------------------ |
| 41 | + |
| 42 | + ! [NOTE] Generated Run ID: 20250617-093352_sample_strategy_447393 |
| 43 | + |
| 44 | +Backtest Performance Summary |
| 45 | +---------------------------- |
| 46 | + |
| 47 | + -------------------- ---------- |
| 48 | + Initial Capital 10000.00 |
| 49 | + Final Capital 9895.98 |
| 50 | + Total Net Profit -104.02 |
| 51 | + Total Net Profit % -1.04% |
| 52 | + -------------------- ---------- |
| 53 | + Total Trades 56 |
| 54 | + Profit Factor 0.20 |
| 55 | + -------------------- ---------- |
| 56 | + Sharpe Ratio -0.643 |
| 57 | + Max Drawdown 1.18% |
| 58 | + -------------------- ---------- |
| 59 | + |
| 60 | +Closed Trades Log |
| 61 | +----------------- |
| 62 | + |
| 63 | + ---- ---------- ------ ----------- ---------- --------------------- --------------------- ---------- ------- |
| 64 | + # Symbol Dir Enter Tag Exit Tag Entry Time Exit Time Qty P&L |
| 65 | + ---- ---------- ------ ----------- ---------- --------------------- --------------------- ---------- ------- |
| 66 | + 1 ETH/USDT Long 2025-05-13 04:45:00 2025-05-13 09:00:00 0.081666 -1.31 |
| 67 | + 2 ETH/USDT Long 2025-05-13 09:05:00 2025-05-13 23:15:00 0.081193 15.62 |
| 68 | + 3 ETH/USDT Long 2025-05-14 00:25:00 2025-05-14 02:05:00 0.074486 -4.49 |
| 69 | + ... ... ... ... ... ... ... ... ... |
| 70 | + 56 ETH/USDT Long 2025-05-23 09:15:00 2025-05-23 10:30:00 0.074020 -2.72 |
| 71 | + ---- ---------- ------ ----------- ---------- --------------------- --------------------- ---------- ------- |
| 72 | + |
| 73 | + |
| 74 | +📊 Backtest finished in: 364.90 ms / Memory usage: 26.00 MB |
| 75 | + |
| 76 | + |
| 77 | + [OK] Backtest for "sample_strategy" finished successfully. |
| 78 | + |
| 79 | +``` |
| 80 | + |
| 81 | +## The Performance Summary |
| 82 | + |
| 83 | +The first section is a definition list that highlights the most important, top-level performance metrics for the entire backtest. |
| 84 | + |
| 85 | +* **Initial / Final Capital**: The starting and ending value of your portfolio. The final capital includes all realized profits from closed trades plus the unrealized value of any positions still open at the end of the test. |
| 86 | +* **Total Net Profit**: The absolute difference between the final and initial capital, in your stake currency. |
| 87 | +* **Total Net Profit %**: The total net profit expressed as a percentage of the initial capital. |
| 88 | +* **Total Trades**: The total number of trades that were opened and closed during the backtest. In the example, you see there's a discrepancy with "56" in the table and "0" in the summary. This indicates a minor bug in the summary calculation that needs to be addressed. |
| 89 | +* **Profit Factor**: A measure of profitability, calculated as Gross Profit divided by Gross Loss. A value greater than 1.0 indicates a profitable system. A value of 2.0, for example, means the strategy made twice as much money on its winning trades as it lost on its losing trades. |
| 90 | +* **Sharpe Ratio**: A common institutional metric for calculating risk-adjusted return. It measures the average return earned in excess of a risk-free rate per unit of volatility. A higher Sharpe Ratio is generally better. |
| 91 | +* **Max Drawdown**: The largest peak-to-trough decline in your portfolio's value, expressed as a percentage. This is a key indicator of risk and represents the worst-case loss an investor would have experienced had they invested at a peak. |
| 92 | + |
| 93 | +## The Closed Trades Log |
| 94 | + |
| 95 | +This table provides a detailed, trade-by-trade breakdown of the backtest. |
| 96 | + |
| 97 | +* **`#`**: A sequential number for each trade. |
| 98 | +* **`Symbol`**: The symbol that was traded (e.g., "BTC/USDT"). |
| 99 | +* **`Dir`**: The direction of the trade: `Long` or `Short`. |
| 100 | +* **`Enter Tag` / `Exit Tag`**: Any custom tags you assigned when calling `$this->entry()` or `$this->exit()`. This is extremely useful for performance attribution. |
| 101 | +* **`Entry Time` / `Exit Time`**: The timestamps when the position was opened and closed. |
| 102 | +* **`Qty`**: The quantity of the asset that was traded. |
| 103 | +* **`P&L`**: The final Profit or Loss for that specific trade, net of any commissions. |
| 104 | + |
| 105 | +## The Open Positions Log |
| 106 | + |
| 107 | +This section only appears if your strategy was still holding positions when the backtest ended. It did not appear in the sample above because all positions were closed. |
| 108 | + |
| 109 | +* **`Symbol`**, **`Dir`**, **`Entry Time`**, **`Qty`**, **`Entry Price`**: These describe the details of the position when it was opened. |
| 110 | +* **`Current Price`**: The closing price of the very last bar in the backtest. |
| 111 | +* **`Unrealized P&L`**: The profit or loss the position would have if it were closed at the `Current Price`. This amount is included in the `Final Capital` calculation in the summary section. |
0 commit comments