Skip to content

Inferred equity ignores tag filters #2535

Description

@jmattheis
hledger setup (CLICK ME)

Using ArchLinux.

Checking your hledger setup..
Legend: good, neutral, unknown, warning

hledger
* is a released version ?                  yes  hledger 1.51.2, linux-x86_64
* is up to date ?                          yes  1.51.2 installed, latest is 1.51.2
* is a native binary for this machine ?    yes  x86_64
* is installed in PATH (this version) ?    yes  /usr/sbin/hledger
* 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 ?   yes  /usr/sbin/less
* the LESS variable is defined ?           yes
* the HLEDGER_LESS variable is defined ?    no
* adjusting LESS variable for color etc. ? yes
* tables will use box-drawing chars ?       no  you can use --pretty to enable them

journal
* the LEDGER_FILE variable is defined ?    yes  /home/jm/src/account/main.journal
* a default journal file is readable ?     yes  /home/jm/src/account/main.journal
* it includes additional files ?           yes  47 files
* all commodities are declared ?           yes  19 commodities
* all accounts are declared ?              yes  66 accounts
* all accounts have types ?                 no  5 accounts without types
* accounts of all types exist ?             no  L accounts not found; some reports may not work
* commodities/accounts are being checked ?  no  you can use -s to check them
* balance assertions are being checked ?   yes  you can use -I to ignore them

I'm using tags in account directives for specifying categories for specific accounts. When using --infer-equity, it seems like the inferred equity ignores tag filters. E.g. when using this journal, the following commands produce unexpected results.

test.journal:

account asset:bank           ; type:A
account asset:stocks:STOCK   ; type:A, category:stock

commodity 1,000.00 EUR
commodity 1,000.000 "STOCK"

P 2020-01-01 "STOCK" 20 EUR
P 2020-02-01 "STOCK" 10 EUR
P 2020-03-01 "STOCK" 25 EUR

2020-01-01
    asset:stocks:STOCK    10 "STOCK" @@ 200.00 EUR
    asset:bank                           -200.00 EUR

2020-02-01
    asset:stocks:STOCK    20 "STOCK" @@ 200.00 EUR
    asset:bank                           -200.00 EUR
$ hledger --infer-equity -f test.journal bal 'tag:category=stock' --value end
          750.00 EUR  asset:stocks:STOCK
          400.00 EUR  equity:conversion:EUR-STOCK:EUR
         -750.00 EUR  equity:conversion:EUR-STOCK:STOCK
--------------------
          400.00 EUR

$ hledger -f test.journal bal 'tag:category=stock' --value end
          750.00 EUR  asset:stocks:STOCK
--------------------
          750.00 EUR

When filtering directly for the account and not using the tag filter, it works fine:

$ hledger --infer-equity -f test.journal bal 'asset:stocks:STOCK' --value end
          750.00 EUR  asset:stocks:STOCK
--------------------
          750.00 EUR

The same seems to be true when using hledger roi.

$ hledger --infer-equity -f test.journal roi --investment 'tag:category=stock' --pnl 'dividend' --value then -b 2020 -e 2021
+---++------------+------------++---------------+------------+-------------+-----++-------++------------+----------+
|   ||      Begin |        End || Value (begin) |   Cashflow | Value (end) | PnL ||   IRR || TWR/period | TWR/year |
+===++============+============++===============+============+=============+=====++=======++============+==========+
| 1 || 2020-01-01 | 2020-12-31 ||             0 | 400.00 EUR |  400.00 EUR |   0 || 0.00% ||      0.00% |    0.00% |
+---++------------+------------++---------------+------------+-------------+-----++-------++------------+----------+

$ hledger -f test.journal roi --investment 'tag:category=stock' --pnl 'dividend' --value then -b 2020 -e 2021
+---++------------+------------++---------------+------------+-------------+------------++--------++------------+----------+
|   ||      Begin |        End || Value (begin) |   Cashflow | Value (end) |        PnL ||    IRR || TWR/period | TWR/year |
+===++============+============++===============+============+=============+============++========++============+==========+
| 1 || 2020-01-01 | 2020-12-31 ||             0 | 400.00 EUR |  750.00 EUR | 350.00 EUR || 92.36% ||    150.00% |  150.00% |
+---++------------+------------++---------------+------------+-------------+------------++--------++------------+----------+

(See different "Value (end)"/PnL)

I'd expect, that the result are the same when using tag:category=stock or querying the account directly via asset:stocks:STOCK.


Thanks for this awesome tool!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-BUGSomething wrong, confusing or sub-standard in the software, docs, or user experience.affects3-fewAffects just a few users.annoyance3-blockerNew user experience or installability bug. A potential user could fail to get started.journalThe journal file format, and its features.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions