Skip to content

1.22: Regression error of inferred prices with @@ directive #1736

Closed

Description

@RomainGehrig

I updated hledger from 1.21 to 1.22.2 and found that I couldn't print my balancesheet anymore due to an error "hledger: Ratio has zero denominator". After bisect, the minimal example uses two balance assertions, one using a total price (@@) directive.

Failing example with hledger > 1.21 (also tried with latest release hledger 47b5b6b, linux-x86_64):

;; Total asset value should be 400 USD + 1000 USD = 1400 USD
2021-10-15 Broker initial balance (equity ABC)
    Assets:Broker           = 4 ABC @@ 400 USD
    Equity:Opening Balances    

2021-10-15 Broker initial balance (USD)
    Assets:Broker           = 1000 USD
    Equity:Opening Balances
$ hledger --version
hledger 1.22.2, linux-x86_64
$ hledger prices --costs
P 2021-10-15 ABC 100.0 USD
hledger: Ratio has zero denominator

On previous hledger:

$ hledger --version
hledger 1.21
$ hledger prices --costs
P 2021-10-15 ABC 100.0 USD

Funny thing: reversing the transactions order fixes the issue but I couldn't find in the changelog if this behavior was expected or not.

[SM: for the record, in recent releases --costs was renamed to --infer-market-prices, and it is not the same as --cost.]

