No position matches error

82 views
Skip to first unread message

salmi....@gmail.com

unread,
Apr 30, 2020, 11:46:46 AM4/30/20
to Beancount
I already checked this thread which seemed like a similar problem but I couldn't apply it to my case: https://groups.google.com/forum/#!topic/beancount/Qvbcq-Sk5NY

Anyway, I'm investing to a ETF with ticker EUNL monthly. Recently I sold some of my position and marked it to my ledger:
2020-03-10 * "EUNL sold"
  Assets:Nordnet:EUNL -20 EUNL @ 47.996 EUR
  Expenses:Financial:Commissions 15 EUR
  Assets:Nordnet:Cash 944.92 EUR


 Next time EUNL is mentioned in my ledger is just a random price definition when I wanted to know my asset worth at certain date:
2020-03-21 price EUNL 42.536 EUR


Today I tried to add a recent purchase of EUNL in a normal way like this:
2020-04-30 * "EUNL purchase"
  Assets:Nordnet:EUNL 8 EUNL {45.9998 EUR}
  Assets:Nordnet:Cash -368.00 EUR


but I get an error:
No position matches "Posting(account='Assets:Nordnet:EUNL', units=5 EUNL, cost=CostSpec(number_per=Decimal('45.9998'), number_total=None, currency='EUR', date=None, label=None, merge=False), price=None, flag=None, meta={'filename': '/home/tuomas/ledger/ledger.beancount', 'lineno': 5847})" against balance (-20 EUNL, 80 EUNL {45.10 EUR, 2018-04-30}, 6 EUNL {45.5980 EUR, 2018-05-07}, 2 EUNL {46.62 EUR, 2018-12-05}, 11 EUNL {46.6660 EUR, 2018-07-05}, 4 EUNL {46.8219 EUR, 2018-11-05}, 3 EUNL {47.0850 EUR, 2019-02-05}, 10 EUNL {47.2815 EUR, 2018-06-05}, 10 EUNL {48.5568 EUR, 2018-08-06}, 4 EUNL {48.6140 EUR, 2019-03-05}, 4 EUNL {49.2354 EUR, 2018-10-05}, 2 EUNL {49.3720 EUR, 2019-06-05}, 4 EUNL {50.49 EUR, 2019-04-05}, 3 EUNL {50.5220 EUR, 2019-08-05}, 4 EUNL {50.6877 EUR, 2019-05-06}, 3 EUNL {52.19 EUR, 2019-07-05}, 4 EUNL {52.436 EUR, 2019-10-07}, 3 EUNL {52.50 EUR, 2019-09-05}, 7 EUNL {52.9177 EUR, 2020-03-05}, 5 EUNL {54.5880 EUR, 2019-11-05}, 4 EUNL {55.14 EUR, 2019-12-05}, 4 EUNL {56.8213 EUR, 2020-01-07}, 3 EUNL {58.5676 EUR, 2020-02-05})



If I remove my selling transaction, the problem disappears. Based on the another thread it looks like this has something to do with how the Beancount tracks lots. To be honest I'm not completely familiar with that topic so I didn't figure out yet why my selling transaction breaks things. So my question is what I'm doing wrong here and how to fix this?

salmi....@gmail.com

unread,
Apr 30, 2020, 11:47:59 AM4/30/20
to Beancount
Oh, and I am using Beancount version 2.1.2

Red S

unread,
Apr 30, 2020, 1:44:27 PM4/30/20
to Beancount
This section of the documentation might help. Specifically:
Reductions
Augmentations vs. Reductions
Homogeneous and Mixed Inventories

Also, read this thread. In short, your sell transaction should look like this:

2020-03-10 * "EUNL sold"
  Assets:Nordnet:EUNL -20 EUNL {} @ 47.996 EUR
  Expenses:Financial:Commissions 15 EUR
  Assets:Nordnet:Cash 944.92 EUR
  Income:Capital-Gains XXX.XX EUR


The {} above might need a lot specification depending on your booking method, and whether you are reducing all positions or some.

salmi....@gmail.com

unread,
Apr 30, 2020, 3:03:55 PM4/30/20
to Beancount
Thanks. Didn't get it yet but I have few questions.

1) After reading the doc it seems to me that I should specify which lots I sold by using {} syntax, am I right? When I sell a part of my position, my bank does not let me to select which lots I'll sell. So I have difficulty in understanding how to apply the lot's price to the transaction. Based on my bank's report I only know that I sold 20 shares. And to clarify I sold only a part of my total position. 

2) Is the booking method (strict, fifo, lifo, average, none) somehow relevant in this and if so, what implications each one has? Since I can't manage which lots I sell from by bank, to me it seems like it would make sense to use average method. Or is this completely unrelated to my problem?

3) In the example transaction you gave I don't understand the point of the Income row. I sold 20 shares with price 47.996 EUR, and in return I had to pay 15 EUR commissions and I got 944.92 EUR to my Cash account. While this transaction would likely result in capital gain or loss, I don't understand how I would calculate that when I don't know the prices of lots I sold. Again I guess this is just a result of my confusion with the first question.

Finally I'm not shorting and this is the first transaction I'm selling this ETF so afaik the balance should not be negative in any part of the ledger as seems to be the case in some other threads. Anyway, I'll try to keep reading and figuring out what I should do.

Red S

unread,
Apr 30, 2020, 4:46:09 PM4/30/20
to Beancount
You're on the right track with your questions. Responses inline:


On Thursday, April 30, 2020 at 12:03:55 PM UTC-7, salmi...@gmail.com wrote:
Thanks. Didn't get it yet but I have few questions.

1) After reading the doc it seems to me that I should specify which lots I sold by using {} syntax, am I right? When I sell a part of my position, my bank does not let me to select which lots I'll sell. So I have difficulty in understanding how to apply the lot's price to the transaction. Based on my bank's report I only know that I sold 20 shares. And to clarify I sold only a part of my total position. 

If you bank does not let you select (STRICT booking, aka "specific identification of shares" in the US), it's possible they picked lots to sell using FIFO, LIFO, average cost, or some other method. I'm not familiar with the laws that apply to you, but you could either research this or back-work it out by asking your bank the value of the gains you realized in that transaction, if they are required by law to maintain that.

 
2) Is the booking method (strict, fifo, lifo, average, none) somehow relevant in this and if so, what implications each one has? Since I can't manage which lots I sell from by bank, to me it seems like it would make sense to use average method. Or is this completely unrelated to my problem?

Yes, this is very related to your problem. If you're sure it's not FIFO or LIFO, then it's likely AVERAGE. However, average cost booking is not yet implemented fully in Beancount. The simple hack is to use the NONE booking method. You can also simulate AVERAGE.

 
3) In the example transaction you gave I don't understand the point of the Income row. I sold 20 shares with price 47.996 EUR, and in return I had to pay 15 EUR commissions and I got 944.92 EUR to my Cash account. While this transaction would likely result in capital gain or loss, I don't understand how I would calculate that when I don't know the prices of lots I sold. Again I guess this is just a result of my confusion with the first question.

This gets into what you're trying to do, and what your tax laws require you to do. If you aren't required to report the gains (eg: tax sheltered accounts in the US are like this), you setting the booking method to NONE is a quick hack if you don't care about recording the gains for yourself. As Martin notes: "Note: If you are familiar with Ledger, this is the default and only booking method that it supports." So while it's one way of doing things, one of the things that made me move to Beancount from Ledger was booking methods beyond NONE.

 
Finally I'm not shorting and this is the first transaction I'm selling this ETF so afaik the balance should not be negative in any part of the ledger as seems to be the case in some other threads. Anyway, I'll try to keep reading and figuring out what I should do.

Your sale got counted as a short position. Your subsequent purchase was assumed to be a short-closing transaction, and beancount attempted to match it against your sale.



 

Martin Michlmayr

unread,
Apr 30, 2020, 9:32:39 PM4/30/20
to bean...@googlegroups.com
* salmi....@gmail.com <salmi....@gmail.com> [2020-04-30 12:03]:
> 2) Is the booking method (strict, fifo, lifo, average, none) somehow
> relevant in this and if so, what implications each one has? Since I
> can't manage which lots I sell from by bank, to me it seems like it
> would make sense to use average method. Or is this completely
> unrelated to my problem?

It typically depends on the tax laws of your country which lot is
sold first.

--
Martin Michlmayr
https://www.cyrius.com/

Martin Blais

unread,
Apr 30, 2020, 9:55:18 PM4/30/20
to Beancount
And it gets really weird if you're filing in two countries simultaneously (e.g. USA and Canada). Technically you'd have to maintain two cost bases (and I don't know how to do that in Beancount).


 

--
Martin Michlmayr
https://www.cyrius.com/

--
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/20200501013225.GA29967%40jirafa.cyrius.com.

salmi....@gmail.com

unread,
May 1, 2020, 2:54:09 AM5/1/20
to Beancount
Alright, this is starting to make some sense :) My country (Finland) uses FIFO method so I marked the relevant account as such:
2018-01-01 open Assets:Nordnet:EUNL EUNL "FIFO"

And then I mark the selling transaction like this:
2020-03-10 * "EUNL sold"
  Assets:Nordnet:EUNL -20 EUNL {} @ 47.996 EUR
  Expenses:Financial:Commissions 15 EUR
  Assets:Nordnet:Cash 944.92 EUR
  Income:Capital-Gain

This seems to resolve the problem and in Fava I can see the Capital-Gain having now a sensible value in euros. 

Is this correct? Fyi I don't use Beancount to make reports for taxation since most of the information about taxation is automatically reported to the tax office in Finland and I'm using Beancount just to keep track on my spending and net worth.

Red S

unread,
May 1, 2020, 3:49:23 AM5/1/20
to Beancount
Yes, that looks correct!

salmi....@gmail.com

unread,
May 1, 2020, 4:28:22 AM5/1/20
to Beancount
Thanks for help and explanations! Looks like I have to spend some time with Beancount docs on my vacation next week :) 

Martin Blais

unread,
May 1, 2020, 8:51:39 AM5/1/20
to Beancount
The commissions will trip up the p/l calculation a bit
I don't have a good workaround
See older posts on the list about that

--
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.
Reply all
Reply to author
Forward
0 new messages