I have occasionally gotten division-by-zero errors from this plugin; I
finally decided to look into what's going on.  I am having trouble
understanding this code from long_short.py:

            # ensure our replacement postings sum up to the original
capital gains postings we removed
            diff = orig_sum - (short_gains + long_gains)
            # divide this diff among short/long. TODO: warn if this is over
tolerance threshold, because it
            # means that the transaction is probably not accounted for
correctly
            if abs(diff) >= entry.meta['__tolerances__'][p.units.currency]:
                total = short_gains + long_gains
                short_gains += (short_gains/total) * diff
                long_gains += (long_gains/total) * diff

A couple specific questions:

- How could the replacement postings not add up to the original posting?
- If they do, do we really want to be robust to this case, or should that
"TODO" really be TODO: make this a fatal error?

Assuming that there are good reasons to enter this block of code to divvy
up unaccounted for gains/losses, the following seem like problems:

- If short_gains and long_gains are both zero, this code will fail with
div-by-zero.
- If short_gains and long_gains are equal and opposite, this code will also
fail.

Thoughts?

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/CAFXPr0tOAqCeXsLPu6egpwTQsu1xJGnxzxQ-Y9W802WBknVwfQ%40mail.gmail.com.

Reply via email to