2

I'm entering journal entries for hledger for a 401k account and have questions about how it should work when an account goes through an exchange (I'm not sure what it is exactly; I guess the finance firm is doing internal shuffling of accounts).

Bucket2 Exchanges       $10000.00   995.000
Bucket1 Realized G/L    $100.00 0.000
Bucket1 Exchanges       -$10000.00  -1000.000

Each line has the bucket (account) associated with the transaction, the type of transaction, the USD amount it is worth, and the number of shares associated with it. I see shares being cashed out from Bucket1 to buy shares of Bucket2 (which have a slightly different cost). There is also the "Realized G/L" transaction which I assume is gains and losses from the transaction. There are no shares associated with it.

All of these occurred on the same day, so I'd like to track it as 2 transactions: one for the exchange and another for the Realized G/L transaction.

Here's what I have right now:

2019-13-31 * 401k exchange
    acct:401k  995.000 "Bucket2" @@ $10000.00
    acct:401k  -1000.000 "Bucket1" @@ $10000.00

2019-13-31 * Realized G/L
    acct:401k  $100.00
    acct:unknown  ; What should this be?

; Assert that the old account is empty.
2019-13-31 * Post-exchange assertion
    acct:401k  = .00 "Bucket1"

However, I have a few questions:

  • The assertion fails because the shares taken out of Bucket1 don't match those that I have tracked going into the bucket. I don't see any transactions I'm missing in the transaction history; where could they have come from? The price per share in the Exchange does not match the number of missing shares based on the gains and losses amount, so this is not where the missing data comes from.

  • Is the G/L transaction merely informational? Either way, how should I track it?

1

Your assertion entry fails to balance because it has just one regular posting. An unbalanced posting would work (parenthesise the account name).

I'm not sure exactly what's going on in your example, but here's an attempt at modeling a similar, complete scenario, with maximum correctness a la #1177.

2019-07-01 opening balances, add $10000 cash
    assets:cash                      $10000        = $10000
    equity:opening/closing balances

2019-07-01 purchase 1000 shares of BKT1 for $9900
    assets:bucket1                     1000 "BKT1" =   1000 "BKT1"  ; quotes because of the digit
    assets:cash                      -$9900        =   $100

; all shares cashed out from bucket1 to buy shares in bucket2:

2019-12-31 sell all BKT1 for $10000, and realize capital gains
    assets:bucket1                    -1000 "BKT1" =      0 "BKT1"
    equity:exchange                    1000 "BKT1"
    equity:exchange                 -$10000
    assets:cash                      $10000        = $10100
    revenues:tax-deferred:gains       $-100  ; gain for lot: 1000 BKT1 acquired 2019-07-01
    assets:cash                        $100        = $10200

2019-12-31 buy BKT2 with the proceeds
    assets:bucket2                      995 "BKT2" =    995 "BKT2"
    equity:exchange                    -995 "BKT2"
    equity:exchange                  $10000
    assets:cash                     -$10000        =   $200

I'm not sure I have it right though. It gives these reports:

cash transactions:

$ hledger reg -w 90,30 cash
2019-07-01 opening balances, add $10000..  assets:cash                $10000        $10000
2019-07-01 purchase 1000 shares of BKT1..  assets:cash                $-9900          $100
2019-12-31 sell all BKT1 for $10000, an..  assets:cash                $10000        $10100
                                           assets:cash                  $100        $10200
2019-12-31 buy BKT2 with the proceeds      assets:cash               $-10000          $200

bucket1 transactions:

$ hledger reg -w 90,30 bucket1
2019-07-01 purchase 1000 shares of BKT1..  ..1           1000 "BKT1"           1000 "BKT1"
2019-12-31 sell all BKT1 for $10000, an..  ..1          -1000 "BKT1"                     0

bucket2 transactions:

$ hledger reg -w 90,30 bucket2
2019-12-31 buy BKT2 with the proceeds      assets:bucket2         995 "BKT2"    995 "BKT2"

all ending balances:

$ hledger bal --flat -E
                   0  assets:bucket1
          995 "BKT2"  assets:bucket2
                $200  assets:cash
         1000 "BKT1"                 
         -995 "BKT2"  equity:exchange
             $-10000  equity:opening balances
               $-100  revenues:tax-deferred:gains
--------------------
              $-9900
         1000 "BKT1"

balance sheet:

$ hledger bs --flat -E
Balance Sheet 2019-12-31

                ||       2019-12-31 
================++==================
 Assets         ||                  
----------------++------------------
 assets:bucket1 ||                0 
 assets:bucket2 ||       995 "BKT2" 
 assets:cash    ||             $200 
----------------++------------------
                || $200, 995 "BKT2" 
================++==================
 Liabilities    ||                  
----------------++------------------
----------------++------------------
                ||                  
================++==================
 Net:           || $200, 995 "BKT2" 

balance sheet including (some) equity:

$ hledger bse --flat -E not:'opening balances'
Balance Sheet With Equity 2019-12-31

                 ||               2019-12-31 
=================++==========================
 Assets          ||                          
-----------------++--------------------------
 assets:bucket1  ||                        0 
 assets:bucket2  ||               995 "BKT2" 
 assets:cash     ||                     $200 
-----------------++--------------------------
                 ||         $200, 995 "BKT2" 
=================++==========================
 Liabilities     ||                          
-----------------++--------------------------
-----------------++--------------------------
                 ||                          
=================++==========================
 Equity          ||                          
-----------------++--------------------------
 equity:exchange || -1000 "BKT1", 995 "BKT2" 
-----------------++--------------------------
                 || -1000 "BKT1", 995 "BKT2" 
=================++==========================
 Net:            ||        $200, 1000 "BKT1" 

income statement:

$ hledger is --flat 
Income Statement 2019-07-01-2019-12-31

                             || 2019-07-01-2019-12-31 
=============================++=======================
 Revenues                    ||                       
-----------------------------++-----------------------
 revenues:tax-deferred:gains ||                  $100 
-----------------------------++-----------------------
                             ||                  $100 
=============================++=======================
 Expenses                    ||                       
-----------------------------++-----------------------
-----------------------------++-----------------------
                             ||                       
=============================++=======================
 Net:                        ||                  $100 
| improve this answer | |
0

So this turned out to be an off-by-one error on my part. I finally went through the history transaction history one by one and found out that later on the day I had previously synced, an entry was added. So when I added entries myself I limited the date range to the day after I had last synced until that day. I was therefore just missing a transaction since it fell in between that date gap.

(I think an answer makes sense so I can mark this as closed. Feel free (or I can) move this bit to the question and close it that way if preferred.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.