Visitar URL original
roi does not accept --pnl "" as advertised · Issue #2670 · hledgerorg/hledger · GitHub
Skip to content

roi does not accept --pnl "" as advertised #2670

Closed

Description

@Garfield1985

Issue description

When I trying to calculate the ROI, it reports the error

hledger roi --inv 'AAPL' --pnl '' --value=end --infer-market-prices -f .\mydata.journal
PS C:\Users\fatca\Documents\Devs\Demo_ledger> hledger roi --inv 'AAPL' --pnl '' --value=end --infer-market-prices -f .\mydata.journal
hledger.exe: Error: Need some transactions classed as investment and not pnl, but the pnl query matches any transaction - will be unable to compute the rates of return

System config

hledger setup
PS C:\Users\fatca\Documents\Devs\Demo_ledger> hledger setup
Checking your hledger setup..
Legend: good, neutral, unknown, warning

hledger
* is running on                                 windows Microsoft Windows [Version 10.0.26200.8875] on x86_64
* is built with a supported compiler/RTS   yes  ghc 9.14.1, using threaded RTS
* is a native binary for this machine ?    yes  x86_64
* is a released version ?                   no  hledger 1.99-gd88cf68ad-20260604, windows-x86_64
* is up to date ? checking latest...         ?  couldn't read https://hledger.org/install.html (HTTP failure)
* is installed in PATH (this version) ?    yes  C:\Users\fatca\Documents\Utils\hledger\hledger.exe
* has a system text encoding configured ?  yes  UTF-8, data files must use this encoding
* has a user config file ?                  no  
* has a local config file ?                 no  

terminal
* the NO_COLOR variable is defined ?        no  
* --color is configured by config file ?    no  
* hledger will use color by default ?      yes  
* the PAGER variable is defined ?           no  
* --pager is configured by config file ?    no  
* hledger will use a pager when needed ?    no  no pager was found
* box-drawing chars are used by default ?   no  you can add --pretty to enable them


* the LEDGER_FILE variable is defined ?     no  
* a default journal file is readable ?      no  C:\Users\fatca\.hledger.journal:
data file "C:\Users\fatca\.hledger.journal" was not found.
Please create it first, eg with "hledger add" or a text editor.
Or, specify an existing data file with -f or $LEDGER_FILE.

* its filesystem supports appending ?      yes  


demo file

decimal-mark .


account bankA:Cash
account Schwab:AAPL

commodity AAPL
commodity usd

2026-06-06  buy AAPL
    bankA:Cash                            -1000.00 usd
    Schwab:AAPL                    10 AAPL @@ 1000 usd

2026-07-23  buy AAPL
    bankA:Cash                             -500.00 usd
    Schwab:AAPL                   8 AAPL @@ 500.00 usd

2026-07-24  Sell AAPL
    Schwab:AAPL                   -18 AAPL @@ 2000 usd
    bankA:Cash                             2000.00 usd

Activity

  1. simonmichael commented on Jul 24, 2026

    @simonmichael
    Member

    Thanks for the report. This does seem a little conflicting with the manual:

    If you do not record changes in the value of your investment manually, or do not require computation of time-weighted return (TWR), --pnl could be an empty query (--pnl "" or --pnl STR where STR does not match any of your accounts).

    Also we could add this error to "this report can fail, for these reasons:".

    Even better, for each of those errors we could add a short hint about how to fix it, in the manual (and even in the error message too, if it can be brief and generally applicable).

  2. Garfield1985 commented on Jul 24, 2026

    @Garfield1985
    Author

    is it means we do need add a PnL account when executing the "roi" command? Thanks.

  3. adept commented on Jul 24, 2026

    @adept
    Contributor

    You dont need to have a PnL account, but you need to have a --pnl query. My guess is that --pnl '' is being reduced to --pnl by your command shell, perhaps? What happens if you try --pnl foobar?

  4. Garfield1985 commented on Jul 25, 2026

    @Garfield1985
    Author

    You dont need to have a PnL account, but you need to have a --pnl query. My guess is that --pnl '' is being reduced to --pnl by your command shell, perhaps? What happens if you try --pnl foobar?

    aha, that works. thanks

  5. simonmichael commented on Jul 30, 2026

    @simonmichael
    Member

    I can reproduce, in a normal shell that doesn't eat the ''. But the doc says '... --pnl can be an empty query (--pnl "" ...'. I vote to make it work as documented (removing one more error case we'd otherwise have to explain).

  6. added
    A-BUGSomething wrong, confusing or sub-standard in the software, docs, or user experience.
    cliCommand line parsing, options, arguments and suchlike.
    annoyance3-blockerNew user experience or installability bug. A potential user could fail to get started.
    affects4-manyAffects potentially a significant number of users.
    on Jul 30, 2026
  7. changed the title [-]ROI calculation does not work in dev[/-] [+]roi does not accept --pnl "" as documented[/+] on Jul 30, 2026
  8. changed the title [-]roi does not accept --pnl "" as documented[/-] [+]roi does not accept --pnl "" as advertised[/+] on Jul 30, 2026
  9. adept commented on Jul 30, 2026

    @adept
    Contributor

    Is it possible that the semantics of the empty-string-as-a-query have changed (recently?) from "matches nothing" to "matches everything"?

    I am very sure that it used to work as documented at the time it was documented.

    It is possible to special-case the empty query in "roi", but then it would not match the behavior of empty string (as the query) elsewhere

  10. adept commented on Jul 30, 2026

    @adept
    Contributor

    I'm going to check this hunch over the weekend, but be a it may, I think a more robust long term solution would be to:

    • make pnl be an optional flag
    • document it as such
    • backport recent changes to 1.xx branch

    Unless there are objections, I can see to it

  11. simonmichael commented on Jul 31, 2026

    @simonmichael
    Member

    It's a slight mystery. The behaviour changed after 1.51:

    ~/src/hledger$ hledger-1.51 -f a.j roi --inv 'AAPL' --pnl '' --value=end --infer-market-prices
    hledger-1.51: Error: No relevant transactions found. Check your investments query
    ~/src/hledger$ hledger-1.52 -f a.j roi --inv 'AAPL' --pnl '' --value=end --infer-market-prices
    hledger-1.52: Error: Need some transactions classed as investment and not pnl, but the pnl query matches any transaction - will be unable to compute the rates of return
    

    Sounds good, thanks!

  12. added a commit that references this issue on Aug 2, 2026
    8bc48f6
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.affects4-manyAffects potentially a significant number of users.annoyance3-blockerNew user experience or installability bug. A potential user could fail to get started.cliCommand line parsing, options, arguments and suchlike.docsDocumentation-related.roi

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions