Unrealized gains

339 views
Skip to first unread message

Dennis

unread,
Sep 6, 2024, 10:59:42 AM9/6/24
to Beancount
Hello everyone,

I just tracked all my ETF purchases over the last years and wanted to see my unrealized gains. 

The documentation suggests to use a plugin:

plugin "beancount.plugins.unrealized" "Unrealized"


However, that plugin doesn't exist anymore. Is there an alternative?

Note, I'm using Beancount v3 as it was suggested to be used by new users in another mail thread here.

Best,
Dennis

Martin Blais

unread,
Sep 6, 2024, 11:09:42 AM9/6/24
to Beancount
- this plugin is gone
- make sure you have recent price declarations
- compute it using beanquery sql or a script


--
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 view this discussion on the web visit https://groups.google.com/d/msgid/beancount/d73c920e-6219-41f0-ba9f-7f84eec07f93n%40googlegroups.com.

Joshua Cabrera

unread,
Sep 7, 2024, 2:17:40 PM9/7/24
to Beancount
If you use fava, you can view unrealized gains using the "at market value" view in the balance sheet without any options or plugins in your main.beancount file.

Note: if you're wondering why my numbers look odd, I'm still working on initializing my ledger.

Screenshot 2024-09-07 111916.png

Eric Altendorf

unread,
Sep 7, 2024, 3:15:26 PM9/7/24
to bean...@googlegroups.com
On Sat, Sep 7, 2024 at 11:17 Joshua Cabrera <josh.d....@gmail.com> wrote:
If you use fava, you can view unrealized gains using the "at market value" view in the balance sheet without any options or plugins in your main.beancount file.

Note to OP, though, fava doesn’t work with beancount 3


Note: if you're wondering why my numbers look odd, I'm still working on initializing my ledger.

Screenshot 2024-09-07 111916.png

On Friday, September 6, 2024 at 10:09:42 AM UTC-5 bl...@furius.ca wrote:
- this plugin is gone
- make sure you have recent price declarations
- compute it using beanquery sql or a script


On Fri, Sep 6, 2024, 10:59 Dennis <dennis...@gmail.com> wrote:
Hello everyone,

I just tracked all my ETF purchases over the last years and wanted to see my unrealized gains. 

The documentation suggests to use a plugin:

plugin "beancount.plugins.unrealized" "Unrealized"


However, that plugin doesn't exist anymore. Is there an alternative?

Note, I'm using Beancount v3 as it was suggested to be used by new users in another mail thread here.

Best,
Dennis

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/beancount/d73c920e-6219-41f0-ba9f-7f84eec07f93n%40googlegroups.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.

Dennis Trautwein

unread,
Sep 8, 2024, 9:47:18 AM9/8/24
to Beancount
Thanks everyone for the quick responses! I didn't know about the Fava feature. Even though it's only for Beancount v2, I can use it with my v3 journal. That's what I'm going with for now! 

Joshua Cabrera

unread,
Sep 8, 2024, 9:47:18 AM9/8/24
to Beancount
Crap, I didn't know that - thank you for pointing that out!

I'm running beancount 2.3.6 while thinking it was v3.

Chary Chary

unread,
Sep 8, 2024, 11:30:22 AM9/8/24
to Beancount
What is exactly the definition of the  unrealized gains in fava in this case? is it documented somewhere?

For instance if I have a following simple  ledger

plugin "beancount.plugins.auto_accounts"

option "operating_currency" "USD"

2024-01-01 price EUR 1.0 USD

2024-01-02 * "Opening balance "
    Assets:EU:Bank      1000 EUR
    Equity:Opening-Balances

2024-01-03 price EUR 2 USD

Then I would expect, that on 3 January I have a 1000 USD of unrealized gains due to EUR/USD change. But as far as I can see fava does not show this.

Am I missing something?

Joshua Cabrera

unread,
Sep 8, 2024, 12:35:20 PM9/8/24
to Beancount
You have to book the USD cost of the EUR for it to calculate the gains/losses - see adjusted example below.

plugin "beancount.plugins.auto_accounts"

option "operating_currency" "USD"

2024-01-01 price EUR 1.0 USD

2024-01-02 * "Opening balance "
    Assets:EU:Bank      1000 EUR {{1000 USD}}
    Equity:Opening-Balances

2024-01-03 price EUR 2 USD

Screenshot 2024-09-08 113413.png

Petr Beránek

unread,
Sep 8, 2024, 12:50:48 PM9/8/24
to bean...@googlegroups.com
Hi, 

as a temporary workaround for the incompatibility of Beancount v3 and Fava, I install Fava via pipx: https://pipx.pypa.io/stable/. It runs the app in a separate virtual environment, so there are no dependency issues.

Best regards
Petr

Dne so 7. 9. 2024 21:15 uživatel Eric Altendorf <erical...@gmail.com> napsal:

Chary Chary

unread,
Sep 9, 2024, 7:55:02 AM9/9/24
to Beancount
Ok,

thanks, it shows unrealized gains now for my case

Unreal_fava.PNG
Jus a few questions regarding this

1) Fava calculates unrealized gains only for things, which you track at cost. And the things you track at cost are the things you are expected to pay a capital gains on, and the things you pay a capital gains on is determined by you local legislation.  
So, affectively this is your local legislation which determines whether you write like this

2024-01-01 price EUR 1.0 USD

2024-01-02 * "Opening balance "
    Assets:EU:Bank      1000 EUR
    Equity:Opening-Balances

Or like this


2024-01-02 * "Opening balance "
    Assets:EU:Bank      1000 EUR { 1.00 USD}
    Equity:Opening-Balances

Is my understanding correct?

2) In my case it calculated the unrealized gains correctly, but I could not find any breakdown on how fava has calculated this.
Can I find any breakdown or Fava just calculates this under the hood and gives you a final  result?
I am just thinking, that in my example it was simple, but what about big and complex  ledger, would you not want to see the breakdown? 

3) Is there any way to create such a Balance Sheet report for a specific date in the past? 

This report does seem to be symmetric.

If I now want to run it for EUR, it show some unrealized gains for EUR, which I would not consider to be the case:

plugin "beancount.plugins.auto_accounts"

option "operating_currency" "EUR"

2024-01-01 price EUR 1.0 USD

2024-01-02 * "Opening balance "
    Assets:EU:Bank      1000 EUR { 1.00 USD}
    Equity:Opening-Balances

2024-02-01 price EUR 2 USD

Unreal_fava_EUR.PNG

Chary Chary

unread,
Sep 9, 2024, 11:24:51 AM9/9/24
to Beancount
On Monday, September 9, 2024 at 1:55:02 PM UTC+2 Chary Chary wrote:


This report does seem to be symmetric.


 Correction of typo:  This report does NOT seem to be symmetric.

 

Joshua Cabrera

unread,
Sep 9, 2024, 2:11:02 PM9/9/24
to Beancount
1) Honestly, it depends. The answer is very dependent on whatever statutory requirements and/or personal reporting preferences you have.

Yes, if it is subject to capital gains, you would want to track your cost basis. Capital gains occur when you purchase an asset and later sell the asset for more than what you purchased it for, so you need a cost basis to be able to calculate that.

You could optionally track cost basis for things that aren't subject to capital gains if you just wish to know how much you stand to gain from exchange/conversion differences - e.g., you're an American currently living in Europe and are curious to know how much you would gain if you decided to liquidate all your EUR assets into USD and move back to USA.

In finance, these differences would be referred to as statutory reporting vs. management reporting.

Continuing with the American expat living in Europe example, Americans' worldwide income is subject to tax by the IRS. Under IRS guidelines, you would want to track your FX amounts at their historical USD amounts - i.e., using the exchange rate from the date of the transaction. So, let's say you're an expat living in Spain and you get paid 1,000 EUR weekly, the USD amount you would report to the IRS would vary slightly for each week based on the prevailing exchange rate. You would not report USD amounts by summing your EUR and converting using the latest exchange rate. For this requirement, you could track your EUR's cost basis in USD and simply report at cost - not market value.


2) I can't point to where in Fava's source how this is calculated exactly, but it'd simply be the number of units (EUR) multiplied by the latest price - this is the total current market value of your holding/position - less the total cost basis of the holding. If you have more than one lot for your position, then the cost basis per unit will vary by lot.

You can get a breakdown by account in the balance sheet view by looking at your assets and liabilities. The unrealized account under equity is simply the sum of those amounts.

If you want a more detailed breakdown, you can explore the holdings page - see example below. Your unrealized amount would be market value less the book value (cost).

Screenshot 2024-09-09 111919.png

If you look at the query, it will show how it's calculating everything.

SELECT account,
    units(sum(position)) as units,
    cost_number as cost,
    first(getprice(currency, cost_currency)) as price,
    cost(sum(position)) as book_value,
    value(sum(position)) as market_value,
    cost_date as acquisition_date
  WHERE account_sortkey(account) ~ "^[01]"
  GROUP BY account, cost_date, currency, cost_currency, cost_number, account_sortkey(account)
  ORDER BY account_sortkey(account), currency, cost_date


3) Yes, go to help >>> filtering entries. 

Your reporting issues are happening because you've changed your operating currency to EUR from USD in your previous example.

This doesn't make sense to me from an abstract finance perspective and seems to be why you're getting funky results. If your operating currency is EUR, then you would be tracking cost basis in EUR, not USD.

I don't have a use for multiple operating currencies, but it seems like others do, so you might want to explore using both EUR and USD.

Chary Chary

unread,
Sep 10, 2024, 3:13:11 PM9/10/24
to Beancount
Joshua,

thanks for your clarification! it is more clear now.

Thought I now have a question about how US expats, who do not use beancount, manage to do their tax declaration, but this is probably not a question for this group.
Reply all
Reply to author
Forward
0 new messages