Activity

  1. added
    A-BUGSomething wrong, confusing or sub-standard in the software, docs, or user experience.
    on Oct 18, 2021
  2. Xitian9 commented on Nov 14, 2021

    @Xitian9
    Collaborator

    I'm not 100% sure what is causing this issue, but your journal is not doing what you think it should. In the second transaction you are asking for a balance assignment, which means that the final value will not be 1400 USD, but rather 1000 USD. To get what you seem to want, use the following journal:

    ;; Total asset value should be 400 USD + 1000 USD = 1400 USD
    2021-10-15 Broker initial balance (equity ABC)
        Assets:Broker           = 4 ABC @@ 400 USD
        Equity:Opening Balances    
    
    2021-10-15 Broker initial balance (USD)
        Assets:Broker             1000 USD
        Equity:Opening Balances
    
  3. simonmichael commented on Nov 14, 2021

    @simonmichael
    Member

    Thanks for the report, and sorry I lost track of it. Confirmed, claim your https://hledger.org/regressionbounty when you like!

    $ cat a.j
    ;; Total asset value should be 400 USD + 1000 USD = 1400 USD
    2021-10-15 Broker initial balance (equity ABC)
        Assets:Broker           = 4 ABC @@ 400 USD
        Equity:Opening Balances    
    
    2021-10-15 Broker initial balance (USD)
        Assets:Broker           = 1000 USD
        Equity:Opening Balances
    $ hledger-1.21 -f a.j prices --costs
    P 2021-10-15 ABC 100.0 USD
    $ hledger-1.22 -f a.j prices --costs
    P 2021-10-15 ABC 100.0 USD
    hledger-1.22: Ratio has zero denominator
    $ hledger-1.23 -f a.j prices --costs
    P 2021-10-15 ABC 100.0 USD
    hledger-1.23: Ratio has zero denominator
    
  4. added
    regressionA backwards step, indicating a weakness in our QA. We don't like these.
    on Nov 14, 2021
  5. changed the title [-]Regression error of inferred prices with @@ directive[/-] [+]Regression error of inferred prices with @@ directive (since 1.22)[/+] on Nov 14, 2021
  6. simonmichael commented on Nov 14, 2021

    @simonmichael
    Member

    In the second transaction you are asking for a balance assignment, which means that the final value will not be 1400 USD, but rather 1000 USD.

    I'm not seeing what you mean @Xitian9; the example looks like it should work, to me.

    Testing some similar balance assertions:

    ; succeeds:
    2021-10-15
        a           4 ABC @@ 400 USD  = 4 ABC @@ 400 USD
        e
    
    ; ignores the price and succeeds:
    2021-10-15
        b           4 ABC  = 4 ABC @@ 400 USD
        e
    
    ; fails:
    2021-10-15
        c           400 USD  = 4 ABC @@ 400 USD
        e
    

    Balance assertions are known to ignore transaction prices:
    https://hledger.org/hledger.html#assertions-and-prices

    Balance assignments are expected to use transaction prices:
    https://hledger.org/hledger.html#balance-assignments-and-prices

  7. simonmichael commented on Nov 14, 2021

    @simonmichael
    Member

    (The reported issue seems to be fallout from 5e7b693.)

  8. Xitian9 commented on Nov 15, 2021

    @Xitian9
    Collaborator
    ;; Total asset value should be 400 USD + 1000 USD = 1400 USD
    2021-10-15 Broker initial balance (equity ABC)
        Assets:Broker           = 4 ABC @@ 400 USD
        Equity:Opening Balances    
    
    2021-10-15 Broker initial balance (USD)
        Assets:Broker           = 1000 USD
        Equity:Opening Balances
    

    I'm only remarking on whether this journal is the correct journal, given the comment at the top. They seem to be expecting a final balance of 1400 USD in assets:Broker, whereas I believe this is asserting a final balance of 4 ABC, 1000 USD. I may be misinterpreting what they're expecting.

  9. Xitian9 commented on Nov 15, 2021

    @Xitian9
    Collaborator

    Aha. The problem seems to be that, with that second balance assertion, hledger is asserting the amount to be:

    2021-10-15 Broker initial balance (USD)
        Assets:Broker                      0 ABC @@ 0 USD
        Assets:Broker                      1000 USD
        Equity:Opening Balances
    

    It then tries to infer the price by calculating 0 / 0, which is causing the divide by zero error here. I'll try to figure out where this is going wrong.

  10. Xitian9 commented on Nov 15, 2021

    @Xitian9
    Collaborator

    This actually points to a more general issue: we now allow zero-prices within hledger. For example, each of the following are allowable.

    2021-10-15 Broker initial balance (USD)
        Assets:Broker                      0 ABC @@ 10 USD
        Assets:Broker                      10 ABC @@ 0 USD
        Equity:Opening Balances
    

    These are valid, and it is impossible to calculate unit prices in at least one direction. How should we handle this?

    • Do not try to generate prices for a posting when at least one side has a zero?
    • Above, but issue a warning?
    • Something else?
  11. simonmichael commented on Nov 15, 2021

    @simonmichael
    Member

    That problem arises with --infer-market-prices, right ? We could respect zero numerators and ignore zero denominators ? I think that would mean:

    • 0 ABC @@ 10 USD - no price is inferred for ABC; 0 ABC price is inferred for USD
    • 10 ABC @@ 0 USD - 0 USD price is inferred for ABC; no price is inferred for USD

    Or, I'm fine with having --infer-market-prices just ignore it if there's a zero on either side.

  12. Xitian9 commented on Nov 15, 2021

    @Xitian9
    Collaborator

    Yes, that's also valid. Should it issue a warning, or just happily ignore?

  13. simonmichael commented on Nov 15, 2021

    @simonmichael
    Member

    No warning, just ignore.

  14. simonmichael commented on Nov 15, 2021

    @simonmichael
    Member

    If unnoticed zeroes ever turn out to be a significant problem, check would be the place to warn about them.

  15. simonmichael commented on Nov 19, 2021

    @simonmichael
    Member

    Thanks!

  16. changed the title [-]Regression error of inferred prices with @@ directive (since 1.22)[/-] [+]1.22: Regression error of inferred prices with @@ directive[/+] on Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-BUGSomething wrong, confusing or sub-standard in the software, docs, or user experience.bountyThar's some kind o' loot on offer..journalThe journal file format, and its features.regressionA backwards step, indicating a weakness in our QA. We don't like these.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions