07 · Investments
A portfolio platform inside the ledger.
Built from a written specification and a locked visual design before any code was written: eight screens over a pure calculation engine, testable to the cent.
Platform description
The investments platform
The investments module is a securities portfolio platform built inside the accounting system for the firm's own traders. It was the first module in v2 built from a full written specification and a locked visual mock-up before any code was written, and it has eight screens: dashboard, holdings, transactions, strategy, watchlist, performance, settings and documents.
The calculation engine is pure by design, with no database, clock or presentation concerns inside it, which is what makes it testable to the cent.
- It maintains weighted-average cost while writing a lot on every purchase, so a first-in-first-out basis can be adopted later without restating history.
- It computes realised profit and loss net of fees.
- It refuses an oversell, and refuses a purchase that would exceed the cash available at the broker in that currency on the trade date.
- Performance is measured by money-weighted return, calculated by Newton's method with a bisection fallback, alongside valuation series, allocation against strategy targets and off-target compliance flags.
Market data. Prices come from a market data feed, with the token held only in an environment variable; they refresh on a configured cadence and are backfilled when a security is new. Foreign exchange comes through the same European Central Bank door the ledger already uses, so a holding and an invoice are always valued at the same rate.
Posted means final. A posted investment transaction is immutable. Correcting one is a reversal followed by a re-post, with an audit note and a visible reversals trail, the same principle the ledger applies to posted accounting data. Reports export to CSV and to PDF for holdings, transactions, income, capital gains and compliance.
Phase one is complete as specified. By agreement, three items were scoped out of it and are not left unfinished:
- general ledger posting of investment activity;
- broker statement import;
- time-weighted return.
The schema scripts still need to be run on each catalog before the screens leave their not-yet-configured state.