Fix SimpleFIN holdings confusing market value with cost basis (#1182) (#1261)

Remove "value" from the market_value fallback chain in the SimpleFIN
HoldingsProcessor and add it to the cost_basis fallback chain instead.
Some brokerages (Vanguard, Fidelity) use "value" to represent cost basis,
causing the system to display average cost per share as the current price
and show massive phantom losses.

https://claude.ai/code/session_01V2gC6BPT3sF7Hu4XQgUQT4

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Juan José Mata
2026-03-23 19:39:32 +01:00
committed by GitHub
parent 7b93f63628
commit a10af59f42
2 changed files with 71 additions and 2 deletions

View File

@@ -42,9 +42,12 @@ class SimplefinAccount::Investments::HoldingsProcessor
end
# Parse provider data with robust fallbacks across SimpleFin sources
# NOTE: "value" is intentionally excluded from the market_value fallback chain
# because some brokerages (e.g. Vanguard, Fidelity) use "value" to mean cost basis,
# which would cause the system to display average cost as current price. (GH #1182)
qty = parse_decimal(any_of(simplefin_holding, %w[shares quantity qty units]))
market_value = parse_decimal(any_of(simplefin_holding, %w[market_value value current_value]))
cost_basis = parse_decimal(any_of(simplefin_holding, %w[cost_basis basis total_cost]))
market_value = parse_decimal(any_of(simplefin_holding, %w[market_value current_value]))
cost_basis = parse_decimal(any_of(simplefin_holding, %w[cost_basis basis total_cost value]))
# Derive price from market_value when possible; otherwise fall back to any price field
fallback_price = parse_decimal(any_of(simplefin_holding, %w[purchase_price price unit_price average_cost avg_cost]))