lib: Use simpler MultiBalanceReport valuation calculations in more cases.
This commit is contained in:
parent
35a83fbd8c
commit
4cd3ed15a0
@ -349,26 +349,29 @@ accumValueAmounts ropts valuation colspans startbals acctchanges = -- PARTIAL:
|
|||||||
CumulativeChange -> cumulative
|
CumulativeChange -> cumulative
|
||||||
PeriodChange -> changeamts
|
PeriodChange -> changeamts
|
||||||
where
|
where
|
||||||
-- Calculate the valued historical balance in each column, ensuring every
|
-- Calculate the valued balances in each column, ensuring every column has an entry.
|
||||||
-- columns has an entry.
|
|
||||||
historical = cumulativeSum startingBalance
|
historical = cumulativeSum startingBalance
|
||||||
-- If no valuation can sum the changes directly, otherwise need to
|
cumulative | fixedValuationDate = cumulativeSum nullacct
|
||||||
-- subtract the valued starting amount from the historical sum
|
| otherwise = fmap (`subtractAcct` valuedStart) historical
|
||||||
cumulative = case value_ ropts of
|
changeamts | fixedValuationDate = M.mapWithKey valueAcct changes
|
||||||
Nothing -> cumulativeSum nullacct
|
| otherwise = M.fromDistinctAscList . zip dates $
|
||||||
Just _ -> fmap (`subtractAcct` valuedStart) historical
|
zipWith subtractAcct histamts (valuedStart:histamts)
|
||||||
-- If no valuation can use the change list directly, otherwise need to
|
where (dates, histamts) = unzip $ M.toAscList historical
|
||||||
-- calculate the incremental differences in the historical sum
|
|
||||||
changeamts = case value_ ropts of
|
|
||||||
Nothing -> changes
|
|
||||||
Just _ -> let (dates, histamts) = unzip $ M.toAscList historical
|
|
||||||
in M.fromDistinctAscList . zip dates $
|
|
||||||
zipWith subtractAcct histamts (valuedStart:histamts)
|
|
||||||
|
|
||||||
cumulativeSum start = snd $ M.mapAccumWithKey accumValued start changes
|
cumulativeSum start = snd $ M.mapAccumWithKey accumValued start changes
|
||||||
where accumValued startAmt date newAmt = (s, valueAcct date s)
|
where accumValued startAmt date newAmt = (s, valueAcct date s)
|
||||||
where s = sumAcct startAmt newAmt
|
where s = sumAcct startAmt newAmt
|
||||||
|
|
||||||
|
-- Whether the market price is measured at the same date for all report
|
||||||
|
-- periods, and we can therefore use the simpler calculations for
|
||||||
|
-- cumulative and change reports.
|
||||||
|
fixedValuationDate = case value_ ropts of
|
||||||
|
Just (AtCost (Just _)) -> singleperiod
|
||||||
|
Just (AtEnd _) -> singleperiod
|
||||||
|
Just (AtDefault _) -> singleperiod
|
||||||
|
_ -> True
|
||||||
|
where singleperiod = interval_ ropts == NoInterval
|
||||||
|
|
||||||
changes = changes' <> zeros
|
changes = changes' <> zeros
|
||||||
startingBalance = HM.lookupDefault nullacct name startbals
|
startingBalance = HM.lookupDefault nullacct name startbals
|
||||||
valuedStart = valueAcct (DateSpan Nothing historicalDate) startingBalance
|
valuedStart = valueAcct (DateSpan Nothing historicalDate) startingBalance
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user