bean-query CONVERT() at a historical rate

51 views
Skip to first unread message

Chary Chary

unread,
Jun 9, 2020, 4:58:51 AM6/9/20
to Beancount
Hi,

is this correct, that beancount does not have possibility to convert to commodity (currency) at a historical rate (at a rate, which commodity had at a date of transaction)?

I see only options to convert at a current exchange rate or at an exchange rate at a particular date 

CONVERT(Amount,str)': Coerce an amount to a particular currency.'
CONVERT
(Amount,str,date)': Coerce an amount to a particular currency.'


I could not find anything to Ledger's --historical (-H)  flag

In a multi-currency situation I want to convert Expenses and Income at a historical exchange rate and Assets and Liabilities at a current one

Martin Michlmayr

unread,
Jun 9, 2020, 5:18:30 AM6/9/20
to bean...@googlegroups.com
* Chary Chary <char...@gmail.com> [2020-06-09 01:58]:
> is this correct, that beancount does not have possibility to convert
> to commodity (currency) at a historical rate (at a rate, which
> commodity had at a date of transaction)?

Someone might have a bette answer but... if you do a simple conversion
(@@), beancount doesn't keep track of the date or the rate. If you
want to keep the historical rate around, you have to use a cost, i.e.
the 10.00 EUR {1.13 USD} syntax, and then you can use SUM(COST(position))
to get the historical cost.

I'm not sure if there's a better way.

I'm sure someone will mention "trading accounts" as a solution but I
don't know how they work.

--
Martin Michlmayr
https://www.cyrius.com/

Chary Chary

unread,
Jun 11, 2020, 3:32:20 AM6/11/20
to Beancount
Martin,

thanks!

I actually found the solution, the query is like that:

select SUM(CONVERT(COST(position),"USD",date)) WHERE account ~ "Income"

With such query the conversion happens with the exchange rate of the transaction date.

I think the bean-query is really amazing thing!
Reply all
Reply to author
Forward
0 new messages