Fix credit card balance history #2414

Merged
zachgoll merged 1 commits from zachgoll/maybe-879-plaid-credit-card-historical-balance-off into main 2025-06-26 05:03:53 +08:00
zachgoll commented 2025-06-26 04:58:31 +08:00 (Migrated from github.com)

When syncing Plaid credit card accounts, we were getting very overstated histories due to the account.cash_balance value. In Balance::ReverseCalculator, we use "cash balance" as our starting point and work backwards, applying entry changes to generate historicals. For credit card accounts, Plaid considers available_balance as "the limit less the current balance, less any pending outflows plus any pending inflows". We were previously setting cash_balance equal to Plaid's available_balance, which was giving us a starting point closer to the "credit limit" (which is often much higher than the user's utilization). This made it so we had today's balance correct, but historicals were then extremely inflated.

This PR moves us to a more standard way of handling Plaid balances:

  • If it's an investment account, we apply custom logic to find cash balance
  • All other accounts do NOT distinguish current vs. available anymore. We simply use current always, which means, "total account value"
When syncing Plaid credit card accounts, we were getting very overstated histories due to the `account.cash_balance` value. In `Balance::ReverseCalculator`, we use "cash balance" as our starting point and work backwards, applying entry changes to generate historicals. For credit card accounts, Plaid considers `available_balance` as "the limit less the current balance, less any pending outflows plus any pending inflows". We were previously setting `cash_balance` equal to Plaid's `available_balance`, which was giving us a starting point closer to the "credit limit" (which is often much higher than the user's utilization). This made it so we had today's balance correct, but historicals were then extremely inflated. This PR moves us to a more standard way of handling Plaid balances: - If it's an investment account, we apply custom logic to find cash balance - All other accounts do NOT distinguish `current` vs. `available` anymore. We simply use `current` always, which means, "total account value"
Sign in to join this conversation.