mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-07 21:15:19 +03:00
lib: fix division by zero in roi when all assets are sold (fixes #2281)
This commit is contained in:
parent
d176215f03
commit
c006959b05
@ -239,7 +239,9 @@ timeWeightedReturn styles showCashFlow prettyTables investmentsQuery trans mixed
|
||||
Left pnl' ->
|
||||
-- PnL change
|
||||
let valueAfterDate = valueOnDate + unMix pnl'
|
||||
unitCost' = valueAfterDate/unitBalance
|
||||
unitCost' =
|
||||
if unitBalance == 0 then initialUnitCost -- everything was sold, let's reset the cost to initial cost
|
||||
else valueAfterDate/unitBalance
|
||||
in (valueOnDate, 0, unitCost', unitBalance))
|
||||
(0, 0, initialUnitCost, initialUnits)
|
||||
$ dbg3 "changes" changes
|
||||
|
Loading…
Reference in New Issue
Block a user