Start and end balance anchors for historical account balances #2455
Reference in New Issue
Block a user
Delete Branch "zachgoll/valuation-anchors-v2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Second attempt at #2449, scoped down significantly to focus solely on valuation anchors. Other work from #2449 will be re-introduced in follow-up PRs.
Account anchors overview
Up to this point we've calculated balances and holdings from the
entriestable as a "pseudo event-sourced" data model, but there are a few missing pieces here:Event sourced ledger
The major goal of this PR is to move to a model where instead of using
account.balanceandaccount.cash_balance(which are really just "cache fields" derived from entries), we have a complete "ledger" ofentriesthat can construct an entire historical balance timeline without any external inputs. Addingbalanceandcash_balanceto theValuationmodel gives the necessary granularity to set an "opening balance" that has all the balance components required to initialize the timeline.By doing this,
balancesandholdingstables become solely "cache tables" (materialized) that can be deleted/re-constructed by applying an algorithm against the "ledger".This PR does not contain the concept of "Holding Snapshots" (i.e. starting point for an account's portfolio), but that will come in a future PR.
Cash vs. Non Cash balance calculation
A big improvement in this PR is an update to the balance calculation algorithm and
Valuationmodel to acknowledge both "Cash" and "Non Cash" balances. Depending on the accountable type, transactions and trades will modify different components of an account's balance.More formally, this could be described in balance sheet terms as "current" vs. "long term" assets/liabilities. For example, Cash equivalents (short term asset) vs. PP&E (long term asset); Short term debt vs. Long term debt. This designation describes how quickly and easily a balance can be liquidated / paid down.
Below is a table showing each of our account types and their designations: