mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
* Placeholder logic for missing prices * Generate holdings properly for "offline" securities * Separate forward and reverse calculators for holdings and balances * Remove unnecessary currency conversion during sync * Clearer sync process * Move price caching logic to dedicated model * Base holding calculator * Base calculator for balances * Finish balance calculators * Better naming * Logs cleanup * Remove stale data type * Remove stale test * Fix price lookup logic for holdings sync * Fix Plaid item sync regression * Remove temp logging * Calculate cash and holdings series * Add holdings, cash, and balance series dropdown for investments
29 lines
814 B
Ruby
29 lines
814 B
Ruby
class Account::Balance::ForwardCalculator < Account::Balance::BaseCalculator
|
|
private
|
|
def calculate_balances
|
|
current_cash_balance = 0
|
|
next_cash_balance = nil
|
|
|
|
@balances = []
|
|
|
|
account.start_date.upto(Date.current).each do |date|
|
|
entries = sync_cache.get_entries(date)
|
|
holdings = sync_cache.get_holdings(date)
|
|
holdings_value = holdings.sum(&:amount)
|
|
valuation = sync_cache.get_valuation(date)
|
|
|
|
next_cash_balance = if valuation
|
|
valuation.amount - holdings_value
|
|
else
|
|
calculate_next_balance(current_cash_balance, entries, direction: :forward)
|
|
end
|
|
|
|
@balances << build_balance(date, next_cash_balance, holdings_value)
|
|
|
|
current_cash_balance = next_cash_balance
|
|
end
|
|
|
|
@balances
|
|
end
|
|
end
|