transferring inventory from one account to another

389 views
Skip to first unread message

jrgo...@gmail.com

unread,
Sep 2, 2021, 1:37:37 AM9/2/21
to Beancount
Hi, 

I tried searching a bit in the documentation and this forum but not sure how to handle this case and carry forward cost-basis information. Imagine you buy some stock at institution 1 and transfer it to institution 2 and then sell. How should one record all this? I tried the following but I'm getting an error related to no positions found. 

Thanks,
Jonathan

2015-02-01 open Assets:Invest:ATrade

2015-02-01 open Assets:Invest:ATrade:Cash


2015-04-01 * "Buy some shares of Hooli in April 2015"

  Assets:Invest:ATrade                                   25 HOOL {10.00 USD, "first-lot"}

  Assets:Invest:ATrade:Cash                            -250 USD



2017-03-01 open Assets:Invest:ZTrade

2017-03-01 open Assets:Invest:ZTrade:Cash


2017-04-01 * "Transfer from ATrade to ZTrade"

  Assets:Invest:ATrade                                   -25 HOOL

  Assets:Invest:ZTrade                                   25 HOOL



2017-05-01 close Assets:Invest:ATrade


2018-05-03 * "Sell some shares of Hooli in May 2018"

  Assets:Invest:ZTrade                                   -25 HOOL {} @ 22.00 USD

  Assets:Invest:ZTrade:Cash


No position matches "Posting(account='Assets:Invest:ZTrade', units=-25 HOOL, cost=CostSpec(number_per=<class 'beancount.core.number.MISSING'>, number_total=None, currency='USD', date=None, label=None, merge=False), price=22.00 USD, flag=None, meta={'filename': '/Users/jonathan/Documents/Finances/beandata/test.beancount', 'lineno': 22})" against balance (25 HOOL)

Ben Blount

unread,
Sep 2, 2021, 2:30:20 AM9/2/21
to Beancount
Yeah this is high on my wishlist too. This came up a bunch for crypto users as well - you should find some examples if you search for crypto on the mailing list.

The workaround is you have to transfer the lots manually, e.g make two postings per lot - one to reduce the lot on the old account, then recreate it with the original date and cost in the new account.
direction
bean-doctor can help you easily get all the lots, you can then copy paste to make this a little less fussy.

I'm on mobile or I'd give you examples.

--
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 on the web visit https://groups.google.com/d/msgid/beancount/b3efe67c-a858-4c2c-af6b-26e7444dd9e1n%40googlegroups.com.

Martin Blais

unread,
Sep 2, 2021, 9:45:29 AM9/2/21
to Beancount
+1 re. Ben's answer.
How many of these do you really do?


jrgo...@gmail.com

unread,
Sep 2, 2021, 4:10:53 PM9/2/21
to Beancount
Thanks @Ben. 

It's not terribly common but I just encountered 5 of them so I think I handling them manually for now is fine. 

Follow-up question: If you want to compute the IRR how will this work? In my specific case I have an investment in a partnership that generated 5 stock distributions which I then moved to my trading account and then I later sold. I'm not clear on all accounting steps I need to record in beancount to make this work. In order to get the cost basis in the new account I have to transfer some cash over I think and then if I want to compute the IRR for the partnership I'm not sure yet how I would do that. 

Ben Blount

unread,
Sep 2, 2021, 5:59:37 PM9/2/21
to bean...@googlegroups.com
Depends on how you are computing IRR - it's not a beancount feature. Are you talking about Martin's experimental returns calculator? I haven't tried that out myself yet and I don't know if IRR is a feature it has.

Based on the IRR formula seems like you'd want to extract basis and cash flows for the investment under analysis, disregarding what account it's being held in. Or maybe you want to bucketize - treating tax-advantaged holdings differently from normal holdings, discounting taxes from the normal asset's IRR.

Martin Blais

unread,
Sep 2, 2021, 8:20:49 PM9/2/21
to Beancount
You can do groups in beangrow and if the accounts are used exclusively for the same group I think you can specify them both and compute the returns over the joint set. I'd have to look at it again it's been forever.

I do something like irr, it's just a little newton search or something. Check out the source code for detail, it's just a few lines of code. All the complexity in that project is over defining and extracting the right cash flows from a beancount stream of directives.



sm...@davethehappysinger.com

unread,
Sep 5, 2021, 7:45:12 PM9/5/21
to Beancount
May I chip in here and say that I have a *lot* of these. The case of transferring crypto around has been well discussed but it's a CGT asset in Aus and moving crypto between exchanges and hot/cold wallets is not uncommon for me: these number in the dozens, maybe even three figures.

I have also at times had multiple stockbrokers and while I can go with abstract account names ("Assets:Shares:<ticker>"), I've preferred to have per-institution accounts so where I have two active accounts at once the statements make sense. Every time I transfer holdings between brokers, those assets are transferred with their cost base attached.

Not sure what the syntax should be. Just eliding the "recipient" leg in a transfer populates the posting with the currency of the cost base: it's beautiful for capital gains but doesn't help us here. So this would break:

  2021-09-02 * "Buy BTC"                                                                       
    Assets:Exchange:AUD                       -1000.00 AUD                                     
    Assets:Exchange:BTC                           1.00 BTC {1000.00 AUD, 2021-09-02} @ 1000.00 AUD    
                                                                                               
  2021-09-03 * "Transfer BTC"                                                                  
    Assets:Exchange:BTC                          -1.00 BTC {}                                  
    Assets:Transfer:BTC                                                                      

(Assets:Transfer:BTC is populated with 1000 AUD, being the cost base; again, wonderful for capital gains, but not what we need here)
 
Perhaps:
                                                                      
  2021-09-03 * "Transfer BTC"                                                                  
    Assets:Exchange:BTC                          -1.00 BTC {}                                  
    Assets:Transfer:BTC                              1.00 BTC {}

This would add {} to the syntax of *augmenting* postings. Correct me if I'm wrong, but that "empty braces" syntax doesn't exist at present for augmentations. Perhaps it could be introduced to mean "dump residuals here, but keep the cost base rather than convert to cost currency". If this doesn't resolve to a single currency it's an error.

But that's really a question for Martin; please just consider this a keen +1 for this feature. I prefer strict booking so I manually fix these up but it would be nice to be able to write software that exports valid entries that beancount can interpolate with FIFO/LIFO in the first instance e.g. for debugging my own code before I make the txs "concrete" with explicit bookings.                                        

Justus Pendleton

unread,
Sep 10, 2021, 9:47:29 AM9/10/21
to Beancount
Here's a plugin I quickly threw together to do this. There are a few things in the code I'm not 100% sure about, so consider this a beta and let me know if it seems like it is doing the right thing or not for you.


It uses a custom directive so you'd write:

2021-09-10 custom "transfer" 100 APPL Assets:Schwab Assets:Fidelity

Caveats: I don't use crypto so maybe I don't understand what you're trying to do; also it transfers assets in LIFO order.

Martin Blais

unread,
Sep 11, 2021, 4:43:49 PM9/11/21
to Beancount
Thank you Justus,
Added to contrib doc.

Ben Blount

unread,
Sep 11, 2021, 4:47:06 PM9/11/21
to Beancount

Jonathan Goldman

unread,
Sep 11, 2021, 5:33:30 PM9/11/21
to bean...@googlegroups.com
Thanks Justus! I'll give it a try for my use case soon. 

Reply all
Reply to author
Forward
0 new messages