Does alpaca rounds up or down to the nearest penny when dealing with account balances?

For fees, it rounds up to the nearest penny, but what about for balances? For instance, if I have 10.111$ will it round up to 10.12 or down to 10.11?

@drest Other than the regulatory fees, other transactions are rounded according to the IEEE 754 standard for floating-point arithmetic. This is also known as “Banker’s Rounding”, “round half to even” or “round to nearest, ties to even”.

Here’s how it works

  • When a number is not exactly at the midpoint between $.01 (eg $1.023) round to the nearest $.01.

  • When a number is exactly halfway between two cents (eg $1.025) round to the nearest cent with an even (zero) least significant digit.

Examples

  • 2.025 rounds to 2.02 (because 2.02 is even).

  • 3.035 rounds to 3.04 (because 3.04 is even).

Why is it used?

  • Reduces bias: Traditional rounding (round half up) can introduce a systematic upward bias when rounding a large set of numbers. Banker’s rounding helps to distribute rounding errors more evenly.

  • More accurate for calculations: This is particularly important in fields like finance and statistics where sums and averages are frequently calculated, as it can lead to more accurate overall results.

OK, I confess I got that last part from ChatGPT :slight_smile:

BTW, the only reason regulatory fees are not rounded this way is 99% of all fees are less than $.003. Therefore they would all round to zero and no fees would ever get collected. Bankers rounding relies upon a rather uniform distribution of numbers. The regulatory fees are highly skewed to numbers less than $.003 so bankers rounding would exhibit that same skew.