On Wed, Mar 27, 2019 at 12:37 PM Chary Chary <[email protected]> wrote:
> Martin, > > I think I have now done enough reading and testing (both beancount and > ledger), that I can continue conversation without sounding too stupid > (forgive me, if it is still the case) > > So, effectively what I think I want > > *Step 1:* I run a report, which shows my Net Worth, converted to single > currency at certain date, using all exchange rates valid for that date. Let > us call it Day A Net Worth Report > > I think in beancount query language such report will look like this > > select account, SUM(convert(position, 'CurrencyCode',<Date A>)) from > close on <Date A> WHERE account ~'Assets' OR account ~'Liabilities' > > This query will give me some output, similar to: > > account sum_convert > ---------------------- ----------------- > Assets:US:PaymentUSD 12300.0 EUR > Assets:Broker:stock:XYZ 2100.0 EUR > Liabilities:DE:creditCard -3000.0 EUR > > So my net worth is 11400.00 Euro (I didn't find a way how to make > beancount query to put a total) > Just remove the "account, " target from your query. The presence of "select account" infers an implicit group-by clause, as a convenience. In a distant future, I'd like to extend the supported SQL syntax to support aggregates rendered at the bottom of each column, e.g. select account, sum(...) as amt bottomline amt as sum or something better than that, that would tell the rendered how to aggregate all the values in a column and render them at the bottom as a special row, because it's common. *Step 2* I run the same report, but for day B (which is after day A). > > *Step 3:* And now I want a single report, which will show how I got from *Day > A net Worth* to *Day B Net Worth. *I want to have a set of numbers, > which, when I add them together, will give me exactly the difference in Net > Worth between pints A and B > Easy: if it's a one-off, export the two queries to CSV and write a script that will read that and compute the difference. In Python, you can do it all at once by using the code in beancount.query.query. Or even just filter the postings through a loop and accumulate the filtered positions in an Inventory instance, and finally convert (see beancount.core.inventory, beancount.core.convert). I even have written a document > <https://docs.google.com/document/d/1z57E8KZ9hIF71s39dDKaE5ow1N7BdJ-eX8y2BFjR9kc/edit?usp=sharing>, > which describes how I think this can be achieved, document contains example > spreadsheet > <https://docs.google.com/spreadsheets/d/1-wdXsPcBLjbYO9qLi924X2JWPw8plkWeGbSdjttcsZY/edit?usp=sharing> > with > formulas, for very simple case > > I think it shall work like this: > > > > 1. > > Expenses and Incomes are tracked at the historical exchange rate (e.i. > at the exchange rate, available during transaction). When exchange rate > changes, Expenses and Income do not get re-calculated. > > This is believed to be inline with conventional wisdom , that if you have > consumed pizza for 100 USD, there is no reason to re-calculate how much > this pizza is worth now in EUR, when USD/EUR exchange rate changed. It only > makes sense to know how much that pizza was worth in EUR, when you consumed > it. > > > 1. > > Assets and Liabilities on the other side are recalculated with every > event of exchange rate change. > > This is also inline with conventional wisdom. If instead of consuming 100 > USD in a form of pizza, you put them in a bank account and all of a sudden > this USD currency became more expensive vs EUR, this means you actually got > reacher in terms on EUR and you want to see it. > Nothing is "tracked". What you want is simply to convert your balance sheet to another currency at different points in time - with the rate at the time - and compute the difference. You can do that as you describe above. Here's a possible method: collect your two balance sheets, say, at time A and B, and then for each line that you compare, you gather the exchange rate at time A and B, as well as the inflows/outflows of capital to that account, compute the component that's from the exchange rate, and split them out from the converted totals at time B. > > > 1. > > The exchange rate changes are taken care in the following way: > > A special Commodity Revaluation transaction is logged. Following the > principle of double-entry accounting > > - > > one shoulder of transaction is logged to corresponding Asset and / or > Liability accounts to adjust these accounts to new exchange rate. > > another shoulder is logged to special Gain due to commodity price change > (trading > account, using Peter Selinger’s terminology). > #3 could essentially be just a transaction where you affect the trading accounts to recognize the aggregate profit/loss that they're accumulated. In my example I do not distinguish realized and unrealized gain. I just > create some virtual income account "Gain due to commodity price change". > this term shall cover everything: gain due to stock price change as well as > due to currency exchange rate. This is because from one side, the term > "realized gain" is closely linked to the term "taxable gain", hence depends > on local legislation. From the other side, for the gain first becomes > unrealized and only then, one can realize it (say by selling the stock). > Gain > due to commodity price change the same. > > So, using example from beancount documentation > <https://docs.google.com/document/d/1WjARst_cSxNE-Lq6JnJ5CC41T3WndEsiMw4d46r2694/edit#> > converting unrealized gain to realized shall look like this > > 2014-02-17 * "Selling some IBM" > Assets:US:ETrade:IBM -3 IBM {160.00 USD} @ > 170.00 USD > Assets:US:ETrade:Cash 500.05 USD > Expenses:Financial:Commissions 9.95 USD > > *Income:GainDueToCommodityPriceChange:realized -30 > USD Income:GainDueToCommodityPriceChange:unrealized 30** USD * > > > > > > Does it make any sense? > There's a lot to read and I have too little time to get deep into the weeds, but I did notice that your transaction above does not balance. Don't forget that the first posting weights for 3 x 160, not 3 x 170 Typically - without your special currency consideration - you would write something like this: 2014-02-17 * "Selling some IBM" Assets:US:ETrade:IBM -3 IBM {160.00 USD} @ 170.00 USD Assets:US:ETrade:Cash 500.05 USD Expenses:Financial:Commissions 9.95 USD *Income:Gains -30 USD* If I understand what you're trying to do, it is that rather than recognize a 30 USD income, you want to recognize that in EUR, but you want to split the gain into two postings: one for the USD gain, and one for the difference in currency (both in EUR). Note that you *could* write a plugin that post-processed your transactions and hits the price table to fetch the rates and split up all those capital gains postings automatically. > Once again, this is all driven by idea to have an explanation on how I got > from Day A net Worth to Day B Net Worth. > I must say I still don't understand how people who do trading and spend > and get paid in different currencies live without such report. I just > wouldn't trust calculation, if I can't see how I got from A to B. > People ignore the currency components, and think in terms of their home currency (folding in the change in currency into their P/L). Note: In my document > <https://docs.google.com/document/d/1z57E8KZ9hIF71s39dDKaE5ow1N7BdJ-eX8y2BFjR9kc/edit#>you > can see, that I have tested ledger, and It looks like ledger does > calculation as per desired calculation method, however it seems not to be > possible to produce a single income statement-like report. One would have > to query ledger is different ways and paste together different parts of > different reports, to get the situation as presented in Appendix A > <https://docs.google.com/document/d/1z57E8KZ9hIF71s39dDKaE5ow1N7BdJ-eX8y2BFjR9kc/edit#heading=h.ibvb27d8cznn> > > It has been later found however, that on more complex example, ledger > produces results with unrealized gains, which appear to be wrong. See more > details here > <https://groups.google.com/forum/#!topic/ledger-cli/t8spw-5sXt8>. > Ledger doesn't book specific sales against purchases. You have to match all your costs manually. In practice it's effectively impossible not to input errors like that. So much detail, so little time... > > > > > > >>> -- > 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 [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/beancount/d3086e02-6ce7-4b0e-b7ee-d45da5877a96%40googlegroups.com > <https://groups.google.com/d/msgid/beancount/d3086e02-6ce7-4b0e-b7ee-d45da5877a96%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/CAK21%2BhOrRP-bTzbjn%2BQPPifJ78b7e-qYi0V7VYVH9dkC5%2B8-Sw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
