Managing Transfers within Retirement Accounts

68 views
Skip to first unread message

Alex Kaufman

unread,
Jun 21, 2025, 5:40:30 PM6/21/25
to Beancount
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}

Martin Blais

unread,
Jun 21, 2025, 6:54:55 PM6/21/25
to bean...@googlegroups.com
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.




 

--
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/111f010c-6a0b-42b7-9ee7-19c77dd3e131n%40googlegroups.com.

Red S

unread,
Jun 21, 2025, 7:01:41 PM6/21/25
to Beancount
I have been struggling with how to manage retirement accounts in beancount. I think my problem may be primarily a conceptual one.

IMHO, you’re spot on: truly understanding what’s going on at a conceptual level will then make the syntax and the rest of it very simple. So let me respond at that level.

 
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.

Just to clarify: income is actually realized, even within a retirement account when a stock is sold. Whether or not that income is taxed is immaterial do the bookkeeping itself.


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.

Issue #1: Realizing and booking income: See above. I book these to (for example) Income:Investments:Roth:Capital-Gains:Account1

Issue #2: Cost basis matters, because they will determine the cash balance in your account after any sale of stock. So how do you get that right? If your broker uses average cost booking within retirement accounts, note that Beancount does not currently support that method, automatically at least. A way for you to simulate it is to book this by 1) selling all your stock, 2) buying all them back at the average cost, and then 3) booking your actual sale.


Hope that helps.

Alex Kaufman

unread,
Jun 21, 2025, 11:00:45 PM6/21/25
to Beancount
Thank you both - really appreciate your responsiveness and willingness to help me understand this better. I'm going to work on this some more, and I might come back with some additional clarifications as I work through it. Thank you again!
Reply all
Reply to author
Forward
0 new messages