Issue with Investment Positions/Trades

194 views
Skip to first unread message

Andrew Sail

unread,
Mar 28, 2017, 3:04:35 PM3/28/17
to Beancount
I'm receiving a strange error when trying to sell shares of an investment fund that I have previously purchased. Below is an example from my ledger, replaced with dummy data. In this example, I'm trying to buy 20 shares of the fund at $200/each, funded from my main account, and then sell them at $205/each (the sale is obviously just for the sake of my understanding of how to use the tool).

2017-01-01 * "buy 20 shares of VGHCX"
  Assets:Investments:Fidelity:Roth:VGHCX                  20 VGHCX{200 USD}
  Assets:Investments:Fidelity:Roth                       -4000 USD

2017-03-27 * "sell 20 shares of VGHCX"
  Assets:Investments:Fidelity:Roth:VGHCX                  -20 VGHCX{205 USD}
  Assets:Investments:Fidelity:Roth

2017-01-01 price VGHCX                              200.00 USD
2017-03-27 price VGHCX                              205.00 USD

The error I receive is below.

$ bean-check ledger.beancount 
/path/to/ledger.beancount:74:      No position matches "Posting(account='Assets:Investments:Fidelity:Roth:VGHCX', units=-20 VGHCX, cost=CostSpec(number_per=Decimal('205.00'), number_total=None, currency='USD', date=None, label=None, merge=False), price=None, flag=None, meta={'filename': '/path/to/ledger.beancount', 'lineno': 75})" against balance (20 VGHCX {200 USD, 2017-01-01})

This leads me to asking a few questions:
1) The obvious; what am I doing wrong? I simply want to sell the 20 shares of VGHCX at $205/share that I own and return the funds as USD to my main account (cash).
2) If I remove the sale, only my principal shows on my ledger, my investment's growth is not shown as a part of my net worth; is this correct, or is there a deeper rooted issue?
3) Should reporting price in my ledger impact my net worth and if not, where in bean-web or fava should I be able to refer to my growth for further analysis?

Thank you in advance for your help!

yegle

unread,
Mar 28, 2017, 3:08:05 PM3/28/17
to Beancount
When you sell your holdings, you should specify which lot you want to sell in the curly bracket. In your case, you should write the following.



2017-03-27 * "sell 20 shares of VGHCX"
  Assets:Investments:Fidelity:Roth:VGHCX                  -20 VGHCX{200 USD} @205 USD
  Assets:Investments:Fidelity:Roth


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/2e046181-afad-4010-8df3-63b97d399a2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Jason Chu

unread,
Mar 28, 2017, 4:03:28 PM3/28/17
to Beancount
To better understand how inventories work, I highly recommend reading http://furius.ca/beancount/doc/booking.  It explains why you have to select lots at all and the various booking methods you probably want to use.

In addition, yegle's example is missing the PnL/CapitalGains account, so you'll actually return the wrong amount to your Roth account.  The doc explains why.

I have converted nearly every one of my sales to using the {} ambiguous matching syntax and I feel so much better for it.

To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/2e046181-afad-4010-8df3-63b97d399a2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

--
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 post to this group, send email to bean...@googlegroups.com.

Andrew Sail

unread,
Mar 28, 2017, 4:08:34 PM3/28/17
to Beancount
Thanks! That's really helpful. Could you modify yegle's example to include a PnL/CapitalGains account? Are you suggesting I return principal to cash but growth to a gains account on sale? If you could also clarify what you mean by {} ambiguous matching syntax, I would really appreciate it.

yegle

unread,
Mar 28, 2017, 4:11:40 PM3/28/17
to Beancount
Ah right, you also need to book your profit/loss in a separate account. Thanks Jason for catching that.

A full example of the sell transaction with P/L:

2017-03-27 * "sell 20 shares of VGHCX"
  Assets:Investments:Fidelity:Roth:VGHCX                  -20 VGHCX{205 USD}
  Assets:Investments:Fidelity:Roth                        205 USD
  Assets:Investments:Fidelity:Roth:PL                      -5 USD


Do note that the {200 USD} notation is to specify your lot, If for some reason you have two lot both with same acquire price, you'll need to add date to disambiguate (something like {200 USD, 2017-01-01}). I believe this is explained in the doc.

To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscribe@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Andrew Sail

unread,
Mar 28, 2017, 4:53:16 PM3/28/17
to Beancount
If the value in the brackets represents my lot then shouldn't it be {200 USD} since that's what I purchased at? With that, wouldn't the second line not balance because I'm actually selling 20 shares @ 205?

Based on the documentation, I modified your suggestion to the following: 

2014-02-17 * "selling vghcx shares"
  Assets:Investments:Fidelity:Roth:VGHCX -20 VGHCX{200 USD} @ 205 USD Assets:Investments:Fidelity:Roth:Cash 4100 USD Assets:Investments:Fidelity:Roth:PnL

This results in my PnL reporting as -100. Is this now the proper way to report PnL?

Jason Chu

unread,
Mar 28, 2017, 5:02:06 PM3/28/17
to Beancount
Close.

PnL is an Income account, not an Asset.  The idea is you're selling the inventory, extracting its original value during the sale and recording the change in value in the PnL account.  The value that's being created comes from the Income account.

Remember that Income and Expense accounts only matter relative to some date (you could ask questions like, "how much income did I have in 2016?"), but Assets and Liabilities last forever (you wouldn't ask the question, "how much assets did I have in 2016?", instead you would say, "what was my balance (the sum of all transactions until a certain time) at the end of 2016?").

Andrew Sail

unread,
Mar 28, 2017, 5:11:26 PM3/28/17
to Beancount
Understood! Thank you for such a thorough explanation!

Last question; as income, this reports as negative... why?

Martin Blais

unread,
Mar 28, 2017, 10:49:03 PM3/28/17
to Beancount
From the POV of this set of accounts, income is something that left the owner in exchange for assets and/or expenses.

Beancount reports numbers as it stores them internally. Eventually there will be options to render values associated with the income, liabilities and equity accounts with inverted (positive) signs, but today we just render the internal values and the user has to remember the income, liabilities and equity accounts normally have negative balances.





To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscribe@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages