Skip to content

Commit

Permalink
[balsheet-pnl] unrealized-gain calculator bugfix
Browse files Browse the repository at this point in the history
The unrealized-gain calculator was flawed.

The fixed function is copied from balance-sheet.scm and adapted to
balsheet-pnl.scm vars.

This fixed function matches unrealized-gains amounts from
balance-sheet.scm
  • Loading branch information
christopherlam committed May 16, 2019
1 parent 0ecfc91 commit f779b81
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions gnucash/report/standard-reports/balsheet-pnl.scm
Expand Up @@ -937,13 +937,16 @@ also show overall period profit & loss."))
(else (list-ref report-dates col-idx))))
(asset-liability-balance
(list-ref asset-liability-balances col-idx))
(latest (monetaries->exchanged
asset-liability-balance
common-currency price-source date))
(avg-cost (monetaries->exchanged
asset-liability-balance
common-currency 'average-cost date)))
(gnc:monetary+ latest (gnc:monetary-neg avg-cost))))))
(asset-liability-basis
(gnc:accounts-get-comm-total-assets
(append asset-accounts liability-accounts)
(lambda (acc)
(gnc:account-get-comm-value-at-date acc date #f))))
(unrealized (gnc:make-commodity-collector)))
(unrealized 'merge asset-liability-basis #f)
(unrealized 'minusmerge asset-liability-balance #f)
(monetaries->exchanged
unrealized common-currency price-source date)))))
(retained-earnings-fn
(lambda (col-idx)
(let* ((date (case price-source
Expand Down

1 comment on commit f779b81

@christopherlam
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the calculation of asset-liability-basis calls, for each relevant account, gnc:account-get-comm-value-at-date, which is rather expensive. It could be optimised, but would require a chunk of code. I'll await to see if any complaints.

Please sign in to comment.