Thanks for sharing your "recipe," Martin. That's a nifty query to get the
average cost.
The first solution doesn't quite work for me given it ends up with a mix of
positive and negative lot units, which bean-price doesn't aggregate, and
therefore incorrectly tries to look up prices for commodities that I have
zero of. Perhaps extending bean-prices to consider aggregates is a
solution. But I also do like the cleanliness of true lot reductions.
Knowing {} means all helps. In cases where it didn't, I moved a subset of
transactions to a FIFO account to help with automatic lot reduction.
Thanks again!
On Friday, November 29, 2019 at 6:27:45 AM UTC-8, Martin Blais wrote:
>
> Here's how I get around this myself now:
> 1. DIsable booking by using "NONE" on the account:
>
>
> 2016-01-01 open Assets:Inv "NONE"
> 2016-01-01 open Assets:Bank
> 2016-01-01 open Income:CapGains
>
> 2016-01-06 * "buy"
> Assets:Inv 3 XYZ {9 USD}
> Assets:Bank
>
> 2016-01-06 * "buy"
> Assets:Inv 3 XYZ {10 USD}
> Assets:Bank
>
> 2016-01-06 * "buy"
> Assets:Inv 4 XYZ {11 USD}
> Assets:Bank
>
> ;; 2016-01-07 * "sell"
> ;; Assets:Inv -10 XYZ {USD} @ 8 USD
> ;; Assets:Bank 80 USD
> ;; Income:CapGains
>
>
> Don't include your reducing transaction.
> Compute average cost manually:"
>
> bean-query avgcost.beancount "select account, sum(number),
> sum(cost(position)) where account = 'Assets:Inv' group by 1"
> account su sum_cos
> ---------- -- -------
> Assets:Inv 10 101 USD
>
> So I've got 10 units of XYZ at 101 USD total cost
>
> Insert your transaction:
>
> 2016-01-07 * "sell"
> Assets:Inv -10 XYZ {10.1 USD} @ 8 USD
> Assets:Bank 80 USD
> Income:CapGains
>
> which expands to
>
>
> bean-doctor linked avgcost.beancount 20
> /home/blais/r/q/beancount-data/user/redstreet0/avgcost.beancount:17:
>
> 2016-01-07 * "sell"
> Assets:Inv -10 XYZ {10.1 USD, 2016-01-07} @ 8 USD
> Assets:Bank 80 USD
> Income:CapGains 21.0 USD
>
>
> Alternatively if you know you capital gains somehow, in your specific
> case because you're selling the entire position (all of the 10 units)
> Beancount is able to match it against the full set of positions and
> reduce that, so this would run without errors:
>
> 2016-01-07 * "sell"
> Assets:Inv -10 XYZ {} @ 8 USD
> Assets:Bank 80 USD
> Income:CapGains 21 USD
>
> Unfortunately it's currently not able to do that if you don't supply the
> gains:
>
> 2016-01-07 * "sell"
> Assets:Inv -10 XYZ {} @ 8 USD
> Assets:Bank 80 USD
> Income:CapGains
>
>
>
>
>
> On Fri, Nov 29, 2019 at 3:37 AM Red S <[email protected] <javascript:>>
> wrote:
> >
> > Thanks, but that was the scenario I'm hoping to avoid. It involves way
> too many manual entries (for my case), or a bunch of scripting or plugins
> that will become obsolete once average cost booking is implemented.
> >
> > I guess I could use FIFO instead. My Income:Capital-Gains numbers may be
> off, but that shouldn't matter much.
> >
> > Do others have this issue at all?
> >
> > Thanks!
> >
> > On Tuesday, November 26, 2019 at 10:14:34 AM UTC-8, Martin Michlmayr
> wrote:
> >>
> >> * Red S <[email protected]> [2019-11-25 02:18]:
> >> > 2016-01-07 * "sell"
> >> > Assets:Inv -10 XYZ @ 8 USD
> >> > Assets:Bank 80 USD
> >> > Income:CapGains
> >>
> >> do it manually:
> >>
> >> 2016-01-07 * "sell"
> >> Assets:Inv -3 XYZ { 9 USD} @ 8 USD
> >> Assets:Inv -3 XYZ {10 USD} @ 8 USD
> >> Assets:Inv -4 XYZ {11 USD} @ 8 USD
> >> Assets:Bank 80 USD
> >> Income:CapGains
> >>
> >> or calculate average cost first manually:
> >>
> >> 2016-01-07 * "Calculate average cost"
> >> Assets:Inv 10 XYZ {10.1 USD}
> >> Assets:Inv -3 XYZ { 9 USD}
> >> Assets:Inv -3 XYZ {10 USD}
> >> Assets:Inv -4 XYZ {11 USD}
> >>
> >> 2016-01-07 * "sell"
> >> Assets:Inv -10 XYZ {10.1 USD} @ 8 USD
> >> Assets:Bank 80 USD
> >> Income:CapGains
> >>
> >>
> >>
> >> > So I really have zero units of XYZ. However, because of the way these
> are
> >> > booked, bean-price includes XYZ in its output. Given I have several
> such
> >> > cases, what is the best way to handle this? I can think of these:
> >> > - wait until average cost booking is available (will it solve this
> problem?)
> >> > - book the purchases above as prices instead of commodities held at
> cost
> >> > (will I lose the average cost of the commodity? How will I know the
> cost
> >> > basis to book profit and loss?)
> >> > - hack a way to get a list of commodities whose lots aggregate to
> zero, and
> >> > remove those from what bean-price lists?
> >> > - something else?
> >> >
> >> > Thank you.
> >> >
> >> > --
> >> > 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 [email protected].
> >> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/beancount/5e4d37c1-016d-499b-a988-a2cf0e7138eb%40googlegroups.com.
>
>
> >>
> >>
> >> --
> >> 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 [email protected] <javascript:>.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/beancount/9e714aa2-b9a3-4925-afaf-555646fb734f%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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/beancount/066c485d-fc4f-4988-a5d3-355f6aa965df%40googlegroups.com.