Questions on cost tracking

68 views
Skip to first unread message

Eric Altendorf

unread,
Aug 3, 2023, 8:37:03 PM8/3/23
to bean...@googlegroups.com
Couple questions on cost tracking:

1. When are acquisition dates tracked in Cost objects vs. not?

The query that I use for generating inventory reports at a particular time is this:
SELECT account, SUM(position) as lots,
UNITS(SUM(position)) AS total,
COST(SUM(position)) AS total_cost
FROM has_account("Assets") CLOSE ON 2020-01-01
WHERE currency~"BTC|ETH"

the lots column generates a list with entries like:
0.5000000000000000 BTC { 8900.0 USD}
0.2250000000000000 BTC { 7700.0 USD}
0.0239900000000000 BTC { 7100.4 USD}

At first I thought acquisition dates were not shown because SUM() is aggregating the amounts of lots with different dates, but now I'm not sure.  Is acquisition date tracked?  Should it be?  If it's not, is it likely user error in how I entered my transactions?

2. How exactly is cost munged in an asset transfer?

I'm looking at inventories (as reported by the previous query) before and after a transfer from one account to another.  I can see a selection of lots disappear from the inventory of the debited account.  I had thought these lots would appear in the same form in the credited account, but instead I see them aggregated into a single lot with what appears to be an averaged cost.

Is it possible to transfer the lots without collapsing?  In conjunction with my previous question, I think it will be necessary to transfer without collapsing in order to preserve acquisition dates on the cost, which will be needed to determine STCG vs LTCG.  Or perhaps the lots are being collapsed because I don't have dates attached, perhaps due to user error?

Bonus question: How can I induce more precision on the cost objects rendered in my inventory?  I typically only get one digit past the decimal point, not sure why.

Thanks :) :)

eric

Daniele Nicolodi

unread,
Aug 9, 2023, 4:38:58 PM8/9/23
to bean...@googlegroups.com
On 04/08/23 02:36, Eric Altendorf wrote:
> Couple questions on cost tracking:
>
> *1. When are acquisition dates tracked in Cost objects vs. not?*
>
> The query that I use for generating inventory reports at a particular
> time is this:
> SELECT account, SUM(position) as lots,
> UNITS(SUM(position)) AS total,
> COST(SUM(position)) AS total_cost
> FROM has_account("Assets") CLOSE ON 2020-01-01
> WHERE currency~"BTC|ETH"
>
> the lots column generates a list with entries like:
> 0.5000000000000000 BTC { 8900.0 USD}
> 0.2250000000000000 BTC { 7700.0 USD}
> 0.0239900000000000 BTC { 7100.4 USD}
>
> At first I thought acquisition dates were not shown because SUM() is
> aggregating the amounts of lots with different dates, but now I'm not
> sure.  Is acquisition date tracked?  Should it be?  If it's not, is it
> likely user error in how I entered my transactions?

AFAIK acquisition date is always tracked. However, when I implemented
the column rendering code for columns reporting postings and inventories
I decided to use a compact representation without the date and optional
labels. This choice can be revisited.

> *2. How exactly is cost munged in an asset transfer?*
>
> I'm looking at inventories (as reported by the previous query) before
> and after a transfer from one account to another.  I can see a selection
> of lots disappear from the inventory of the debited account.  I had
> thought these lots would appear in the same form in the credited
> account, but instead I see them aggregated into a single lot with what
> appears to be an averaged cost.
>
> Is it possible to transfer the lots without collapsing?  In conjunction
> with my previous question, I think it will be necessary to transfer
> without collapsing in order to preserve acquisition dates on the cost,
> which will be needed to determine STCG vs LTCG.  Or perhaps the lots are
> being collapsed /because/ I don't have dates attached, perhaps due to
> user error?

I'm not sure I understand what you are trying to do, what beancount
does, and what you expect it to be doing. Can you present a minimal
ledger that shows the problem?

> *Bonus question:* How can I induce more precision on the cost objects
> rendered in my inventory?  I typically only get one digit past the
> decimal point, not sure why.

Just write them with the desired amount of decimal digits in the ledger.
If this does not work as expected, again, please provide a minimal
ledger demonstrating the problem.

Cheers,
Dan

Eric Altendorf

unread,
Aug 9, 2023, 6:36:26 PM8/9/23
to bean...@googlegroups.com
On Wed, Aug 9, 2023 at 1:38 PM Daniele Nicolodi <dan...@grinta.net> wrote:
>
> At first I thought acquisition dates were not shown because SUM() is
> aggregating the amounts of lots with different dates, but now I'm not
> sure.  Is acquisition date tracked?  Should it be?  If it's not, is it
> likely user error in how I entered my transactions?

AFAIK acquisition date is always tracked. However, when I implemented
the column rendering code for columns reporting postings and inventories
I decided to use a compact representation without the date and optional
labels. This choice can be revisited.

Thank you for the confirmation and explanation.  The compact representation is reasonable.  I discovered the cost_date column which allowed me to debug this and see what was going on inside.
 
