Here are my notes on rewriting many aspects of how commodities are "valuated",
or appraised, via the -X and -V options. Many things will change, but I think
it makes nearly any usage scenario implementable. Comments welcome!
This file is the beginnings of my baseline test for this feature.
John
; Changes to options:
;
; -O --quantity use each posting's amOunt (DEFAULT)
; -B --cost use each posting's cost Basis
; -I --price use each posting's commodity prIce (i.e., {$10})
; this is the same as the cost if none specified
;
; -V --value request to value commodities, DWIM-style
; -X $ --exchange request to value commodities in terms of $
; -G --change show difference between cost basis and "value",
; whatever that means based on the options used
;
; -H --historical value commodities at time of acquisition
; --current value commodities as of today (DEFAULT)
; --now= define "today"
; These can all be mixed now, so:
;
; bal brokerage --cost --exchange $ --historical
; show much I spent to buy stocks, in $
;
; bal brokerage --cost --exchange $
; show much I spent to buy stocks, in today's $
;
; bal assets --exchange $ --historical
; how many $ would it have taken (at the time) to acquire my assets?
;
; bal assets --exchange $
; present value of my assets in $, or how many $ it would take to
; replace those assets today
; NEW: Virtual Costs
:
; Normally each exchange of a commodity in a journal is recorded as an
; historical price point. You can now use "virtual costs" to keep a
; particular exchange off the record. Simply surround the @ or @@ symbols
; with parentheses: (@) (@@).
; NEW: Value Annotations
;
; Commodities can now have a "valuation" expression, surrounded by (()):
;
; $20 {30 CAD} ((market)) ; value these $20 using market price
; $20 {30 CAD} ((30 CAD)) ; value is always 30 CAD, no matter what
;
; $20 {30 CAD} ((a, d, c -> market(30 CAD, d, c) ))
; ; value is always 30 CAD, but report that
; ; 30 CAD in terms of user's request
; Value expression functions:
;
; appraise(a [, d, c]) ask the amount a for its value (opt. on d in c)
; market(a , d, c) return the market price of a on d in c
; TODOs:
; - jww (2012-03-03): Change from the current, special-casey lot logic to a
; further generalization of commodity annotations.
;
; - jww (2012-03-03): Rewrite the way annotated commodities are kept in the
; pool, and how they are found.
python
from datetime import *
def download_price(amount, when=datetime.now(), commodity=None):
value = Amount(current_value_of(commodity or amount.commodity))
return value * amount
define myfunc(a, d, c) = market(a, d, c)
value market ; change the default valuation
commodity $
value a, d, c -> market(a, d, c) * 2
account Assets:Cash
value market ; function to use to get the value
value myfunc ; use myfunc function defined above
value a, d, c -> market(a, d, c) ; expression to use to get the value
value $10 ; just use a literal value
value download_price ; use the Python function above to
; always download the latest price
payee KFC
value market
2012-03-03 KFC
; Value:: market
Expenses:Food $20 ((market))
; Value:: market
Assets:Cash
commodity $
value market