Realized and unrealized currency gain

214 views
Skip to first unread message

pat...@ch.tario.org

unread,
Sep 18, 2017, 2:14:22 PM9/18/17
to Beancount
Hi,

I've now tried to search for this for quite a bit but somehow I'm not finding the right stuff or maybe not understanding it right and I hope someone can help me.

I would like to separate the currency gains from other income and would like to also differentiate between realized and unrealized gain.

Let's take the following example

2017-06-01 * "Buy USD"
Assets:CHF -30 CHF
Assets:USD 20 USD @ 1.5 CHF

2017-07-01 price USD 1.7 CHF

2017-08-01 * "Sell USD"
Assets:USD -20 USD @ 2 CHF
Assets:CHF           40 CHF

  • On 2017-07-01 I would have an unrealized currency gain of 4 CHF, how would I see this?
  • On 2017-08-02 I would have a realized currency gain of 10 CHF, how would I set this up to see this as income?

One thing I found was

Which looked quite interesting to me and seems to have a solution for this but I'm struggling with implementing some of the details of it.
I think in my case the concept of "adjusted cost base" seems to be the simplest and make sense. 

So if I understood that correct I would need to do the following:

2017-06-01 *
Assets:CHF -30 CHF
Income:USDTrading       30 CHF
Income:USDTrading       -20 USD
Assets:USD 20 USD

2017-07-01 price BTC 0.30 CHF

2017-08-01 *
Assets:USD -20 USD
Income:USDTrading       20 USD
Income:USDTrading       -30 CHF
Income:USDTradingRealized       -10 CHF
Assets:CHF           40 CHF

What I get out of this
  • If I take the balance of Income:USDTradingRealized with the current exchange rate this should reflect my unrealized gain

A couple of things that confuse me
  • This feels somehow "wrong" as I'm no longer using the @ price annotation and have this price implicit in the difference between the amounts in one currency going into the USDTrading and and out of the USDTrading in the other currency.
  • I need to manually calculate the -10 CHF realized gain
  • Income:USDTradingRealized could actually be an income or an expense, depending on current exchange rates

Can anyone help me with this or point me in the right direction?


Thanks and Regards,
Patrick


Zhuoyun Wei

unread,
Sep 19, 2017, 3:15:25 AM9/19/17
to patrick via Beancount
Hi Patrick,

in order to compute PnL, you need to provide cost instead of price:


2017-06-01 * "Buy USD"
Assets:CHF -30 CHF
Assets:USD 20 USD { 1.5 CHF }

2017-07-01 price USD 1.7 CHF

2017-08-01 * "Sell USD"
Assets:USD -20 USD { 1.5 CHF } @ 2 CHF
Assets:CHF 40 CHF
Income:PnL


This way you could see a realized PnL of (2 CHF - 1.5 CHF) * 10 = 5 CHF
in the account Income:PnL.

To compute unrealized PnL, you could enable a built-in plugin:


plugin "beancount.plugins.unrealized" "Unrealized"


This way you could see an unrealized PnL in Assets:CHF:Unrealized.


See official documentation for more information: https://docs.google.com/document/d/1WjARst_cSxNE-Lq6JnJ5CC41T3WndEsiMw4d46r2694/edit



2017-09-18 11:14:22 patrick via Beancount <bean...@googlegroups.com>:
> --
> You received this message because you are subscribed to the Google Groups "Beancount" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> beancount+...@googlegroups.com.
> To post to this group, send email to bean...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/
> 397c15c6-c5ea-4d9c-917f-60adf03344d4%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


--
Zhuoyun Wei
signature.asc

Patrick Ruckstuhl

unread,
Sep 19, 2017, 1:19:55 PM9/19/17
to bean...@googlegroups.com
Hi,

Thank you very much, I got confused by this: https://docs.google.com/document/d/1dW2vIjaXVJAf9hr7GlZVe3fJOkM-MtlVjvCO1ZpNLmg/edit (Beancount - Comparison / Differences)
which made me think that currency transactions should never use the cost functionality.

