beanquery
beanquery copied to clipboard
Document should cover CONVERT()
Original report by Martin Michlmayr (Bitbucket: tbm13, GitHub: tbm).
I want to use CONVERT() to convert something to its historical cost (i.e. exchange rate on date of transaction, without later revaluation).
I don't think this is currently possible with beancount. Maybe CONVERT() can be extended to allow an optional DATE.
Example:
2014-01-01 open Expenses:Test
2014-01-01 open Assets:Cash
2014-01-09 * "Test" "Test 1"
Expenses:Test 10.00 EUR @ 0.8283 GBP
Assets:Cash -8.28 GBP
2014-06-10 * "Test" "Test 2"
Expenses:Test 10.00 EUR @ 0.8106 GBP
Assets:Cash -8.11 GBP
2014-07-30 * "Test" "Test 3"
Expenses:Test 10.00 EUR @ 0.7914 GBP
Assets:Cash -7.91 GBP
2014-09-11 price EUR 0.8011 GBP
2014-12-31 price EUR 0.7825 GBP
select date, position, convert(position, "GBP"), balance where account ~ 'Expenses'
date position convert_po balance
---------- --------- ---------- ---------
2014-01-09 10.00 EUR 7.8250 GBP 10.00 EUR
2014-06-10 10.00 EUR 7.8250 GBP 20.00 EUR
2014-07-30 10.00 EUR 7.8250 GBP 30.00 EUR
It uses the latest exchange rate (0.7825) for all transactions.
Original comment by Patrick Ruckstuhl (GitHub: tarioch).
This is possible, I'm using this. It's the third argument. e.g. convert(position, "GBP", date)
Original comment by Martin Michlmayr (Bitbucket: tbm13, GitHub: tbm).
Thanks, Patrick. This issue is a documentation issue then since this isn't mention anywhere.
After adding explicit price entries, it works:
beancount> select date, position, convert(position, "GBP", date), balance where account ~ 'Expenses'
date position convert_po balance
---------- --------- ---------- ---------
2014-01-09 10.00 EUR 8.2830 GBP 10.00 EUR
2014-06-10 10.00 EUR 8.1060 GBP 20.00 EUR
2014-07-30 10.00 EUR 7.9140 GBP 30.00 EUR
The converted positions have 4 digits of precision: 8.1060. Is there a way to round this?
Original comment by Martin Michlmayr (Bitbucket: tbm13, GitHub: tbm).
Patrick, do you know how to specify a specific date. A string ("2018-03-15") doesn't work.
Original comment by Martin Blais (Bitbucket: blais, GitHub: blais).
The list of available functions is located in this file: https://bitbucket.org/blais/beancount/src/358d24867d12e7145f7fe2c321f3f809089051fa/beancount/query/query_env.py?at=default&fileviewer=file-view-default#query_env.py-638
I'd like to eventually generate a full list or serve it from the help.