Converting between commodities; costs

64 views
Skip to first unread message

Martin Michlmayr

unread,
Mar 22, 2018, 1:30:47 PM3/22/18
to bean...@googlegroups.com
Let's assume you have some kind of points which can be converted to
USD at 0.75 cents or converted to air miles 1:1.

If we do:

2010-01-01 open Assets:Test
2010-01-01 open Expenses:Whatever

2018-03-20 * "Use MR for purchase"
Expenses:Whatever 42.30 USD
Assets:Test -5641 MR @@ 42.30 USD

2018-03-21 * "Convert MR to miles"
Expenses:Whatever 1 KRISFLYER
Assets:Test -1 MR @@ 1 KRISFLYER

everything is fine.

However, let's be masochistic and track these MR points at a cost of
0.075 cents:

option "inferred_tolerance_default" "USD:0.01"

2010-01-01 open Assets:Test
2010-01-01 open Equity:Opening-Balance
2010-01-01 open Expenses:Whatever
2010-01-01 open Assets:Krisflyer

2018-03-20 * "MR is treated as a commodity"
Assets:Test 10000 MR {0.0075 USD}
Equity:Opening-Balance

2018-03-20 * "Use MR for purchase"
Assets:Test -5641 MR {0.0075 USD}
Expenses:Whatever 42.31 USD

2018-03-21 * "Convert MR to KrisFlyer"
Assets:Test -100 MR {0.0075 USD} @ 1 KRISFLYER
Assets:Krisflyer

Now:

bean-report d5 balances -e Assets:Krisflyer
Assets:Krisflyer 0.7500 USD

Why is this USD and not 100 KRISFYLER? Is there any way to convert
something with cost USD to some other commodity or do you always have
to convert to the cost commodity (i.e. USD here)?

It sort of makes sense because how else can the gain be calculated?
But ledger happily creates 100 KRISFYLER in the example above and
somehow this ought to be possible but I don't know how.

Maybe my transactions are not right because of my ledger-mindset
(i.e. I'm confusing costs and prices all the time) but how would
I do this?

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

Martin Blais

unread,
Mar 22, 2018, 7:57:19 PM3/22/18
to Beancount
This should have failed.
I'm pretty darn sure I added a test to prevent this in the past, but I'm stunned now that this passes, and I can't find the test!
That this doesn't output an error message, is a bug.
I'll make this fail now, you're not supposed to be allowed to use a different price currency than the cost currency you're using.

In any case, when you use the cost, the price is ignored (other than to be added to the prices database).
The "weight" of that posting against the rest is that which is used and it is inferred by the cost only.

 
  Assets:Krisflyer

Now:

bean-report d5 balances -e Assets:Krisflyer
Assets:Krisflyer        0.7500 USD

Why is this USD and not 100 KRISFYLER? 

Because the price is ignored (desired).

 
Is there any way to convert
something with cost USD to some other commodity or do you always have
to convert to the cost commodity (i.e. USD here)?

You can make the other posting priced in USD (not supported in Ledger BTW, if I recall correctly).


It sort of makes sense because how else can the gain be calculated?

Yep.

 
But ledger happily creates 100 KRISFYLER in the example above and
somehow this ought to be possible but I don't know how.

This works:

2018-03-21 * "Convert MR to KrisFlyer"
  Assets:Test                -100 MR {0.0075 USD}
  Assets:Krisflyer           100 KRISFLYER @ 0.007500 USD


This too:

2018-03-21 * "Convert MR to KrisFlyer"
  Assets:Test                -100 MR {0.0075 USD}
  Assets:Krisflyer           100 KRISFLYER @ USD




Maybe my transactions are not right because of my ledger-mindset
(i.e. I'm confusing costs and prices all the time) but how would
I do this?

I'd be more confused if I had two different syntaxes which do the same thing if you ask me...

- prices are used for price conversions (e.g., currencies)
- costs are used only when you need to track the cost basis (e.g., investments)

That's it.

Martin Blais

unread,
Mar 22, 2018, 8:28:27 PM3/22/18
to Beancount
Reply all
Reply to author
Forward
0 new messages