> *2. How exactly is cost munged in an asset transfer?*
>
> I'm looking at inventories (as reported by the previous query) before
> and after a transfer from one account to another.  I can see a selection
> of lots disappear from the inventory of the debited account.  I had
> thought these lots would appear in the same form in the credited
> account, but instead I see them aggregated into a single lot with what
> appears to be an averaged cost.
>
> Is it possible to transfer the lots without collapsing?  In conjunction
> with my previous question, I think it will be necessary to transfer
> without collapsing in order to preserve acquisition dates on the cost,
> which will be needed to determine STCG vs LTCG.  Or perhaps the lots are
> being collapsed /because/ I don't have dates attached, perhaps due to
> user error?

I'm not sure I understand what you are trying to do, what beancount
does, and what you expect it to be doing. Can you present a minimal
ledger that shows the problem?

Sure, here is one.  Perhaps my understanding or expectations are wrong (or I've made a dumb typo).

2000-01-01 open Equity:Opening-Balances
2020-01-01 open Assets:BrokerA:USD USD
2020-01-01 open Assets:BrokerA:ASSET ASSET
2020-01-01 open Assets:BrokerB:ASSET ASSET

2020-01-01 pad      Assets:BrokerA:USD  Equity:Opening-Balances
2020-01-02 balance  Assets:BrokerA:USD  100.00 USD

2020-02-01 * "Buy some ASSET"
  Assets:BrokerA:ASSET                   5.00 ASSET {10.00 USD}
  Assets:BrokerA:USD                   -50.00 USD

2020-03-01 * "Buy some more ASSET"
  Assets:BrokerA:ASSET                   4.00 ASSET {12.50 USD}
  Assets:BrokerA:USD                   -50.00 USD

2020-05-01 * "Transfer ASSET"
  Assets:BrokerA:ASSET                  -9.00 ASSET
  Assets:BrokerB:ASSET                   9.00 ASSET 



Now I try these two queries on the ledger:

beanquery> SELECT account, position, cost_date FROM has_account("Assets") CLOSE ON 2020-04-01
        account                   position          cost_date
-----------------------  -------------------------  ----------
Assets:BrokerA:USD        100.00 USD                          
Equity:Opening-Balances  -100.00 USD                          
Assets:BrokerA:ASSET        5.00 ASSET {10.00 USD}  2020-02-01
Assets:BrokerA:USD        -50.00 USD                          
Assets:BrokerA:ASSET        4.00 ASSET {12.50 USD}  2020-03-01
Assets:BrokerA:USD        -50.00 USD      

beanquery> SELECT account, position, cost_date FROM has_account("Assets") CLOSE ON 2020-06-01
        account                   position          cost_date
-----------------------  -------------------------  ----------
Assets:BrokerA:USD        100.00 USD                          
Equity:Opening-Balances  -100.00 USD                          
Assets:BrokerA:ASSET        5.00 ASSET {10.00 USD}  2020-02-01
Assets:BrokerA:USD        -50.00 USD                          
Assets:BrokerA:ASSET        4.00 ASSET {12.50 USD}  2020-03-01
Assets:BrokerA:USD        -50.00 USD                          
Assets:BrokerA:ASSET       -9.00 ASSET                        
Assets:BrokerB:ASSET        9.00 ASSET      


Before the transfer, it appears the the two lots appear separately in BrokerA with a cost and date.  After the transfer, in the BrokerB account, they've been merged with no cost or date.

If I annotate one, the other, or both legs of the transfer transaction in the ledger, with either "{USD}" or "{}" cost specs, I can induce various other behaviors, but I'm just acting like a monkey with a keyboard :) , and none of them are what I want, which is for BrokerB to contain both lots with the original cost info.

I think this is the same question I asked here: https://groups.google.com/g/beancount/c/vDX1oA2mJXA/m/Y8yZqUqPAQAJ

eric

Eric Altendorf

unread,
Aug 15, 2023, 8:35:44 PM8/15/23
to bean...@googlegroups.com
So, I've made a bunch of progress on many of my issues, but I
haven't yet figured out how to get cost tracking through transfers
working.  It's illustrated by example in the below email.

Any suggestions on how to start attacking this are welcome.  I
am willing to jump into beancount core code if need be -- I am
actually not even entirely sure what work, if any, is needed
there (see my questions on this other thread)

thanks,
eric

Red S

unread,
Aug 21, 2023, 11:38:26 PM8/21/23
to Beancount
Your example doesn't involve transferring. You're buying a brand new lot of 9 units (short) in A, and buying a brand new lot of 9 units (long) in B. Specify the lot to transfer. Use `balances` inside bean-query to confirm.

Eric Altendorf

unread,
Aug 22, 2023, 12:32:28 AM8/22/23
to bean...@googlegroups.com
On Mon, Aug 21, 2023 at 20:38 Red S <redst...@gmail.com> wrote:
Your example doesn't involve transferring. You're buying a brand new lot of 9 units (short) in A, and buying a brand new lot of 9 units (long) in B. Specify the lot to transfer. Use `balances` inside bean-query to confirm.

Fair enough.

In that case what I’m looking for is a feature request to automatically make the augmentation leg lots match whatever the booking algo decides are the reduction lots.  It seems Martin has discussed this possibility in the past, which made me think it was a reasonable direction.

I’ve started working on this, see other thread. 


--
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/7835f45f-a836-4dba-b66e-4d391826b13fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages