Announcement of the sing_curr_conv: Neth Worth Change explainer / Unrealized Gains analyzer. Request for feedback.

181 views
Skip to first unread message

Chary Ev2geny

unread,
Jan 12, 2025, 1:08:52 PM1/12/25
to Beancount

Dear all I would like to a announce a sing_curr_conv: Neth Worth Change explainer / Unrealized Gains analyzer


This tool makes it possible to explain changes in the Net Worth between any two dates in a situation of multi-currency / multi-commodity ledger with changing exchange rates and transfers of funds from one commodity to another (both cost and not cost-based tracked). This is achieved by creating a converted / equivalent ledger, on which further analysis can be done using beanquery.


The tool can be used

  • from a command line

  • as a function in Python code

  • as a plugin


I may be wrong, but I think there is no generic solution for the Net Worth Change problem in the beancount community (e.g. see this discussion).


The accompanying Jupyter notebook sing_curr_conv_usage.ipynb has detailed example of how the sing_curr_conv can be used in practice.


The sing_curr_conv is a part of the evbeantools package, which can be found here


https://github.com/Ev2geny/evbeantools


I must say, the sing_curr_conv is a result of quite a long activity, and actually the very reason I came to beancount 6 years ago and one of the reasons I learned python. With this in mind and taken into account, that I am not a professional developer, any feedback is more than welcome (including, but not limiting the feedback on the code, style, project etc).

Martin Blais

unread,
Jan 13, 2025, 6:55:34 AM1/13/25
to bean...@googlegroups.com
Thanks for sharing! Added to the contribs list.


--
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 visit https://groups.google.com/d/msgid/beancount/77d5fe9f-19ba-4664-a65d-8ca6d272f331n%40googlegroups.com.

Chary Ev2geny

unread,
Jan 13, 2025, 9:35:23 AM1/13/25
to Beancount
Martin,

thanks!


We did have several discussions with you on this idea of mine (e.g. here). 

I also know that you were working on the unrealized gains as well.

I remember you had had an unrealized gain plugin, plus in v3 I think there were plans for trading accounts based on the Peter Selinger's document.

I will really appreciate you could spend 5 min time to review how I implemented the idea. 

It is best shown in this Jupiter notebook:


For me it does exactly what I need so far, but I wonder if you can see any flaws there or have any comments.

Martin Blais

unread,
Jan 16, 2025, 9:24:02 AM1/16/25
to bean...@googlegroups.com
I wouldn't do it like that.

I think it's quite strange to convert AAA to BBB units in BankA and I wouldn't do that.

This:
2020-02-01 * "Exchange AAA to BBB"
    Assets:BankA               -100.0 AAA
    Assets:BankB                150.0 BBB @@ 100 AAA ; <== price, different from the one in the price directive

Instead of this:

2020-02-01
* "Exchange AAA to BBB" Assets:BankA -100.0
BBB Assets:BankB 150 BBB Income:Unrealized-Gains:BBB-AAA -50.0000000000000000000000000 BBB

Would instead be converted to

2020-02-01
* "Exchange AAA to BBB" Assets:BankA -100.0 AAA Assets:BankB 150 BBB
  Expenses:CurrencyAccounts:AAA                                  100.0 AAA
  Expenses:CurrencyAccounts:BBB                                 -150 BBB


Chary Ev2geny

unread,
Jan 16, 2025, 4:39:54 PM1/16/25
to Beancount
Martin,

thanks for the feedback. I guess this is a   trading accounts method, based on the Peter Selinger's document.

But how would you approach the situation, when there is no exchange at all.

======================

option "operating_currency" "BBB"

2020-01-01 open Assets:Bank
2020-01-01 open Equity:Opening-Balances

2020-01-01 price AAA 1.0 BBB

2020-01-01 * "Opening Balance"
    Assets:Bank                100 AAA
    Equity:Opening-Balances   -100 AAA

; Note: at this moment out net worth, when measured in BBB, is 100 BBB, as the exchange rate is 1.0

2020-02-01 price AAA 2.0 BBB

; Note: at this moment out net worth, when measured in BBB, is 200 BBB, as the exchange rate has changed

=======================

The sing_curr_conv solves this like this

2020-01-01 open Assets:Bank 2020-01-01 open Equity:Opening-Balances 2020-01-01 price AAA 1.0 BBB 2020-01-01 * "Opening Balance" Assets:Bank 100.0 BBB scc_msg: "Converted from 100 AAA" Equity:Opening-Balances -100.0 BBB scc_msg: "Converted from -100 AAA" 2020-02-01 open Income:Unrealized-Gains:BBB-AAA 2020-02-01 price AAA 2.0 BBB 2020-02-01 * "Unrealized gains due to AAA price change from 1.0 to 2.0 BBB (BBB price change from 1 to 0.5 AAA)" scc_msg: "Created by the Single Currency Converter" Assets:Bank 100.0 BBB scc_msg: "Calculated on the balance of 100 AAA at the beginning of this day (end of prev. day)" scc_at_cost: "no_cost" scc_unreal_g_cause: "price_change" Income:Unrealized-Gains:BBB-AAA -100.0 BBB scc_msg: "Calculated on the balance of 100 AAA at the beginning of this day (end of prev. day)" scc_at_cost: "no_cost" scc_unreal_g_cause: "price_change" scc_bal_s_acc: "Assets:Bank"

I guess, the method I implemented is what is described as  The "official" solution: translation to a single currency in the Peter Selinger's document.

Regards.
Reply all
Reply to author
Forward
0 new messages