Check out what I do in this script:
https://github.com/beancount/beanlabs/blob/master/beanlabs/compensation/net-worth-over-time.py#L223

It could be made nicer, an iterator could be created that yields the state
at a given list of timestamps, so all the aggregation would be abstracted
away.



On Sat, Nov 27, 2021 at 5:10 AM Stefano Zacchiroli <[email protected]> wrote:

> On Fri, Nov 26, 2021 at 09:08:18AM -0500, Martin Blais wrote:
> >
> https://github.com/beancount/beancount/blob/master/beancount/ops/summarize.py#L589
>
> Thanks a lot Martin, I didn't know about
> beancount.ops.summarize.balance_by_accounts(), and now that I know it
> helped me simplify some code I had around.
>
> While I'm at it, the code in question compute the average daily balance
> in a given account for a given year and currency (which matters for
> fiscal reasons in Italy, don't ask...). The core of it looks like this:
>
>     # XXX naive approach: we re-calculate realizations from the beginning
> of the ledger
>     # to each day in the target year. It is acceptably fast, so we didn't
> bother making
>     # it more efficient than this (for now).
>     for day in tqdm(list(year_days(year))):
>         inventory = balance_by_account(entries, date=day)[0][account]
>         amount = inventory.get_currency_units(currency)
>         balances.append(amount.number)
>
> As per comment, it is good enough (takes ~20 seconds on my main ledger),
> but it's not great. What would be the best way/internal API to implement
> this "right", i.e., with a running balance that is updated with daily
> batches of entries?
>
> TIA,
> Cheers
> --
> Stefano Zacchiroli . [email protected] . upsilon.cc/zack          _. ^ ._
> Full professor of Computer Science              o     o   o     \/|V|\/
> Télécom Paris, Polytechnic Institute of Paris     o     o o    </>   <\>
> Co-founder & CTO Software Heritage            o o o     o       /\|^|/\
> Former Debian Project Leader & OSI Board Director               '" V "'
>
> --
> 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/20211127101046.tw5yy4x6b4ooxvmp%40upsilon.cc
> .
>

-- 
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/CAK21%2BhM2x0r2KkSkrdvnKS2tTFEK_KG2UrTv2jR2dbxh6njoAQ%40mail.gmail.com.

Reply via email to