It looks like the average cost booking method has also been implemented in the mean time, so I can do it like this without having to bother about lots (which I don't care about)


2017-06-01 *
    Assets:CHF                            -30 CHF
    Assets:USD                            20 USD { 1.5 CHF }

2017-07-01 price USD 1.7 CHF

2017-08-01 *
    Assets:USD                    -10 USD { * } @ 2 CHF
    Assets:CHF           40 CHF
    Income:USDTrading



signature.asc

Patrick Ruckstuhl

unread,
Sep 19, 2017, 1:48:23 PM9/19/17
to bean...@googlegroups.com
Looks like I was too quick, seems like * is not yet implemented, this fails:


2017-06-01 *
    Assets:CHF                            -30 CHF
    Assets:USD                            20 USD { 1.5 CHF }

2017-06-01 *
    Assets:CHF                            -30 CHF
    Assets:USD                            20 USD { 1.6 CHF }


2017-07-01 price USD 1.7 CHF

2017-08-01 *
    Assets:USD                    -10 USD { * } @ 2 CHF
    Assets:CHF           40 CHF
    Income:USD:Realized


So will I have to go through the manual steps of converting the lots to an average cost booking or is there something I'm missing?

signature.asc

Jason Chu

unread,
Sep 19, 2017, 1:55:30 PM9/19/17
to bean...@googlegroups.com
The reason you don't usually track cost basis for currency conversion is because usually you just spend the money you get after doing the conversion. Knowing that the 5 USD you just spent on ice cream used to be 7.5 CHF and reporting it as a realized gain isn't usually required.

Your situation is different because you are trading currencies for investments and thus reporting them on your taxes. In that situation, you do want to know the change in value of the commodities over time.

I don't have a recommendation on average cost booking at this point. Luckily I haven't run into that situation yet ;)

Zhuoyun Wei

unread,
Sep 20, 2017, 12:13:18 AM9/20/17
to 'Patrick Ruckstuhl' via Beancount
2017-09-19 19:19:44 'Patrick Ruckstuhl' via Beancount <bean...@googlegroups.com>:
> Hi,
>
> Thank you very much, I got confused by this: https://docs.google.com/document/d/
> 1dW2vIjaXVJAf9hr7GlZVe3fJOkM-MtlVjvCO1ZpNLmg/edit (Beancount - Comparison / Differences)
> which made me think that currency transactions should never use the cost functionality.
>

As Jason says, there's no need to record cost for currencies if you are
just "spending" them. In your case, you are "trading" USD for profits.
USD, in your case, if more of a stock held at cost to you.

> It looks like the average cost booking method has also been implemented in the mean time, so I can do it like this
> without having to bother about lots (which I don't care about)
>
> 2017-06-01 *
>     Assets:CHF                            -30 CHF
>     Assets:USD                            20 USD { 1.5 CHF }
>
> 2017-07-01 price USD 1.7 CHF
>
> 2017-08-01 *
>     Assets:USD                    -10 USD { * } @ 2 CHF
>     Assets:CHF           40 CHF
>     Income:USDTrading
>
>

Last time I checked, AVERAGE booking method is not implemented. Only
STRICT (default), FIFO, LIFO and NONE are available for now.


--
Zhuoyun Wei
signature.asc

Zhuoyun Wei

unread,
Sep 20, 2017, 12:18:46 AM9/20/17
to 'Patrick Ruckstuhl' via Beancount
2017-09-19 19:48:16 'Patrick Ruckstuhl' via Beancount <bean...@googlegroups.com>:
> Looks like I was too quick, seems like * is not yet implemented, this fails:
>
> 2017-06-01 *
>     Assets:CHF                            -30 CHF
>     Assets:USD                            20 USD { 1.5 CHF }
>
> 2017-06-01 *
>     Assets:CHF                            -30 CHF
>     Assets:USD                            20 USD { 1.6 CHF }
>
> 2017-07-01 price USD 1.7 CHF
>
> 2017-08-01 *
>     Assets:USD                    -10 USD { * } @ 2 CHF
>     Assets:CHF           40 CHF
>     Income:USD:Realized
>

To be exact, "*" is only a syntax meaning "select some lots from my
inventory and I don't care which lots". It's the same as an empty
bracket (-10 USD {} @ 2 CHF).

The booking method in use is determined by a global- or per-account
option. You could either:


1) Define a global option:

option booking_method "FIFO"

2) Define a per-account option:

open Assets:USD USD "FIFO"

--
Zhuoyun Wei
signature.asc

Martin Blais

unread,
Sep 24, 2017, 1:14:24 PM9/24/17
to Beancount
This thread has conflicting information.
Here's the low-down:

- Average cost booking is not implemented. '*' won't work yet.

- Gains from exchange rates aren't being tracked. The correct way to account for gains resulting in varying rates over time is to use the "trading accounts" method linked somewhere else on this list, not the cost basis. Eventually Beancount will make that method the default method to balance currency conversions, and then it should be possible.

- However, if you're actually trading currencies for the sake of trading, you should instead treat those trades not as Beancount currencies, but as instruments, e.g. "USDCHF", in which case cost basis would make sense. There's the extra complication of symmetry introduced by the unique nature of currencies and I haven't bothered building something special for it. I trade currencies myself, and I don't bother, I only report quarterly aggregates (too many trades, and long/short exposure makes it more complicated than I want to be, and my broker reports nice aggregates so why bother).

I hope this helps,





--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages