Total match sale and balance error

96 views
Skip to first unread message

Damien R.

unread,
Dec 18, 2023, 8:57:50 PM12/18/23
to Beancount
Hi,

I have an investment in a mutual fund that has been converted from one commodity to another. I'm trying to represent that in my ledger with a sale of the first commodity (it's a total match sale as everything is sold) and then a buy of the second one (that's how it appears on the statement):

    2023-06-21 * "Selling Commodity A"
       Assets:CA:Broker:COMMA  -3151.6173 COMMA {} @ 9.361 CAD
       Assets:CA:Broker:Cash       29502.29 CAD

Bean-check gives the following error:

    Transaction does not balance: (124.4641276 CAD)

I tried changing the tolerance for that commodity to 0.0001 but no luck with that. Any idea what is going on and what I should to to address it?

As I'm dealing with mutual fund issues right now, I'll piggy back on my first question and ask what's the state of the average booking method? From my understanding it's still not supported and from the documentation I couldn't find how I should deal with partial sales, if I want to sale 50% of one commodity for instance.


Thanks,
Damien

Martin Blais

unread,
Dec 18, 2023, 8:59:53 PM12/18/23
to bean...@googlegroups.com
When you sell something you need to account for P/L. 
You're missing an account posting for that P/L, the amount of which can be left to be automatically calculated by Beancount, for that $124.46

--
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/88cc74be-3d56-4ab5-964a-53689d988663n%40googlegroups.com.

Damien R.

unread,
Dec 18, 2023, 9:25:06 PM12/18/23
to Beancount
Thank you! It seems pretty obvious now... sorry for the dumb question!

If they had decided to sell only 50% of the commodity, what would have been the best way to handle it in my ledger? Use a total match to sell everything and buy back 50% of that commodity?

Martin Blais

unread,
Dec 18, 2023, 10:03:43 PM12/18/23
to bean...@googlegroups.com
On Mon, Dec 18, 2023 at 9:25 PM Damien R. <damien...@gmail.com> wrote:
Thank you! It seems pretty obvious now... sorry for the dumb question!

There are no dumb questions. Nothing to feel sorry about.

 
If they had decided to sell only 50% of the commodity, what would have been the best way to handle it in my ledger? Use a total match to sell everything and buy back 50% of that commodity?

No.
You would have declared selling -3151.6173/2 units of COMMA @ 9.361 CAD, the cash would be correspondingly half, and the inferred P/L would be half as well.


 
Le lundi 18 décembre 2023 à 20:59:53 UTC-5, bl...@furius.ca a écrit :
When you sell something you need to account for P/L. 
You're missing an account posting for that P/L, the amount of which can be left to be automatically calculated by Beancount, for that $124.46

On Mon, Dec 18, 2023 at 8:57 PM Damien R. <damien...@gmail.com> wrote:
Hi,

I have an investment in a mutual fund that has been converted from one commodity to another. I'm trying to represent that in my ledger with a sale of the first commodity (it's a total match sale as everything is sold) and then a buy of the second one (that's how it appears on the statement):

    2023-06-21 * "Selling Commodity A"
       Assets:CA:Broker:COMMA  -3151.6173 COMMA {} @ 9.361 CAD
       Assets:CA:Broker:Cash       29502.29 CAD

Bean-check gives the following error:

    Transaction does not balance: (124.4641276 CAD)

I tried changing the tolerance for that commodity to 0.0001 but no luck with that. Any idea what is going on and what I should to to address it?

As I'm dealing with mutual fund issues right now, I'll piggy back on my first question and ask what's the state of the average booking method? From my understanding it's still not supported and from the documentation I couldn't find how I should deal with partial sales, if I want to sale 50% of one commodity for instance.


Thanks,
Damien

--
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/88cc74be-3d56-4ab5-964a-53689d988663n%40googlegroups.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.

Damien R.

unread,
Dec 19, 2023, 8:54:52 AM12/19/23
to Beancount
Le lundi 18 décembre 2023 à 22:03:43 UTC-5, bl...@furius.ca a écrit :
On Mon, Dec 18, 2023 at 9:25 PM Damien R. <damien...@gmail.com> wrote:
Thank you! It seems pretty obvious now... sorry for the dumb question!

There are no dumb questions. Nothing to feel sorry about.

 
If they had decided to sell only 50% of the commodity, what would have been the best way to handle it in my ledger? Use a total match to sell everything and buy back 50% of that commodity?

No.
You would have declared selling -3151.6173/2 units of COMMA @ 9.361 CAD, the cash would be correspondingly half, and the inferred P/L would be half as well.
 
I did a few tries and when selling only part of the commodity, I get "ambiguous matches". I get that if I don't specify the cost basis beancount is not able to match the lot I want to sale, so I really don't know how I would write "sell 1000 COMMA, get 9361 in cash" in the context of a mutual fund.

Martin Blais

unread,
Dec 19, 2023, 9:02:46 AM12/19/23
to bean...@googlegroups.com
On Tue, Dec 19, 2023 at 8:54 AM Damien R. <damien...@gmail.com> wrote:
Le lundi 18 décembre 2023 à 22:03:43 UTC-5, bl...@furius.ca a écrit :
On Mon, Dec 18, 2023 at 9:25 PM Damien R. <damien...@gmail.com> wrote:
Thank you! It seems pretty obvious now... sorry for the dumb question!

There are no dumb questions. Nothing to feel sorry about.

 
If they had decided to sell only 50% of the commodity, what would have been the best way to handle it in my ledger? Use a total match to sell everything and buy back 50% of that commodity?

No.
You would have declared selling -3151.6173/2 units of COMMA @ 9.361 CAD, the cash would be correspondingly half, and the inferred P/L would be half as well.
 
I did a few tries and when selling only part of the commodity, I get "ambiguous matches". I get that if I don't specify the cost basis beancount is not able to match the lot I want to sale, so I really don't know how I would write "sell 1000 COMMA, get 9361 in cash" in the context of a mutual fund.

Can you run "bean-doctor context" around that transaction?  It's possible I put a heuristic on the total amount to be matched.


 

Damien R.

unread,
Dec 19, 2023, 12:30:12 PM12/19/23
to Beancount
Le mardi 19 décembre 2023 à 09:02:46 UTC-5, bl...@furius.ca a écrit :
On Tue, Dec 19, 2023 at 8:54 AM Damien R. <damien...@gmail.com> wrote:
Le lundi 18 décembre 2023 à 22:03:43 UTC-5, bl...@furius.ca a écrit :
On Mon, Dec 18, 2023 at 9:25 PM Damien R. <damien...@gmail.com> wrote:
Thank you! It seems pretty obvious now... sorry for the dumb question!

There are no dumb questions. Nothing to feel sorry about.

 
If they had decided to sell only 50% of the commodity, what would have been the best way to handle it in my ledger? Use a total match to sell everything and buy back 50% of that commodity?

No.
You would have declared selling -3151.6173/2 units of COMMA @ 9.361 CAD, the cash would be correspondingly half, and the inferred P/L would be half as well.
 
I did a few tries and when selling only part of the commodity, I get "ambiguous matches". I get that if I don't specify the cost basis beancount is not able to match the lot I want to sale, so I really don't know how I would write "sell 1000 COMMA, get 9361 in cash" in the context of a mutual fund.

Can you run "bean-doctor context" around that transaction?  It's possible I put a heuristic on the total amount to be matched.

Here goes. I've shortened the list of balances before and after transaction, lists were essentially the sames.

bean-doctor context accounts/broker/broker.beancount 2108
** Transaction Id --------------------------------

Hash:d9b1a802839532df6ff5a7fa90f3d538
Location: accounts/broker/broker.beancount:2108


** Balances before transaction --------------------------------

  Assets:CA:Broker:COMMA              5.3522 COMMA {9.342 CAD, 2018-03-15}
  Assets:CA:Broker:COMMA              1.1888 COMMA {9.337 CAD, 2018-03-28}
  [...]
  Assets:CA:Broker:COMMA             16.0548 COMMA {9.343 CAD, 2023-05-16}
  Assets:CA:Broker:COMMA              9.5853 COMMA {9.333 CAD, 2023-05-30}

  Assets:CA:Broker:Cash                                        -10000.00 CAD

  Income:CA:Broker:PnL


** Unbooked Transaction --------------------------------

2023-06-21 * "Selling COMMA"
  Assets:CA:Broker:COMMA  -1000.0000 COMMA {} @ 9.361 CAD  ;
  Assets:CA:Broker:Cash     9361.00 CAD                    ; 9361 CAD
  Income:CA:Broker:PnL                                     ;


** Transaction --------------------------------

2023-06-21 * "Selling COMMA"


** Residual and Tolerances --------------------------------



** Balances after transaction --------------------------------

  Assets:CA:Broker:COMMA              5.3522 COMMA {9.342 CAD, 2018-03-15}
  Assets:CA:Broker:COMMA              1.1888 COMMA {9.337 CAD, 2018-03-28}
  [...]
  Assets:CA:Broker:COMMA             16.0548 COMMA {9.343 CAD, 2023-05-16}
  Assets:CA:Broker:COMMA              9.5853 COMMA {9.333 CAD, 2023-05-30}

  Assets:CA:Broker:Cash                                        -10000.00 CAD

  Income:CA:Broker:PnL

Martin Blais

unread,
Dec 23, 2023, 1:44:44 PM12/23/23
to bean...@googlegroups.com
On Tue, Dec 19, 2023 at 12:30 PM Damien R. <damien...@gmail.com> wrote:
Le mardi 19 décembre 2023 à 09:02:46 UTC-5, bl...@furius.ca a écrit :
On Tue, Dec 19, 2023 at 8:54 AM Damien R. <damien...@gmail.com> wrote:
Le lundi 18 décembre 2023 à 22:03:43 UTC-5, bl...@furius.ca a écrit :
On Mon, Dec 18, 2023 at 9:25 PM Damien R. <damien...@gmail.com> wrote:
Thank you! It seems pretty obvious now... sorry for the dumb question!

There are no dumb questions. Nothing to feel sorry about.

 
If they had decided to sell only 50% of the commodity, what would have been the best way to handle it in my ledger? Use a total match to sell everything and buy back 50% of that commodity?

No.
You would have declared selling -3151.6173/2 units of COMMA @ 9.361 CAD, the cash would be correspondingly half, and the inferred P/L would be half as well.
 
I did a few tries and when selling only part of the commodity, I get "ambiguous matches". I get that if I don't specify the cost basis beancount is not able to match the lot I want to sale, so I really don't know how I would write "sell 1000 COMMA, get 9361 in cash" in the context of a mutual fund.

Can you run "bean-doctor context" around that transaction?  It's possible I put a heuristic on the total amount to be matched.

Here goes. I've shortened the list of balances before and after transaction, lists were essentially the sames.

Yeah, that makes sense. Which ones do you want to sell? It doesn't know.
You'd have to select the particular postings you want to sell (the "specific lot identification method").
That, or give that account a booking method, like FIFO or LIFO, and then it'll do it for you.


 

Damien Riegel

unread,
Dec 24, 2023, 9:21:30 PM12/24/23
to bean...@googlegroups.com

On Sat., Dec. 23, 2023, 13:44 Martin Blais, <bl...@furius.ca> wrote:
On Tue, Dec 19, 2023 at 12:30 PM Damien R. <damien...@gmail.com> wrote:
Le mardi 19 décembre 2023 à 09:02:46 UTC-5, bl...@furius.ca a écrit :
On Tue, Dec 19, 2023 at 8:54 AM Damien R. <damien...@gmail.com> wrote:
Le lundi 18 décembre 2023 à 22:03:43 UTC-5, bl...@furius.ca a écrit :
On Mon, Dec 18, 2023 at 9:25 PM Damien R. <damien...@gmail.com> wrote:
Thank you! It seems pretty obvious now... sorry for the dumb question!

There are no dumb questions. Nothing to feel sorry about.

 
If they had decided to sell only 50% of the commodity, what would have been the best way to handle it in my ledger? Use a total match to sell everything and buy back 50% of that commodity?

No.
You would have declared selling -3151.6173/2 units of COMMA @ 9.361 CAD, the cash would be correspondingly half, and the inferred P/L would be half as well.
 
I did a few tries and when selling only part of the commodity, I get "ambiguous matches". I get that if I don't specify the cost basis beancount is not able to match the lot I want to sale, so I really don't know how I would write "sell 1000 COMMA, get 9361 in cash" in the context of a mutual fund.

Can you run "bean-doctor context" around that transaction?  It's possible I put a heuristic on the total amount to be matched.

Here goes. I've shortened the list of balances before and after transaction, lists were essentially the sames.

Yeah, that makes sense. Which ones do you want to sell? It doesn't know.
You'd have to select the particular postings you want to sell (the "specific lot identification method").
That, or give that account a booking method, like FIFO or LIFO, and then it'll do it for you.

Indeed it makes sense that beancount can't figure which lot to sell. I think the booking method I'm looking for is "average" but it's not supported in v2 (and I haven't checked in v3). I've stumbled upon threads that discuss the subject and it seems quite tricky to implement. If you don't mind, could you explain what is the hard part? I think one of the patch set that enabled the feature was removed for performance reasons.

I could use FIFO or LIFO to track the number of shares owned in the mutual fund, but would that give me correct return numbers when using beangrow? I suppose it would but I'm not familiar enough with the way the IRR is computed to be sure.

You received this message because you are subscribed to a topic in the Google Groups "Beancount" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beancount/BTLie1Ds8DA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/CAK21%2BhM-Ubc%3DYg7%2BWCgjxs%3DLjEGD3ju5xm2L4Yo0axMXoOS29A%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages