Repository navigation
Closed
Labels
A-BUGSomething wrong, confusing or sub-standard in the software, docs, or user experience.Something wrong, confusing or sub-standard in the software, docs, or user experience.affects4-manyAffects potentially a significant number of users.Affects potentially a significant number of users.annoyance3-blockerNew user experience or installability bug. A potential user could fail to get started.New user experience or installability bug. A potential user could fail to get started.cliCommand line parsing, options, arguments and suchlike.Command line parsing, options, arguments and suchlike.docsDocumentation-related.Documentation-related.roi
Description
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
Metadata
Metadata
Assignees
Labels
A-BUGSomething wrong, confusing or sub-standard in the software, docs, or user experience.Something wrong, confusing or sub-standard in the software, docs, or user experience.affects4-manyAffects potentially a significant number of users.Affects potentially a significant number of users.annoyance3-blockerNew user experience or installability bug. A potential user could fail to get started.New user experience or installability bug. A potential user could fail to get started.cliCommand line parsing, options, arguments and suchlike.Command line parsing, options, arguments and suchlike.docsDocumentation-related.Documentation-related.roi
Activity
simonmichael commentedon Jul 24, 2026
Thanks for the report. This does seem a little conflicting with the manual:
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).
Garfield1985 commentedon Jul 24, 2026
is it means we do need add a PnL account when executing the "roi" command? Thanks.
adept commentedon Jul 24, 2026
You dont need to have a PnL account, but you need to have a
--pnlquery. My guess is that--pnl ''is being reduced to--pnlby your command shell, perhaps? What happens if you try--pnl foobar?Garfield1985 commentedon Jul 25, 2026
aha, that works. thanks
simonmichael commentedon Jul 30, 2026
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).[-]ROI calculation does not work in dev[/-][+]roi does not accept --pnl "" as documented[/+][-]roi does not accept --pnl "" as documented[/-][+]roi does not accept --pnl "" as advertised[/+]adept commentedon Jul 30, 2026
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
adept commentedon Jul 30, 2026
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:
Unless there are objections, I can see to it
simonmichael commentedon Jul 31, 2026
It's a slight mystery. The behaviour changed after 1.51:
Sounds good, thanks!
fix: roi: make --pnl truly optional, update docs and test file