Plaid portfolio sync algorithm and calculation improvements #1526
Reference in New Issue
Block a user
Delete Branch "zachgoll/reverse-investment-portfolio-sync"
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?
This PR adds the ability to synchronize the
Account::BalanceandAccount::Holdingrecords in both the forward and reverse directions to support both "manual" and "connected" accounts.Manual account syncs
When dealing with a "manual" account (i.e. an account where the user is managing the data and balances), we must sync the account in the forwards direction.
For a manual account sync, we start the account at $0 and apply all
Account::Entryrecords in chronological order.Plaid account syncs
When dealing with "connected" account syncs, we must treat the provided balance as the source of truth. In our case, Plaid will provide us with the user's "current balance" (i.e. "current bank balance"). We take that as our source of truth and must work backwards, applying
Account::Entryrecords (also provided by Plaid) in reverse-chronological order to build up the historical balance.This also applies to investment holdings. Plaid provides the "current portfolio" (i.e. today's holding quantities, prices, values), which we treat as the source of truth and again, work backwards to construct the historical value of the investment portfolio.
Balance terminology
Depending on the account type, "balance" means different things. In general, the
account_balancestable represents a daily historical view of the overall "balance" on the account, which translates to:brokerage cash + holdings market valueThis PR adds a
cash_balancefield to bothAccountandAccount::Balancetables to more easily display the total "balance" on an account. This field is optional and is primarily used forInvestmentaccounts (cash_balanceis "brokerage cash",balanceis "total value", and the difference represents the "market value of the holdings")