->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 |
A trade’s own numbers keep the scale they were built with — 10 decimal places through Trade::make(), fromArray() and fromRow(). Construct the NumericValueAsString fields yourself (NumericValueAsString::of($size, scale: 18)) when a price × size needs more; Building trades shows how.
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.