docs: rewrite prices section
This commit is contained in:
		
							parent
							
								
									795d85f36e
								
							
						
					
					
						commit
						ea0c12e2de
					
				
							
								
								
									
										70
									
								
								MANUAL.md
									
									
									
									
									
								
							
							
						
						
									
										70
									
								
								MANUAL.md
									
									
									
									
									
								
							@ -301,64 +301,70 @@ taken from the directive.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
### Prices
 | 
					### Prices
 | 
				
			||||||
 | 
					
 | 
				
			||||||
You can specify a commodity's unit price or exchange rate, in terms of
 | 
					You can record a commodity's price (also known as cost or exchange rate)
 | 
				
			||||||
another commodity. To set the price for a single posting's amount, write
 | 
					in terms of another commodity, and see amounts converted to the latter
 | 
				
			||||||
`@ UNITPRICE` after the amount, where UNITPRICE is the per-unit price in a
 | 
					with the `--cost/-B` flag.
 | 
				
			||||||
different commodity:
 | 
					
 | 
				
			||||||
 | 
					Note hledger assumes prices do not vary over time (unless explicitly
 | 
				
			||||||
 | 
					changed by a later price declaration.)  This makes tracking simple foreign
 | 
				
			||||||
 | 
					currency transactions easy. For more advanced needs such as tracking
 | 
				
			||||||
 | 
					fluctuating-value investments or capital gains, you will probably want to
 | 
				
			||||||
 | 
					run c++ ledger.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					There are several ways to specify prices:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. Set the unit price for a single posting by writing `@ UNITPRICE` after
 | 
				
			||||||
 | 
					the amount, where UNITPRICE is the per-unit price in a different
 | 
				
			||||||
 | 
					commodity. Eg:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        2009/1/2
 | 
					        2009/1/2
 | 
				
			||||||
     assets:cash:foreign currency       €100 @ $1.35  ; one hundred euros priced at $1.35 each
 | 
					         assets:cash:foreign currency       €100 @ $1.35  ; one hundred euros at $1.35 each
 | 
				
			||||||
         assets:cash
 | 
					         assets:cash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Or, you can write `@@ TOTALPRICE`, which is sometimes more convenient:
 | 
					2. Or specify the total price and let hledger work out the unit price for
 | 
				
			||||||
 | 
					the posting by writing `@@ TOTALPRICE`:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        2009/1/2
 | 
					        2009/1/2
 | 
				
			||||||
     assets:cash:foreign currency       €100 @@ $135  ; one hundred euros priced at $135 for the lot (equivalent to the above)
 | 
					         assets:cash:foreign currency       €100 @@ $135  ; one hundred euros at $135 for the lot
 | 
				
			||||||
         assets:cash
 | 
					         assets:cash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Or, you can set the price for this commodity as of a certain date, using a
 | 
					3. Or specify all of a transaction's amounts using two commodities, and
 | 
				
			||||||
historical price directive (P) as shown:
 | 
					hledger will infer the unit price that balances the transaction:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ; the exchange rate for euro is $1.35 on 2009/1/1 (and thereafter, until a newer price directive is found)
 | 
					        2009/1/2
 | 
				
			||||||
    ; four space-separated fields: P, date, commodity symbol, unit price in 2nd commodity
 | 
					         expenses:foreign currency       €100   ; one hundred euros at $135 for the lot
 | 
				
			||||||
 | 
					         assets                         $-135
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					4. Or set a price that applies to all transactions after a certain date,
 | 
				
			||||||
 | 
					using the P historical price directive:
 | 
				
			||||||
 | 
					<!-- (Note a time and numeric time zone are allowed but ignored, like ledger.) -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ; 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  
 | 
					        P 2009/1/1 € $1.35  
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        2009/1/2
 | 
					        2009/1/2
 | 
				
			||||||
     expenses:foreign currency       €100
 | 
					         expenses:foreign currency       €100   ; one hundred euros at the 2009/1/2 price ($1.35 each)
 | 
				
			||||||
         assets
 | 
					         assets
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Note: a time and numeric time zone are allowed in historical price directives, but currently ignored.
 | 
					To see any prices that are in effect, use the print command. Eg the first
 | 
				
			||||||
 | 
					example above gives:
 | 
				
			||||||
Or, you can write a transaction in two commodities, without prices but
 | 
					 | 
				
			||||||
with all amounts specified, and a conversion price will be inferred so as
 | 
					 | 
				
			||||||
to balance the transaction:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    2009/1/2
 | 
					 | 
				
			||||||
     expenses:foreign currency       €100
 | 
					 | 
				
			||||||
     assets                         $-135
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
The print command shows any prices in effect. So the first example above gives:
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $ hledger print
 | 
					    $ hledger print
 | 
				
			||||||
    2009/01/02
 | 
					    2009/01/02
 | 
				
			||||||
        expenses:foreign currency  €100 @ $1.35
 | 
					        expenses:foreign currency  €100 @ $1.35
 | 
				
			||||||
        assets                     €-100 @ $1.35
 | 
					        assets                     €-100 @ $1.35
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To see amounts converted to their total cost, use the `--cost/-B` flag
 | 
					To see amounts converted to their price's commodity (ie, their cost), use
 | 
				
			||||||
with any command:
 | 
					the `--cost/-B` flag with any reporting command:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $ hledger print --cost
 | 
					    $ hledger print --cost
 | 
				
			||||||
    2009/01/02 x
 | 
					    2009/01/02 x
 | 
				
			||||||
        expenses:foreign currency       $135.00
 | 
					        expenses:foreign currency       $135.00
 | 
				
			||||||
        assets                         $-135.00
 | 
					        assets                         $-135.00
 | 
				
			||||||
 | 
					
 | 
				
			||||||
In other words the `--cost/-B` flag converts amounts to their price's
 | 
					<!-- (It will not look up the price of a price.) -->
 | 
				
			||||||
commodity. (It will not look up the price of a price.)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Note hledger handles prices differently from c++ ledger in this respect:
 | 
					 | 
				
			||||||
we assume unit prices do not vary over time.  This is good for simple
 | 
					 | 
				
			||||||
reporting of foreign currency transactions, but not for tracking
 | 
					 | 
				
			||||||
fluctuating-value investments or capital gains.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Including other files
 | 
					### Including other files
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user