Two questions about budgeting

25 views
Skip to first unread message

Marcin Borkowski

unread,
Jan 24, 2023, 2:52:28 AM (13 days ago) Jan 24
to Ledger
Hi all,

as I mentioned previously, I finally decided to finish my booklet about
Ledger, and I really want to show how to do budgeting with it.

However, I myself cannit grok it. Please help.

Here is my example file (totally fake).

--8<---------------cut here---------------start------------->8---
~ Daily
Expenses:Food 30.00 PLN
Assets

~ Monthly
Expenses:Books 200.00 PLN
Assets

2022-01-02 Groceries
Expenses:Food 20.00 PLN
Assets:Cash

2022-01-03 C.S.Lewis "That hideous strength"
Expenses:Books 45.00 PLN
Assets:Cash

2022-01-03 Groceries
Expenses:Food 100.00 PLN
Assets:Cash
--8<---------------cut here---------------end--------------->8---

I ran a budgeting command against this file, and I don't know how to
interpret its output.

--8<---------------cut here---------------start------------->8---
$ ledger reg -f budget-example.ledger ^expenses -b 2022-01-01 -e 2022-01-04 -y %Y-%m-%d --invert --budget
2022-01-02 Budget transaction Expenses:Food 30.00 PLN 30.00 PLN
2022-01-01 Budget transaction Expenses:Books 200.00 PLN 230.00 PLN
2022-01-02 Groceries Expenses:Food -20.00 PLN 210.00 PLN
2022-01-03 Budget transaction Expenses:Food 30.00 PLN 240.00 PLN
2022-01-03 C.S.Lewis "..." Expenses:Books -45.00 PLN 195.00 PLN
2022-01-03 Groceries Expenses:Food -100.00 PLN 95.00 PLN
--8<---------------cut here---------------end--------------->8---

1. Why is there no "budget transaction" for groceries for 2022-01-01?
2. I would assume that after these three days my "books" budget should
allow me to spend 155 PLN more on books and my "food" budget would
be short of 30 PLN. Yet I can see neither of these amounts in the
report. How to make Ledger compute them?

TIA,

--
Marcin Borkowski
http://mbork.pl

Marcin Borkowski

unread,
Jan 24, 2023, 11:37:56 PM (12 days ago) Jan 24
to Ledger

On 2023-01-24, at 08:52, Marcin Borkowski <mb...@mbork.pl> wrote:

> Hi all,
>
> as I mentioned previously, I finally decided to finish my booklet about
> Ledger, and I really want to show how to do budgeting with it.
>
> However, I myself cannit grok it. Please help.
>
> [...]

Hi all,

I figured out (a few) things. First of all, using ~bal~ instead of
~reg~ helped (as did adding ~--monthly~). Still, it looks like
there's a bug with ~Daily~ periodic transactions: if I have a ~Daily~
~Food~ expense of 30 PLN, it is only counted towards my budget on days
an actual ~Food~ expense was made.

Is this by design? If so, how do I get the correct budget? The
problem with using a ~Monthly~ budget amounts is that they don't tell
me /in the middle of the month/ if I'm ahead or behind -- I hoped
~Daily~ periodic transactions could help with that...

Best,

Marcin Borkowski

unread,
Jan 25, 2023, 12:43:32 PM (11 days ago) Jan 25
to Ihor Radchenko, Ledger

On 2023-01-25, at 14:29, Ihor Radchenko <yant...@posteo.net> wrote:

> Marcin Borkowski <mb...@mbork.pl> writes:
>
>>... Still, it looks like
>> there's a bug with ~Daily~ periodic transactions: if I have a ~Daily~
>> ~Food~ expense of 30 PLN, it is only counted towards my budget on days
>> an actual ~Food~ expense was made.
>
> I think that ~ Daily alone is ambiguous. When should it start? Infinite
> years back? You need to specify at least "from" in addition. Otherwise,
> what ledger does kind of makes sense - budget only when you actually
> spend. Anything else would be insane.

Well, yes and no -- I took care to supply `--begin` in my Ledger
invocation.

By the way, is there a way to supply a starting date /in the Ledger file
itself/?

