Skip to content
Dmitry Astapov edited this page Mar 20, 2020 · 7 revisions

Associated directory: 10-foreign-currency

Handling transactions in foreign currency: starting simple

Let's tackle the most common scenario: most of your transactions (both earnings and spendings) are in a single currency (henceforth called "native" currency), but sometimes you are being charged amounts in foreign currency, but this does not happen often. Examples in this repository that you've seen so far have all been in GBP (£), and this would be our "native" currency, and I will use USD ($) as an example of the foreign currency.

In a situation like this you will probably want to think in the native currency whenever you are looking at long-term figures (like total annual expenditure), but at the same time you would like to know exact amount spent in foreign currency when you are looking at a particular transaction.

To achieve this, you would have to record the cost of your foreign currency transaction in native currency, like this:

2020-03-09 Foreign currency expense example
  assets:bank    -£10
  expenses:whatever    $11.65 @@ £10

Note that amount in foreign currency (with native cost) goes on the expense account posting - as you will be deducting native currency from you bank account.

Now hledger will report your expenses as $11.65, but if you will use --cost flag, it will use the cost instead and report this item of expenses as £10.

When looking at the annual income/expenses report, you will probably want to use --cost most of the time. This way you would immediately see the cost of foreign-currency expenses in the units most familiar to you. It is easy to add "--cost" flag to the appropriate hledger invocation in export.hs (see diffs/09-to-10.diff)

Handling foreign currency transactions in bank statements

Now, if we were recording foreign currency transactions, this would be all that you need to do and remember.

But if you want to handle foreign currency transaction as they are reported by your bank, then (in my experience), you will need to do a bit of work first. More often than not banks report foreign currency transactions in a way that does not lend itself to easy handling by hledger's CSV conversion rules. Foreign currency amount (or FX rate) might be tucked away in some sort of free-form description field, and transaction amount will always be reported in the native currency.

You might need to do a bit of preprocessing. I found that it is ofter easy to "sacrifice" one of the existing columns to extract foreign currency amount/rate out of the description field. In 10-foreign-currency I provided an example of how "inconvenient" bank statement might look like, and we will sacrifice "sort code" column to put foreigh currency amount there with the help of in2csv script.

After that it is simply the matter of producing suitable CSV conversion rules so that foreign currency amount will be used as transaction amount, and transaction amount will become the price:

if
FOREIGN CCY
  amount2  %sortcode @@ £%amount1-out

And that's it!

Next steps

To be continued