Skip to content

Commit

Permalink
lib: fix division by zero in roi when all assets are sold (fixes #2281)
Browse files Browse the repository at this point in the history
  • Loading branch information
adept authored and simonmichael committed Nov 7, 2024
1 parent d176215 commit c006959
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hledger/Hledger/Cli/Commands/Roi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c006959

Please sign in to comment.