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.