Also, daily budget makes /a lot/ of practical sense. If my monthly food
budget is, say, 600 PLN, it's Jan 25 and I've spent 480 PLN on food,
I can't immediately tell if I'm overspending or not. For the record,
I wrote myself a very simple web app which gets data from Ledger and
displays my spending this month against budget computed /for today/ (so
in the above case it would tell me that I'm ahead of my budget). It
would be cool if Ledger could provide such information, too...

Marcin Borkowski

unread,
Jan 25, 2023, 2:51:22 PM (11 days ago) Jan 25
to Ihor Radchenko, Ledger

On 2023-01-25, at 18:58, Ihor Radchenko <yant...@posteo.net> wrote:

> I meant
>
> ~ Daily from 2023/01/01
> Expenses:Food ...
> Assets:Checking
>
> Not sure about global "from".

Ah, I see.

>> Also, daily budget makes /a lot/ of practical sense. If my monthly food
>> budget is, say, 600 PLN, it's Jan 25 and I've spent 480 PLN on food,
>> I can't immediately tell if I'm overspending or not. For the record,
>> I wrote myself a very simple web app which gets data from Ledger and
>> displays my spending this month against budget computed /for today/ (so
>> in the above case it would tell me that I'm ahead of my budget).
>
> Yup, I totally agree that it is useful. I have such thing too :)
> https://github.com/yantar92/emacs-config/blob/master/system-config.org#continuous-monitoring-of-budget
> Displayed right at my status bar.
>
>> It
>> would be cool if Ledger could provide such information, too...
>
> But isn't it already the case? The balance with budget already provides
> this info.

What it doesn't do (or at least I can't do it) is to tell me that
(sticking to the example above) my food budget /for Jan 25/ is ~484 PLN,
so if I already spent 480 PLN, I'm good. Ledger can only tell me that
I can still spend 120 PLN /until the end of the month/, which is the
same mathematically -- but doing these calculations in your head is not
always easy.

Ihor Radchenko

unread,
Jan 25, 2023, 5:23:33 PM (11 days ago) Jan 25
to Marcin Borkowski, Ledger
Marcin Borkowski <mb...@mbork.pl> writes:

>> I think that ~ Daily alone is ambiguous. When should it start? Infinite
>> years back? You need to specify at least "from" in addition. Otherwise,
>> what ledger does kind of makes sense - budget only when you actually
>> spend. Anything else would be insane.
>
> Well, yes and no -- I took care to supply `--begin` in my Ledger
> invocation.

> By the way, is there a way to supply a starting date /in the Ledger file
> itself/?

I meant

~ Daily from 2023/01/01
Expenses:Food ...
Assets:Checking

Not sure about global "from".

> Also, daily budget makes /a lot/ of practical sense. If my monthly food
> budget is, say, 600 PLN, it's Jan 25 and I've spent 480 PLN on food,
> I can't immediately tell if I'm overspending or not. For the record,
> I wrote myself a very simple web app which gets data from Ledger and
> displays my spending this month against budget computed /for today/ (so
> in the above case it would tell me that I'm ahead of my budget).

Yup, I totally agree that it is useful. I have such thing too :)
https://github.com/yantar92/emacs-config/blob/master/system-config.org#continuous-monitoring-of-budget
Displayed right at my status bar.

> It
> would be cool if Ledger could provide such information, too...

But isn't it already the case? The balance with budget already provides
this info.

--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Ihor Radchenko

unread,
Jan 25, 2023, 5:23:33 PM (11 days ago) Jan 25
to Marcin Borkowski, Ledger
Marcin Borkowski <mb...@mbork.pl> writes:

>> But isn't it already the case? The balance with budget already provides
>> this info.
>
> What it doesn't do (or at least I can't do it) is to tell me that
> (sticking to the example above) my food budget /for Jan 25/ is ~484 PLN,
> so if I already spent 480 PLN, I'm good. Ledger can only tell me that
> I can still spend 120 PLN /until the end of the month/, which is the
> same mathematically -- but doing these calculations in your head is not
> always easy.

I see. Why don't just use daily budget then?
The daily budget gets applied progressively, and I know how much I can
spend each day.

Ihor Radchenko

unread,
Jan 25, 2023, 5:23:33 PM (11 days ago) Jan 25
to Marcin Borkowski, Ledger
Marcin Borkowski <mb...@mbork.pl> writes:

>... Still, it looks like
> there's a bug with ~Daily~ periodic transactions: if I have a ~Daily~
> ~Food~ expense of 30 PLN, it is only counted towards my budget on days
> an actual ~Food~ expense was made.

I think that ~ Daily alone is ambiguous. When should it start? Infinite
years back? You need to specify at least "from" in addition. Otherwise,
what ledger does kind of makes sense - budget only when you actually
spend. Anything else would be insane.

Marcin Borkowski

unread,
Jan 26, 2023, 12:43:34 AM (11 days ago) Jan 26
to Ihor Radchenko, Ledger

On 2023-01-25, at 21:14, Ihor Radchenko <yant...@posteo.net> wrote:

> Marcin Borkowski <mb...@mbork.pl> writes:
>
>>> But isn't it already the case? The balance with budget already provides
>>> this info.
>>
>> What it doesn't do (or at least I can't do it) is to tell me that
>> (sticking to the example above) my food budget /for Jan 25/ is ~484 PLN,
>> so if I already spent 480 PLN, I'm good. Ledger can only tell me that
>> I can still spend 120 PLN /until the end of the month/, which is the
>> same mathematically -- but doing these calculations in your head is not
>> always easy.
>
> I see. Why don't just use daily budget then?
> The daily budget gets applied progressively, and I know how much I can
> spend each day.

That's what I wanted to do. But since the daily budget apparently does
not kick in on days when I spent nothing on e.g. food, this is of little
use for me... If my daily budget is 20 PLN and I spend nothing on
a particular day, I expect to be "allowed" to spend 40 PLN on the next
day.

Ihor Radchenko

unread,
Jan 26, 2023, 1:09:38 AM (11 days ago) Jan 26
to Marcin Borkowski, Ledger
Marcin Borkowski <mb...@mbork.pl> writes:

>> I see. Why don't just use daily budget then?
>> The daily budget gets applied progressively, and I know how much I can
>> spend each day.
>
> That's what I wanted to do. But since the daily budget apparently does
> not kick in on days when I spent nothing on e.g. food, this is of little
> use for me... If my daily budget is 20 PLN and I spend nothing on
> a particular day, I expect to be "allowed" to spend 40 PLN on the next
> day.

Sorry, I think you missed my first reply.

Try

~ Daily from 2022
Expenses:Food 30.00 PLN
Assets

2022-01-02 Groceries
Expenses:Food 20.00 PLN
Assets:Cash

2022-01-03 C.S.Lewis "That hideous strength"
Expenses:Books 45.00 PLN
Assets:Cash

2022-01-03 Groceries
Expenses:Food 100.00 PLN
Assets:Cash


> ledger reg -f /tmp/test.dat ^expenses -b 2022-01-01 -e 2022-01-04 -y %Y-%m-%d --invert --budget
2022-01-01 Budget transaction Expenses:Food 30.00 PLN 30.00 PLN
2022-01-02 Budget transaction Expenses:Food 30.00 PLN 60.00 PLN
2022-01-02 Groceries Expenses:Food -20.00 PLN 40.00 PLN
2022-01-03 Budget transaction Expenses:Food 30.00 PLN 70.00 PLN
2022-01-03 Groceries Expenses:Food -100.00 PLN -30.00 PLN

John Wiegley

unread,
Jan 27, 2023, 4:39:58 PM (9 days ago) Jan 27
to Marcin Borkowski, Ledger
>>>>> "MB" == Marcin Borkowski <mb...@mbork.pl> writes:

> 1. Why is there no "budget transaction" for groceries for 2022-01-01?

Use this:

~ Daily from 2022-01-01

> 2. I would assume that after these three days my "books" budget should
> allow me to spend 155 PLN more on books and my "food" budget would
> be short of 30 PLN. Yet I can see neither of these amounts in the
> report. How to make Ledger compute them?

Did you try the "budget" report?

John

Marcin Borkowski

unread,
Jan 30, 2023, 1:00:35 AM (7 days ago) Jan 30
to ledge...@googlegroups.com

On 2023-01-27, at 22:39, John Wiegley <jwie...@gmail.com> wrote:

>>>>>> "MB" == Marcin Borkowski <mb...@mbork.pl> writes:
>
>> 1. Why is there no "budget transaction" for groceries for 2022-01-01?
>
> Use this:
>
> ~ Daily from 2022-01-01

Great, thanks!

>> 2. I would assume that after these three days my "books" budget should
>> allow me to spend 155 PLN more on books and my "food" budget would
>> be short of 30 PLN. Yet I can see neither of these amounts in the
>> report. How to make Ledger compute them?
>
> Did you try the "budget" report?

No, it looks /very/ good!

I did some experiments, and here is what I came up with. Can you
confirm that I guessed correctly?

1. I can do

~ Daily from 2022-01-01 to 2023-01-01

~ Daily from 2023-01-01

(the intervals are closed-open, like with -b/-e). Right?

2. The --invert option does nothing for the `budget` report. Correct?

3. If I don't provide -b, the default for the budget seems to be what
was in `~ Daily from`, but the transactions from before that date also
count towards the actual expenses. That probably means that I should
/always/ provide -b to the `budget` report. Is that right?

4. If I don't provide -e, the default (for the `budget` report) is
--current. Is that correct?

5. If I don't provide `from` in `~ Daily`, the default seems to be the
date if the /first/ transaction on a given account. Right?

6. (Almost) last but not least -- the `budget` report gives me a table
with 5 columns:
- actual expenses
- budgeted expenses
- the difference (negative means I spent less than the budget --
a bit counterintuitive, but makes sense given the order of the
previous two)
- what percentage of the budget was spent
- name of the account

Using classical spreadsheet column names: C = A - B and D = A/B (as
percentage). Do I guess correctly?

If so, this means that the web app I wrote to present this exact
information is mostly irrelevant. %-P Still, it draws a nice chart
which is accessible from a smartphone. I have a post-commit hook which
scp's the file to my VPS, and the web app there serves the chart -
that's a very useful arrangement I plan to blog about one day.

Now, my final question is this. Much of what we discuss here is
apparently undocumented in the Ledger manual. My book is my book, and
it contains examples and such, but I think it is fair to have these
options at least mentioned in the manual. I have just fetched the
ledger repo, and I can see that the last commit in
`ledger/doc/ledger3.texi` was 7 years ago... Would you accept a PR with
a small manual update? (One minor issue with that idea is that I don't
speak texinfo, so you'd have to check every my edit very carefully.)

Best,

John Wiegley

unread,
Feb 3, 2023, 1:42:49 PM (2 days ago) Feb 3
to Marcin Borkowski, ledge...@googlegroups.com
>>>>> "MB" == Marcin Borkowski <mb...@mbork.pl> writes:

MB> 1. I can do
MB> ~ Daily from 2022-01-01 to 2023-01-01
MB> ~ Daily from 2023-01-01
MB> (the intervals are closed-open, like with -b/-e). Right?

Yes, intervals should always be closed-open, everywhere.

MB> 2. The --invert option does nothing for the `budget` report. Correct?

I wouldn't be surprised at all if that were the case.

MB> 3. If I don't provide -b, the default for the budget seems to be what was
MB> in `~ Daily from`, but the transactions from before that date also count
MB> towards the actual expenses. That probably means that I should /always/
MB> provide -b to the `budget` report. Is that right?

I would, yes.

MB> 4. If I don't provide -e, the default (for the `budget` report) is
MB> --current. Is that correct?

That sounds right.

MB> 5. If I don't provide `from` in `~ Daily`, the default seems to be the
MB> date if the /first/ transaction on a given account. Right?

Correct.

MB> 6. (Almost) last but not least -- the `budget` report gives me a table
MB> with 5 columns: - actual expenses - budgeted expenses - the difference
MB> (negative means I spent less than the budget -- a bit counterintuitive,
MB> but makes sense given the order of the previous two) - what percentage of
MB> the budget was spent - name of the account

MB> Using classical spreadsheet column names: C = A - B and D = A/B (as
MB> percentage). Do I guess correctly?

I think so?

MB> If so, this means that the web app I wrote to present this exact
MB> information is mostly irrelevant. %-P Still, it draws a nice chart which
MB> is accessible from a smartphone. I have a post-commit hook which scp's the
MB> file to my VPS, and the web app there serves the chart - that's a very
MB> useful arrangement I plan to blog about one day.

I'm glad it's useful, but definitely, custom code can always go further.

MB> Now, my final question is this. Much of what we discuss here is apparently
MB> undocumented in the Ledger manual. My book is my book, and it contains
MB> examples and such, but I think it is fair to have these options at least
MB> mentioned in the manual. I have just fetched the ledger repo, and I can
MB> see that the last commit in `ledger/doc/ledger3.texi` was 7 years ago...
MB> Would you accept a PR with a small manual update? (One minor issue with
MB> that idea is that I don't speak texinfo, so you'd have to check every my
MB> edit very carefully.)

Absolutely! I'd be honored to accept your PR.

John
Reply all
Reply to author
Forward
0 new messages