stock-bot/docs/development/architecture/decisions/002-financial-policy.md
Boki b4af840d4e feat(research): add financial contracts and availability-aware datasets
Implement reviewed F01/D01 foundations without changing active trading runtimes. Validate strict Rust/TypeScript financial wire contracts, decimal postings, versioned datasets, explicit calendars, provenance, and v1 compatibility.
2026-10-22 20:51:25 -04:00

3.6 KiB

ADR-002 — Money, cost basis, ownership and funding

Status: approved by owner, 2026-10-22 (explicit “yes” to ADR-002/003/004 as written). This revision replaces the unimplemented half-even/rounded-average proposal; approval does not itself alter legacy code or accounts.

Selected minimal policy

  • Use a maintained checked decimal implementation (for example a pinned Rust decimal crate), not hand-written fixed-point arithmetic. Monetary postings and quantities use8 fractional digits initially. Explicit half-up/away-from-zero tie rounding matches the current TS amount() policy; tick/lot rules may be stricter. Reject unsupported precision, non-finite values and overflow.
  • Decimal strings are financial command/snapshot transport. Market observations and statistical feature arrays need not become strings or be copied through the boundary per observation.
  • Remaining cost amount is authoritative. Average price is derived. For a partial disposal release the proportional basis rounded at posting precision; the final disposal releases the exact remaining residual. Example: cost5 for3 shares must release exactly5 over all sales, not5.00000001 reconstructed from average1.66666667.
  • Store owner-keyed quantity/cost/P&L from the first ledger implementation (F02 absorbs F03). Account quantities/basis aggregate those books. Fees are explicit separate postings; initial unallocated capital belongs to a reserve owner. Broker suspense handling is deferred with broker integration, not a generalized suspense-account subsystem now.
  • First project-gated model is single-base-currency cash-funded long-only, no borrowing. Fee-inclusive reservations and fill-time checks live in Rust. Adverse gaps reject unaffordable remaining quantity rather than borrow or silently resize.
  • No internal crossing/netting. Stable owner/intent admission priority; one owner cannot sell/cancel another's inventory. A strategy instance selects target OR explicit-order mode; mixing modes rejects in v1.
  • Account daily-loss reset follows one declared account risk-session calendar, not each asset's venue or UTC date. Explicit boundary commands roll only the daily baseline. Drawdown peak/halt survives sessions and restore; authorized operator reset records its baseline.

Legacy correction is different

C03 only adds unpaid-fee liability to the existing non-reducing gross-capital test. It preserves existing short/reducing behavior and8-place rounding. It is not the new cash-only account model and makes no claim to eliminate all debt in legacy short covers.

Evidence / alternative costs

TS amount/cost basis, aggregate owner attribution problem, native fill broadcast. Exact postings fix arithmetic, not market modeling. A full multicurrency double-entry/margin/borrow engine is not required for v1.

Migration and tests

F01 owns scalar/command fixtures; F02 implements owned books once; F04 owns funding/risk. Preserve old results; account conversion must reconcile quantities, cost residuals, cash and fees or refuse an implicit migration. No switch restoring a correctness defect. Required tests: positive/negative rounding ties, partial/final residual, A/B owner basis, duplicate fees, overflow and persisted daily/drawdown state.

“Project-gated” means the specified regression tests passed on declared modeling policies. It is not independent certification, proof of alpha, a broker guarantee or a generic certification framework.