docs: clarify transaction prices vs historical prices

This commit is contained in:
Simon Michael 2012-01-22 21:56:20 +00:00
parent ea0c12e2de
commit 7ac9934b27

View File

@ -301,71 +301,54 @@ taken from the directive.
### Prices ### Prices
You can record a commodity's price (also known as cost or exchange rate) #### Transaction prices
in terms of another commodity, and see amounts converted to the latter
with the `--cost/-B` flag.
Note hledger assumes prices do not vary over time (unless explicitly When recording an amount, you can also record its price in another
changed by a later price declaration.) This makes tracking simple foreign commodity. This represents the exchange rate that was applied within this
currency transactions easy. For more advanced needs such as tracking transaction (or to be precise, within the posting). There are three ways
fluctuating-value investments or capital gains, you will probably want to to specify a transaction price:
run c++ ledger.
There are several ways to specify prices: 1. Write the unit price (exchange rate) explicitly as `@ UNITPRICE` after the amount:
1. Set the unit price for a single posting by writing `@ UNITPRICE` after 2009/1/1
the amount, where UNITPRICE is the per-unit price in a different assets:foreign currency €100 @ $1.35 ; one hundred euros at $1.35 each
commodity. Eg:
2009/1/2
assets:cash:foreign currency €100 @ $1.35 ; one hundred euros at $1.35 each
assets:cash assets:cash
2. Or specify the total price and let hledger work out the unit price for 2. Or write the total price for this amount as `@@ TOTALPRICE`:
the posting by writing `@@ TOTALPRICE`:
2009/1/2 2009/1/1
assets:cash:foreign currency €100 @@ $135 ; one hundred euros at $135 for the lot assets:foreign currency €100 @@ $135 ; one hundred euros at $135 for the lot
assets:cash assets:cash
3. Or specify all of a transaction's amounts using two commodities, and 3. Or fully specify all posting amounts using exactly two commodities:
hledger will infer the unit price that balances the transaction:
2009/1/2 2009/1/1
expenses:foreign currency €100 ; one hundred euros at $135 for the lot assets:foreign currency €100 ; one hundred euros
assets $-135 assets:cash $-135 ; exchanged for $135
4. Or set a price that applies to all transactions after a certain date, You can use the `--cost/-B` flag with reporting commands to see such
using the P historical price directive: amounts converted to their price's commodity. Eg, using any of the above
<!-- (Note a time and numeric time zone are allowed but ignored, like ledger.) --> examples we get:
; Historical price directives look like: P DATE COMMODITYSYMBOL UNITPRICE
; This one says the euro's exchange rate is $1.35 on or after 2009/1/1
; (unless overridden by a later price directive)
P 2009/1/1 € $1.35
2009/1/2
expenses:foreign currency €100 ; one hundred euros at the 2009/1/2 price ($1.35 each)
assets
To see any prices that are in effect, use the print command. Eg the first
example above gives:
$ hledger print
2009/01/02
expenses:foreign currency €100 @ $1.35
assets €-100 @ $1.35
To see amounts converted to their price's commodity (ie, their cost), use
the `--cost/-B` flag with any reporting command:
$ hledger print --cost $ hledger print --cost
2009/01/02 x 2009/01/01
expenses:foreign currency $135.00 assets:foreign currency $135.00
assets $-135.00 assets $-135.00
<!-- (It will not look up the price of a price.) --> #### Historical prices
You can also record a series of historical prices for a commodity using P
directives. Typically these are used to record daily market prices or
exchange rates. ledger uses them to calculate market value with -V, but
hledger currently ignores them. They look like this:
<!-- (A time and numeric time zone are allowed but ignored, like ledger.) -->
; Historical price directives look like: P DATE COMMODITYSYMBOL UNITPRICE
; These say the euro's exchange rate is $1.35 during 2009 and
; $1.40 from 2010/1/1 on.
P 2009/1/1 € $1.35
P 2010/1/1 € $1.40
### Including other files ### Including other files
You can pull in the content of additional journal files, by writing lines like this: You can pull in the content of additional journal files, by writing lines like this: