Transaction does not balance

54 views
Skip to first unread message

POliveira

unread,
Dec 7, 2021, 4:05:40 AM12/7/21
to Ledger
Hi,

I am trying to record a multi-currency exchange transaction.
Say I have an online multi-currency wallet like Paypal where I hold 20 USD and 0 EUR.
Additionally, I have a GBP bank account (Bank 1) and a EUR bank account (Bank 2)

I want to convert my 20 USD to GBP, therefore I convert them first to EUR within my paypal account, and then settle the transaction by sending 15 EUR from Bank 2 to Bank1, which will be credited in GBP.

The following works (i.e. balances well):

2021/05/31 * Currency Exchange
    Assets:Paypal            15.00 EUR
    Assets:Paypal           -20.00 USD

2021/05/31 * Currency Exchange
    Assets:Bank1           10.00 GBP
    Assets:Bank2          -15.00 EUR

However, I was trying to consolidate everything in one entry, but the following does not balance and throws as error when parsing:

2021/05/31 * Currency Exchange
    Assets:Paypal            15.00 EUR
    Assets:Paypal           -20.00 USD
    Assets:Bank1           10.00 GBP
    Assets:Bank2          -15.00 EUR

Question 1: Is it possible to record this transaction in a single entry? How?
Question 2: Why doesn't the second option above does not balance? Isn't it equivalent to the 1st option?

Thanks, POliveira

Martin Michlmayr

unread,
Dec 7, 2021, 5:38:22 AM12/7/21
to ledge...@googlegroups.com
* POliveira <polive...@gmail.com> [2021-12-07 01:05]:
> 2021/05/31 * Currency Exchange
> Assets:Paypal 15.00 EUR
> Assets:Paypal -20.00 USD

Typically, you should specify an exchange rate with @ or @@ to make
the relationship between two currencies clear.

However, if there are only two postings, ledger will do an implicit
conversation for you, i.e. it does not require an explicit exchange
rate (@) or exchange amount (@@).

I strongly recommend to always use @ or @@ though since implicit
conversations could lead to problems that are hard to track down
later.

> 2021/05/31 * Currency Exchange
> Assets:Paypal 15.00 EUR
> Assets:Paypal -20.00 USD
> Assets:Bank1 10.00 GBP
> Assets:Bank2 -15.00 EUR

This involves 3 currencies. How should ledger know the relationship
between these currencies?

It may be obvious to a human what you want in this case, but you'll
have to tell ledger explicitly. As mentioned above, *explicit* is
good anyway as it helps you avoid mistakes.

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

POliveira

unread,
Dec 7, 2021, 8:31:17 AM12/7/21
to Ledger
Thanks Martin.
I was reading the manual and trying to sort out how to use exchange amounts in this case, but without success.
Can you exemplify how this transaction could be recorded in a single entry using explicit exchange rates/amounts?

Martin Michlmayr

unread,
Dec 7, 2021, 9:47:29 AM12/7/21
to ledge...@googlegroups.com
* POliveira <polive...@gmail.com> [2021-12-07 05:31]:
> I was reading the manual and trying to sort out how to use exchange amounts
> in this case, but without success.
> Can you exemplify how this transaction could be recorded in a single entry
> using explicit exchange rates/amounts?

You can use any of the following 3 transactions:

2021/05/31 * Currency Exchange
Assets:Paypal 15.00 EUR @ 1.333 USD
Assets:Paypal -20.00 USD
Assets:Bank1 10.00 GBP @ 1.5 EUR
Assets:Bank2 -15.00 EUR

2021/05/31 * Currency Exchange
Assets:Paypal 15.00 EUR @ (1/0.75 USD)
Assets:Paypal -20.00 USD
Assets:Bank1 10.00 GBP @ 1.5 EUR
Assets:Bank2 -15.00 EUR

2021/05/31 * Currency Exchange
Assets:Paypal 15.00 EUR @@ 20.00 USD
Assets:Paypal -20.00 USD
Assets:Bank1 10.00 GBP @@ 15.00 EUR
Assets:Bank2 -15.00 EUR

psionl0

unread,
Dec 7, 2021, 10:18:16 PM12/7/21
to Ledger
I must admit that I am also puzzled why the transaction needs to be "balanced" when a post involves multiple currencies/commodities.
In the first example, ledger produces the following balance report.
           10.00 GBP
          -20.00 USD  Assets
           10.00 GBP    Bank1
          -15.00 EUR    Bank2
           15.00 EUR
          -20.00 USD    Paypal
--------------------
           10.00 GBP
          -20.00 USD

If it does a "conversion" within each individual transaction then it doesn't make use of the information when displaying the result so there is no reason why the second transaction shouldn't also lead to the same report. Ledger doesn't need to "know" the conversion rate when a transaction contains multiple currencies. It just has to "assume" that whatever the exchange rate is will balance the transaction (ie assume nothing).

The reason why I question this is that ledger could also be used to record items of stock in the same way that it records currencies. Unfortunately, as it stands, I have to record the purchase or sale of each item of stock individually which breaks up the bank transaction and makes it more difficult to reconcile with my bank statement. Using @ or @@ prevents ledger from displaying the individual item totals in the balance report (they have all been converted).

Martin Michlmayr

unread,
Dec 8, 2021, 4:30:25 AM12/8/21
to ledge...@googlegroups.com
* psionl0 <gsc...@iinet.net.au> [2021-12-07 19:18]:
> Ledger doesn't need to "know" the conversion rate when a transaction
> contains multiple currencies. It just has to "assume" that whatever
> the exchange rate is will balance the transaction (ie assume
> nothing).

Your "assume nothing" is to assume something.

I don't want ledger to make assumptions. I want ledger to enforce
the balancing requirement.

Personally I don't like that ledger allows implicit conversations
since ledger assumes an exchange rate. Beancount, for example,
requires an explicit exchange rate when there are only two postings /
two commodities.

Let's do:

2021-12-08 * Test
Assets:A 10.00 EUR
Assets:B -8.52 GBP

If you know roughly the values of EUR and GBP, this transaction
looks obviously correct to you. But this requires a lot of knowledge
(i.e. assumptions about the world).

Now:

2021-12-08 * Test
Assets:A 1000 EUR ; let's say I forgot the . between the 00s
Assets:B -8.52 GBP

You'd probably agree that this isn't quite right, yet ledger will
happily assume an (incorrect) exchange rate.

Using explicit exchange rates makes ledger enforce the balancing
requirement.

If I had done:

2021-12-08 * Test
Assets:A 1000 EUR @ 0.852 GBP
Assets:B -8.52 GBP

ledger would complain.

You *WANT* ledger to complain.

You don't want ledger to assume.

> The reason why I question this is that ledger could also be used to
> record items of stock in the same way that it records currencies.
> Unfortunately, as it stands, I have to record the purchase or sale
> of each item of stock individually which breaks up the bank
> transaction and makes it more difficult to reconcile with my bank
> statement. Using @ or @@ prevents ledger from displaying the
> individual item totals in the balance report (they have all been
> converted).

Maybe you could give an example, so it's clearer.

psionl0

unread,
Dec 9, 2021, 1:09:34 AM12/9/21
to Ledger
"
Maybe you could give an example, so it's clearer".
When I tried POliveira's original example using the @@ option I couldn't get an output (I don't know why).

I have since tried an example of my own and these options appear to work as desired:
2021/01/01 * Stock up
   Assets:Fruit       100 apples @@ $10.00
   Assets:Fruit        80 oranges @@ $50.00
   Assets:Meat        50 steaks @@ $ 200.00
   Bank:Bank Account

2021/01/02 * Cash Sale
   Assets:Meat          -1 steaks @@ $10.00
   Bank:Cash

2021/01/03 * Mrs Smith
   Assets:Fruit         -5 oranges @@ $10.00
   Assets:Fruit        -10 apples @@ $5.00
   Assets:Accounts Receivable
   
ledger -f shop.txt bal | cat
                 $15
           90 apples
          75 oranges
           49 steaks  Assets
                 $15    Accounts Receivable
           90 apples
          75 oranges    Fruit
           49 steaks    Meat
               $-250  Bank
               $-260    Bank Account
                 $10    Cash
--------------------
               $-235
           90 apples
          75 oranges
           49 steaks


Reply all
Reply to author
Forward
0 new messages