->scale() (or the scale config key) sets the decimal places of every amount: P&L, volume, value, commission, their averages, the expectancy’s and risk/reward ratio’s average win and loss, and the drawdown. bcmath truncates rather than rounds, so each figure is truncated to its scale as it is stored; ratios are divided at a higher working scale first, so an operand below the result’s precision — a loss of 0.00005 BTC, a deviation of a few basis points — still counts. Ratios and percentages are reported at a fixed scale, whatever the run’s:
| Figures | Decimal places |
|---|---|
| volume, value, commission, P&L and their averages, expectancy value / averageWin / averageLoss, riskRewardRatio averageWin / averageLoss, maxDrawdown value / equity / peak | the run’s scale (default 10) |
| counts, wins, streaks | 0 |
| frequency | 1 |
| wins->winRatio, profitFactor | 2 |
| cumulativeReturn (percent), duration (seconds) | 2 |
| expectancy->winRate / lossRate, winRateByPeriod->rates | 4 |
| riskRewardRatio->value, maxDrawdown->percentage, sharpeRatio, sortinoRatio | 4 |
| riskAdjustedReturns meanReturn / standardDeviation / downsideDeviation | 10 |
Each trade’s own numbers are exact: Trade::make(), fromArray() and fromRow() keep every amount at its own decimal places (at least 10), and its P&L and value at entry (size × open price) are computed without truncation, so the run’s scale truncates them only once, into its results. Building trades shows a high-precision example.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.