Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ verifies the actual payment. Manifest `trusted_verification_scope` lists only th
`market_admission_certified` remains false because this module does not assess complete market
admission.

Under `EVIDENCED_PIT`, `AccountSnapshot.cost_basis` is a reporting average rounded
half-even to the instrument price field's scale. Mixed fills can have a repeating
average or a finite average finer than that scale. Valuation, risk and settlement
use exact posted total cost rather than that display price. Partial closes allocate
the proportional total book cost once, half-even at `money_scale`; the unallocated
residue stays with the position, and the final close removes all remaining cost.
Realized P&L is the exact residual of posted proceeds and allocated cost. This book
allocation convention does not relax dividend payment-policy or PIT FX precision
requirements. Fees remain separate expense postings.

Manifest `1.1.0` dividend exports seal one ledger snapshot before writing. Opening positions,
external cash, marks, ordinary ledger events, PIT FX observations, valuations, and dividend phases
share one ordered operation sequence. Replay applies those business facts in order and uses final
Expand Down
13 changes: 13 additions & 0 deletions src/quant_execution/_fixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ def multiply_decimal_exact(*values: Decimal | FixedPoint | int) -> Decimal:
return fraction_decimal_exact(result)


def fixed_fraction_half_even(value: Fraction, scale: int) -> FixedPoint:
"""Round a rational book allocation/report value once, independently of context."""
if not isinstance(value, Fraction):
raise ValidationError("value must be a Fraction")
FixedPoint(0, scale) # Validate the bounded scale before exponentiation.
scaled = value * 10**scale
units, remainder = divmod(abs(scaled.numerator), scaled.denominator)
doubled = remainder * 2
if doubled > scaled.denominator or (doubled == scaled.denominator and units % 2):
units += 1
return FixedPoint(-units if scaled < 0 else units, scale)


def floor_to_scale(value: Decimal, scale: int) -> FixedPoint:
return fixed(value, scale, rounding=ROUND_DOWN)

Expand Down
Loading
Loading