hledger/tests/journal/market-prices.test
Simon Michael c23fc8b671 speed up -V/--value by converting reports, not the journal (#999)
Instead of converting all journal amounts to value early on, we now
convert just the report amounts to value, before rendering.

This was basically how it originally worked (for the balance command),
but now it's built in to the four basic reports used by print,
register, balance and their variants - Entries, Postings, Balance,
MultiBalance - each of which now has its own xxValue helper.

This should mostly fix -V's performance when there are many
transactions and prices (the price lookups could still be optimised),
and allow more flexibility for report-specific value calculations.

+------------------------------------------++-----------------+-------------------+--------------------------+
|                                          || hledger.999.pre | hledger.999.1sort | hledger.999.after-report |
+==========================================++=================+===================+==========================+
| -f examples/1000x1000x10.journal bal -V  ||            1.08 |              0.96 |                     0.76 |
| -f examples/2000x1000x10.journal bal -V  ||            1.65 |              1.05 |                     0.73 |
| -f examples/3000x1000x10.journal bal -V  ||            2.43 |              1.58 |                     0.84 |
| -f examples/4000x1000x10.journal bal -V  ||            4.39 |              1.96 |                     0.93 |
| -f examples/5000x1000x10.journal bal -V  ||            7.75 |              2.99 |                     1.07 |
| -f examples/6000x1000x10.journal bal -V  ||           11.21 |              3.72 |                     1.16 |
| -f examples/7000x1000x10.journal bal -V  ||           16.91 |              4.72 |                     1.19 |
| -f examples/8000x1000x10.journal bal -V  ||           27.10 |              9.83 |                     1.40 |
| -f examples/9000x1000x10.journal bal -V  ||           39.73 |             15.00 |                     1.51 |
| -f examples/10000x1000x10.journal bal -V ||           50.72 |             25.61 |                     2.15 |
+------------------------------------------++-----------------+-------------------+--------------------------+

There's one new limitation, not yet resolved: -V once again can pick a
valuation date in the future, if no report end date is specified and
the journal has future-dated transactions. We prefer to avoid that,
but reports currently are pure and don't have access to today's date.
2019-04-23 17:39:01 -07:00

121 lines
2.5 KiB
Plaintext

# http://hledger.org/journal.html#market-prices
# http://hledger.org/hledger.html#market-value
# 1. Market prices are ignored by -B.
hledger -f- bal -NB
<<<
P 2011/01/01 € $1.35
2011/01/01
expenses:foreign €100
assets
>>>
€-100 assets
€100 expenses:foreign
>>>=0
# 2. Market prices are used by bal -V.
# Market prices for other commodities are not used.
# Nor are transaction prices.
hledger -f- bal -N -V
<<<
P 2011/01/01 € $1.35
P 2011/01/01 GBP $1.35
2011/01/01
(expenses:foreign) €100 @ $1.20
>>>
$135.00 expenses:foreign
>>>=0
# 3. Market prices in the future (later than today's date) are always ignored. #453, #683
# XXX not working right now
hledger -f- bal -N -V
<<<
P 2000/1/1 $ €1.20
P 3000/1/1 $ €1.30
3000/01/01
(a) $100
>>>
€130.00 a
>>>=0
# 4. The market prices in effect at the report end date are used.
# The location of price directives does not matter.
# If multiple directives have the same date, the last parsed is used.
hledger -f- bal -N -V a -e 3000/2
<<<
P 3000/3/1 $ €1.40
3000/01/01
(a) $100
3000/03/03
(b) $100
P 2000/1/1 $ €1.20
P 3000/1/1 $ €1.35
P 3000/1/1 $ €1.30
>>>
€130.00 a
>>>=0
# 5. Again, this time there are prices later than the journal data and
# an explicit report end date brings them into play.
hledger -f- bal -N -V a -e 3000/2
<<<
P 3000/1/1 $ €1.10
P 3000/2/1 $ €1.30
3000/01/01
(a) $100
>>>
€130.00 a
>>>=0
# 6. Market prices interact with D directives and with amount style canonicalisation. #131
hledger -f- balance -V
<<<
D 1000.00 H ; declare a default commodity named H
P 2015/08/14 EEEE 41.66 ; default commodity H is used for these market prices
P 2015/08/14 FFFF 74.62
P 2015/08/14 GGGG 32.39
2015/08/15
a 2.4120 EEEE @@ 100 ; default commodity H is used for these transaction prices
a 0.3350 FFFF @@ 25
a 0.7718 GGGG @@ 25
b ; implicit balancing amount is in the cost commodity, H
>>>
150.48 H a
-150.00 H b
--------------------
0.48 H
>>>=0
# 7. register: -V affects posting amounts and total.
hledger -f- reg -V
<<<
P 2000/1/1 $ €1.20
2000/1/1
(a) $100
>>>
2000/01/01 (a) €120.00 €120.00
>>>=0
# 8. print: -V affects posting amounts but not balance assertion amounts.
hledger -f- print -V
<<<
P 2000/1/1 $ €1.20
2000/1/1
(a) $100 = $100
>>>
2000/01/01
(a) €120.00 = $100
>>>=0