$ cat test.ledger
P 2021/08/01 STOCK $1.00
2021/08/01 * Opening Balances
equity:opening balances -$1,000.00
assets:checking $1,000.00
2021/08/01 * Stock purchase ; shares:
I can then run the following command and get a sensible-looking output, though I have not verified the IRR/TWR figures:
$ hledger roi -Y -f test.ledger -V --investment "assets:shares" --pnl "equity:pnl" --cashflow
IRR cash flow for 2021-01-01 - 2021-12-31
+------------++----------+
| || Amount |
+============++==========+
| 2021-08-01 || $-110.00 |
| 2022-01-01 || $100.00 |
+------------++----------+
TWR cash flow for 2021-01-01 - 2021-12-31
+------------++-----------------+--------------++---------+----------+------------+-------++------------------+
| || Portfolio value | Unit balance || Pnl | Cashflow | Unit price | Units || New Unit Balance |
+============++=================+==============++=========+==========+============+=======++==================+
| 2021-08-01 || 0 | 0 || 0 | $110.00 | 100 | 1.1 || 1.1 |
| 2021-08-02 || 110.00 | 1.1 || $-10.00 | 0 | 90.91 | 0 || 1.1 |
+------------++-----------------+--------------++---------+----------+------------+-------++------------------+
Final unit price: $100.00/1.1 units = 90.91
Total TWR: -9.09%.
Period: 1.00 years.
Annualized TWR: -9.09%
+---++------------+------------++---------------+----------+-------------+---------++---------+--------+
| || Begin | End || Value (begin) | Cashflow | Value (end) | PnL || IRR | TWR |
+===++============+============++===============+==========+=============+=========++=========+========+
| 1 || 2021-01-01 | 2021-12-31 || 0 | $110.00 | $100.00 | $-10.00 || -20.34% | -9.09% |
+---++------------+------------++---------------+----------+-------------+---------++---------+--------+