Well, after modifying two thousands transactions in my personal ledger
file, I realized that I got it wrong and that I had not fully
understood the way ledger handles multiple currency accounting.
I used the following syntax, that I mistakenly believed the smartest.
2011/01/03 Buy food
Assets:US_Cash -40 USD
Expenses:Food 40 USD @ 1.3 CAD
Income:Currency
With 2000 transactions like that in my personal ledger, the problem is
that I accumulated a lot of "XX USD @ YY CAD". When accumulating
several thousands of USD, a very slight change in USD/CAD currency
rate make a huge change in CAD total.
As an example, let's add the following line in my test files named
"selinger_table_4_4-*".
P 2011/01/08 USD 1.45 CAD
When doing "ledger bal", only 3 files give a zero balance:
- selinger_table_4_4-currency_trading_account
- selinger_table_4_4-pricing@
- selinger_table_4_4-pricing@@
When doing "ledger -X CAD bal", only 2 give a correct result:
- selinger_table_4_4-balanced
- selinger_table_4_4-currency_trading_account
Only "selinger_table_4_4-currency_trading_account" looks to be the
solution. I remind the syntax used:
2011/01/03 Buy food
Assets:US_Cash -40 USD
Income:Currency:USD 40 USD
Income:Currency:CAD -52 CAD
Expenses:Food 52 CAD
While correct, I do not like this syntax, because I have to manually
compute the CAD amount (52 CAD equals 40 USD @ 1.3 CAD), and also when
"ledger reg Food", I lost the fact that it was a 40 USD spending.
After some thinking, I finally found the trick, by using the following
syntax:
2011/01/03 Buy food
Assets:US_Cash -40 USD
Expenses:Food 40 USD {= 1.3 CAD}
Income:Currency
This gives me satisfaction: "bal", "bal --basis", "bal -X CAD" all
gives correct results, even when using --end with dates 2011/01/04,
2011/01/07, and 2011/01/08.
In my previous post, I disregarded "fixated commodity price" because
it gives weird results. Actually, it gives correct result when
balanced with an empty "Income:Currency". But if used without an empty
"Income:Currency", it gives strange results.
As a summary, here is file syntax:
-----------8<-----------8<-----------8<-----------
2011/01/01 Opening balance
Assets:Canadian_Cash 200 CAD
Equity:Initial_Capital
2011/01/02 Exchange
Assets:Canadian_Cash -120 CAD
Assets:US_Cash 100 USD
Income:Currency
P 2011/01/03 USD 1.30 CAD
2011/01/03 Buy food
Assets:US_Cash -40 USD
Expenses:Food 40 USD {= 1.3 CAD}
Income:Currency
2011/01/05 Exchange
Assets:US_Cash -60 USD
Assets:Canadian_Cash 75 CAD
Income:Currency
2011/01/07 Buy food
Assets:Canadian_Cash -20 CAD
Expenses:Food
P 2011/01/08 USD 1.45 CAD
-----------8<-----------8<-----------8<-----------