Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--infer-market-prices is not limited by queries #2092

Open
chrpinedo opened this issue Sep 25, 2023 · 5 comments
Open

--infer-market-prices is not limited by queries #2092

chrpinedo opened this issue Sep 25, 2023 · 5 comments
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. close docs Documentation-related. impact3 Affects just a few users. journal The journal file format, and its features. needs:docs To unblock: needs corresponding documentation or doc updates severity2 Minor to moderate usability/doc bug, reasonably easy to avoid or tolerate. valuation

Comments

@chrpinedo
Copy link

chrpinedo commented Sep 25, 2023

I am not sure if this is a bug or if it is something to live with. I only open the issue for your consideration.

Description: when --infer-market-prices is used all the transactions and postings are considered for pricing purpose, even if those are excluded in the current search.

Example:

Journal file:

2022-10-01 begin
    assets:checkings  100.00 EUR
    equity:open/close balance

2022-10-01 buy stocks
    assets:stocks  10 AAA @ 10.00 EUR
    assets:checkings

P 2022-11-01 AAA 20.00 EUR

2022-12-31 close books  ; clopen=2023
    assets:stocks  -10 AAA @@ 100.00 EUR
    equity:open/close balance

2023-01-01 open books  ; clopen=2023
    assets:stocks  10 AAA @@ 100.00 EUR
    equity:open/close balance

When the value is calculated without --infer-market-prices, I get the good value:

$ hledger -f tmp.journal bal -V                                          
          200.00 EUR  assets:stocks
         -100.00 EUR  equity:open/close balance
--------------------
          100.00 EUR

When the value is inferred I get bad value:

$ hledger -f tmp.journal bal -X EUR  --infer-market-prices               
          100.00 EUR  assets:stocks
         -100.00 EUR  equity:open/close balance
--------------------
                   0  

Even If I exclude the clopen entries:

$ hledger -f tmp.journal bal -X EUR  --infer-market-prices not:tag:clopen
          100.00 EUR  assets:stocks
         -100.00 EUR  equity:open/close balance
--------------------
                   0  

This behavior can be a bit confusing, specially when we close books. In the close books documentation it is proposed to use the clopen tag to exclude the open/close transactions when we want an inter-annual report. Well, if we use --infer-market-prices, the inferred price of clopen transactions is not excluded. This could be solved by different ways:

  • change the --infer-market-prices behavior
  • document that in case of using --infer-market-prices in the reports it is recommend to provide "P" directives to the open/close dates to avoid issues with the valuation of assets in inter-annual reports.

Version:

$ hledger --version                                                      
hledger 1.31, linux-x86_64
@chrpinedo chrpinedo added the A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. label Sep 25, 2023
@wgslr
Copy link
Sponsor

wgslr commented Oct 4, 2023

Hi! I think the current behavior is correct, and in my use case it is more useful. I don't track stocks but have expenses and accounts in multiple currencies. And before I started using P directives, I was relying on infer-market-prices to get rough currency conversions. So even if all transactions today were in EUR, I could do hledger print -p today -X USD --infer-market--prices and get the prices in USD based on some older exchange transaction. With your approach, --infer-market-prices would become useless whenever a short time period was selected.

I see you point that it can be surprising, depending on your mental model, an inconvenient with the book closing transaction. I wouldn't call it a bug, but rather matter of ensuring the documentation is clear and perhaps creating a separate feature for "filtered" inferred prices

@simonmichael
Copy link
Owner

simonmichael commented Oct 5, 2023

Thanks for the report and response. I tend to agree with @wgslr. I'll try to justify it as well: market prices are a kind of immutable background data, with a fixed value on each date. We normally read them from explicit P directives; or we can automate that more by generating the P directives from transactions with --infer-market-prices. Other than choosing valuation date, we don't get to/want to choose subsets of market prices. (If you did need that, you could arrange to put them in different price files and select the one you want at report time.)

@simonmichael simonmichael added journal The journal file format, and its features. valuation docs Documentation-related. close A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. and removed A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. labels Oct 5, 2023
@simonmichael
Copy link
Owner

Perhaps saying something about this at https://hledger.org/dev/hledger.html#--infer-market-prices-market-prices-from-transactions would be helpful ? A draft or PR is welcome

@simonmichael simonmichael changed the title inferred prices from excluded registries --infer-market-prices is not limited by queries Oct 5, 2023
@chrpinedo
Copy link
Author

I agree that perhaps it is not a bug, only a handicap of using --infer-market-prices.

But I found so disturbing the closing books case. Because the closing book documentation proposes to use the clopen tag to open and close the books. It is always possible to do inter-anual reports with not:tag:clopen, it is like not having closed the books. Well this is correct but only if it is not used --infer-market-prices because in that case values and hledger roi command provides wrong values for the dates of opening/closing transactions. Because although the opening/closing transactions are not taken into account for the current report, the inferred prices of those transactions are taken into account.

The solution for closing books and using the --infer-market-prices is to provide additional P directives for the books' opening and closing dates.

I would add some comment to https://hledger.org/dev/hledger.html#example-excluding-closingopening-transactions or I would close this issue. If anybody else faces again this issue, it can find the solution in this closed issue.

@simonmichael
Copy link
Owner

Thanks for the suggestion. I haven't really understood exactly where the problem arises with close. What comment would you suggest ?

The solution for closing books and using the --infer-market-prices is to provide additional P directives for the books' opening and closing dates.

Yes, that is (should be) our general recommendation when inferred market prices aren't working out ("...value reports can sometimes be affected in confusing/undesired ways by your journal entries...") - declare market prices explicitly with P.

@simonmichael simonmichael added needs:docs To unblock: needs corresponding documentation or doc updates severity2 Minor to moderate usability/doc bug, reasonably easy to avoid or tolerate. impact3 Affects just a few users. labels Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. close docs Documentation-related. impact3 Affects just a few users. journal The journal file format, and its features. needs:docs To unblock: needs corresponding documentation or doc updates severity2 Minor to moderate usability/doc bug, reasonably easy to avoid or tolerate. valuation
Projects
None yet
Development

No branches or pull requests

3 participants