Tax-deferred retirement accounts aren't like regular accounts in that their
tax treatment does not require keeping track of the cost basis.
Therefore, most institutions holding these accounts don't track the basis.

In Beancount, you use "NONE" to disable booking rules for those because
those accounts tend to break a bunch of rules.
e.g., sometimes they can take quarterly fees by seeling small amounts of
stock across all positions, etc.

One way I've been wanting to handle this is: aggregating the cost basis
over all same instruments whenever an opening trade is done.
This sets the average cost basis for that one posting per instrument.
Selling at this cost basis sells at the average cost basis.
I once prototyped this - 10 years ago? - and for a number of reasons put it
on the ice.
Right now you just set the cost basis that you want on sale.

Hopefully if you liquidate the account you and use the average cost basis
for those positions - which you would calculate manually
(I've done this in the past, it works.)

Don't use equity; use income for P/L, even if it's not taxable. Some of
your P/L accounts will be taxable, some not. That's fine.

As for why your example fails:

- Without FIFO booking it's using STRICT booking. It has 10 STOCK {1 USD}
and 10 STOCK {2 USD} in the inventory.
It doesn't know which onne to resolve to, so you get an ambiguous match
error.

- With FIFO it resolves to -5 STOCK1 {1 USD} but your second leg of 1
STOCK2 {10 USD} fails to balance.
$5 != $10.
You should write 1.00 STOCK2 {5.00 USD} to maintain the cost basis.






On Sat, Jun 21, 2025 at 5:40 PM Alex Kaufman <[email protected]> wrote:

> Hello beancount community (beancounters?)
>
> I have been struggling with how to manage retirement accounts in
> beancount. I think my problem may be primarily a conceptual one. Where I
> get particularly confused is in how to handle trades within retirement
> accounts for stocks/funds that have gained value. In these cases we havent
> realized income but there are trades that depend on the value gained for
> certain stocks/funds.
>
> I've included a minimal ledger below where I have tried to create an
> example of where I get confused. In the case of a retirement account when
> the rebalance transaction is performed there are gains relative to the
> average cost of STOCK1. Right now this ledger will throw an error because
> the rebalance transaction lot selection is ambiguous. The ambiguity could
> be resolved with FIFO or LIFO bookkeeping but this is beside the point.
>
> Say we set it to use FIFO bookkeeping. In this case the trade transaction
> as it is currently written does not balance. In beancount where should we
> say that $5 has come from? It isn't really income but it is necessary to
> balance the transaction. I thought about using Equity but then this becomes
> difficult to track the gains of the retirement account as a whole.
>
> I'd appreciate guidance on how to best handle this. Thank you in advance!
> -Alex
>
> option "operating_currency" "USD"
>
> 2024-01-01 open Assets:BankAccount
> 2024-01-01 open Equity:Opening-Balances
>
> 2024-01-02 pad Assets:BankAccount Equity:Opening-Balances
> 2024-01-03 balance Assets:BankAccount 100 USD
>
> 2024-12-31 open Assets:Broker:STOCK1 STOCK1
> 2024-12-31 open Assets:Broker:STOCK2 STOCK2
>
> 2025-01-01 * "investment 1"
>   Assets:Broker:STOCK1 10.00 STOCK1 {1.00 USD}
>   Assets:BankAccount -10.00 USD
>
> 2025-01-02 price STOCK1 2.00 USD
>
> 2025-01-02 * "investment 2"
>   Assets:Broker:STOCK1 10.00 STOCK1 {2.00 USD}
>   Assets:BankAccount  -20.00 USD
>
> 2025-01-02 price STOCK2 10.00 USD
>
> 2025-01-03 * "trade"
>     Assets:Broker:STOCK1 -5.00 STOCK1 {} @@ 10.00 USD
>     Assets:Broker:STOCK2 1.00 STOCK2 {10.00 USD}
>
> --
> 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 view this discussion visit
> https://groups.google.com/d/msgid/beancount/111f010c-6a0b-42b7-9ee7-19c77dd3e131n%40googlegroups.com
> <https://groups.google.com/d/msgid/beancount/111f010c-6a0b-42b7-9ee7-19c77dd3e131n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion visit 
https://groups.google.com/d/msgid/beancount/CAK21%2BhN8cCVXhS4ynnGgwo1km6O3obpDsep6pa3uwxWv3nF-5g%40mail.gmail.com.

Reply via email to