TL;DR: I'm wondering how should I balance out values when dealing with multiple currencies being traded over time along with normal expenses that might occur along the way, as well as transactions exclusive to separate currencies.
I have been timidly tinkering with double entry accounting recently and while I'm comfortable with the nature of balancing all transactions, I'm scratching my head to understand how to correctly process this across different currencies (or even if I should balance them against anything at all).
While I'm using ledger-cli, this is more of a conceptual question rather than one related to how this specific software works.
Suppose I begin with $ 5000 at the 1st, which being the single transaction will be balanced out by default:
2021/10/01
Assets:Cash $ 5000.00 ; D
Equity:Opening $ -5000.00 ; C
1. Trading at the simplest level
Let's work with a fictional staking cryptocurrency as an example, as this will enable me to showcase both the trading aspects and dividends, and to start let's say I'll buy an amount for $ 2 each:
2021/10/02
Assets:Crypto XPTO 864.00 ; D
Assets:Cash $ -1728.00 ; C
Buying an amount at a price of $ 2, I'll still have a balanced ledger, albeit with different currencies:
$ 3272.00
XPTO 864.00 Assets
$ 3272.00 Cash
XPTO 864.00 Crypto
$ -5000.00 Equity:Opening
--------------------
$ -1728.00
XPTO 864.00
Now let's say all that happens is that I sell XPTO at a later date at a higher price ($ 2.27). This will make my ledger unbalanced due to the capital gain obtained:
2021/10/07
Assets:Cash $ 1961.28 ; D
Assets:Crypto XPTO -864.00 ; C
This is how the ledger would be at this point:
$ 5233.28 Assets:Cash
$ -5000.00 Equity:Opening
--------------------
$ 233.28
Should I be looking to balance out the capital gain observing all accounts? Or should I only pay attention to the balance sheet?
As far as I understand, the next move should be accruing the capital gain as an income against my equity:
2021/10/07
Income:Gains $ 233.28 ; D
Equity:Profits $ -233.28 ; C
However, since this is double-entry, looking at all five accounts together (assets, liabilities, equity, income, expenses) will keep the ledger "unbalanced":
$ 5233.28 Assets:Cash
$ -5233.28 Equity
$ -5000.00 Opening
$ -233.28 Profits
$ 233.28 Income:Gains
--------------------
$ 233.28
On the other hand, if I just look at the balance sheet (assets, liabilities, equity), things will level out:
$ 5233.28 Assets:Cash
$ -5233.28 Equity
$ -5000.00 Opening
$ -233.28 Profits
--------------------
0
What I'm not sure right now is which of these two should I be looking for: the balance sheet is only "zeroed" because absolutely nothing happened between buying and selling the cryptocurrency. Now, if anything happens inbetween, this does not hold true anymore:
2021/10/04
Expenses:Sandwich $ 3.00 ; D
Assets:Cash $ -3.00 ; C
While the sandwich was yummy, I'm left in a pickle: the five accounts together will balance out its value, but keep the "inbalance" of the crypto. On the other hand, the balance sheet balances out the trade while keeping the "inbalance" of my sandwich:
; All five accounts together
$ 5230.28 Assets:Cash
$ -5233.28 Equity
$ -5000.00 Opening
$ -233.28 Profits
$ 3.00 Expenses:Sandwich
$ 233.28 Income:Gains
--------------------
$ 233.28
; Balance sheet only
$ 5230.28 Assets:Cash
$ -5233.28 Equity
$ -5000.00 Opening
$ -233.28 Profits
--------------------
$ -3.00
Which one of the two should I be aiming to balance out completely and which transaction would be needed for such?
2. Enter the fee
Now, to me things get even more complicated. Had I been trading stock, brokerage fees would be made in dollars, but since this is a crypto, let's work on the usual approach where fees are covered in crypto accordingly:
2021/10/01
Assets:Cash $ 5000.00 ; D
Equity:Opening $ -5000.00 ; C
2021/10/02
Assets:Crypto XPTO 864.00 ; D
Assets:Cash $ -1728.00 ; C
2021/10/02
Expenses:Brokerage XPTO 0.83 ; D
Assets:Crypto XPTO -0.83 ; C
Now let's say I'll still sell everything on the 7th like I did in the first example. Obviously, the amount won't be the same due to this fee:
2021/10/07
Assets:Cash $ 1959.40 ; D
Assets:Crypto XPTO -863.17 ; C
Now looking at the five accounts together, I'll have to deal with the capital gain as last time, but since the fees have both been debited and credited in XPTO, it'll always be there unless I do something, but since I've already sold everything of it, I'm not sure [what/if anything] should be done here:
$ 5231.40 Assets:Cash
$ -5000.00 Equity:Opening
XPTO 0.83 Expenses:Brokerage
--------------------
$ 231.40
XPTO 0.83
3. Receiving staking rewards
I'm pretty sure this will be the same or very similar to the previous case, but anyways, let's consider that this cryptocurrency rewards staking users. In a discussion with an accountant friend, he was of the opinion that should we be talking about personal ledgers, dividends would be accounted for as equity:
2021/10/01
Assets:Cash $ 5000.00 ; D
Equity:Opening $ -5000.00 ; C
2021/10/02
Assets:Crypto XPTO 864.00 ; D
Assets:Cash $ -1728.00 ; C
2021/10/02
Expenses:Brokerage XPTO 0.83 ; D
Assets:Crypto XPTO -0.83 ; C
2021/10/05
Assets:Crypto XPTO 51.79 ; D
Equity:Dividends XPTO -51.79 ; C
2021/10/07
Assets:Cash $ 2076.96 ; D
Assets:Crypto XPTO -914.96 ; C
Now both by looking at the five accounts together or just the balance sheet, I'll have inbalances in both currencies:
; All five accounts together
$ 5348.96 Assets:Cash
$ -5000.00
XPTO -51.79 Equity
XPTO -51.79 Dividends
$ -5000.00 Opening
XPTO 0.83 Expenses:Brokerage
--------------------
$ 348.96
XPTO -50.96
; Balance sheet only
$ 5348.96 Assets:Cash
$ -5000.00
XPTO -51.79 Equity
XPTO -51.79 Dividends
$ -5000.00 Opening
--------------------
$ 348.96
XPTO -51.79
Which in this case I'm not even sure if I should write the capital gains as it would be done in the first example, since I can't simply take the difference between buy and sell due to these staking rewards.
I'm probably missing a basic accounting operation in all of these cases, but I've struggled with this for months now and I always come back to square one. I hope the examples suffice to reach an answer, but please pinpoint to any unclear passages I've left here.
EDIT: making a case for the rationale based on Jérémie's answer
We were thinking if whenever a transaction involving a trading account would need to update exchange rates accodingly to the date the transaction was made. I'm pretty sure this is irrelevant and the only rates needed are the first and the last.
Let's rework the third example using a trading account:
2021/10/01
Assets:Cash $ 5000.00 ; D
Equity:Opening ; C
; Buying XPTO at $ 2
2021/10/02
Assets:Crypto XPTO 864.00 ; D
Trading:XPTO XPTO -864.00
Assets:Cash $ -1728.00 ; C
Trading:USD $ 1728.00
; I'll treat fees as if the rate never moved
2021/10/02
Expenses:Fees $ 1.66 ; D
Trading:USD $ -1.66 ; C
Assets:Crypto XPTO -0.83 ; D
Trading:XPTO XPTO 0.83 ; C
; The same for dividends (staking), even though we're in a different date
2021/10/05
Assets:Crypto XPTO 51.79 ; D
Trading:XPTO XPTO -51.79 ; C
Trading:USD $ 103.58 ; D
Equity:Dividends $ -103.58 ; C
Now, the balance at the 4th will look like:
$ 3272.00
XPTO 914.96 Assets
$ 3272.00 Cash
XPTO 914.96 Crypto
$ -5103.58 Equity
$ -103.58 Dividends
$ -5000.00 Opening
$ 1.66 Expenses:Fees
$ 1829.92
XPTO -914.96 Trading
$ 1829.92 USD
XPTO -914.96 XPTO
--------------------
0
Again, let's sell XPTO for $ 2.27:
2021/10/07
Assets:Cash $ 2076.96 ; D
Trading:USD $ -2076.96 ; C
Assets:Crypto XPTO -914.96 ; D
Trading:XPTO XPTO 914.96 ; C
The balance looks like this now:
$ 5348.96 Assets:Cash
$ -5103.58 Equity
$ -103.58 Dividends
$ -5000.00 Opening
$ 1.66 Expenses:Fees
$ -247.04 Trading:USD
--------------------
0
Now, if we take by logic, the profit should be 2076.96 - 1728.00 = 348.96 (all the dollars I got for selling XPTO vs. all the dollars I've spent for buying XPTO), so at first glance, it seems something is wrong.
However, if we take into account that we have already "pocketed" both the fee and the staking reward, the value to balance out is right: 103.58 + 247.04 - 1.66 = 348.96
Sure, this allows for some "creative accounting" depending on the situation and intent of the bookkeeper, but now I'm convinced the best way to handle this is through the use of the trading account.