Illustrated ledger -> beancount example

67 views
Skip to first unread message

Martin Michlmayr

unread,
Mar 30, 2018, 8:27:53 AM3/30/18
to bean...@googlegroups.com
As mention in the ledger2beancount announcement, I created an
illustrated ledger example that shows how ledger syntax is converted
to beancount syntax and explains some of the differences.

Since I'm new to beancount myself, I wanted to ask if someone could
review that everything makes sense and that I'm using the correct
beancount terminology:
https://github.com/zacchiro/ledger2beancount/blob/master/examples/illustrated.ledger

Thanks!

--
Martin Michlmayr
http://www.cyrius.com/

Martin Blais

unread,
Mar 30, 2018, 11:57:10 PM3/30/18
to Beancount
Comments:

- Found a bug in the example file:

  bergamot [hg|]:~/src/ledger2beancount$     ./bin/ledger2beancount examples/illustrated.ledger             
  Can't parse date 03/28 at ./bin/ledger2beancount line 161.                                                

(This is out of the box, probably an easy fix.)
Idea: You may want to add a unit test on the running of the conversion on each of the examples provided.


- About the payee_match feature: Just wanted to point out the fix_payees plugin:
I'm not sure if it can do what Ledger does; but if you think it can be modified to match your needs, let me know.


- About "tag foo"; you can use
pushtag #foo
...
poptag #foo
to achieve something similar (I think it's similar?)


- I think you'll find complexities when you start to translate reductions (e.g. selling shares), though the current automated lot selection might help a lot.

Nice work!
Thanks,






--
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+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/20180330122221.cb6teky77h5krotz%40jirafa.cyrius.com.
For more options, visit https://groups.google.com/d/optout.

Martin Michlmayr

unread,
Mar 31, 2018, 9:38:25 AM3/31/18
to bean...@googlegroups.com
* Martin Blais <bl...@furius.ca> [2018-03-30 23:56]:
> - Found a bug in the example file:
>
> bergamot [hg|]:~/src/ledger2beancount$ ./bin/ledger2beancount
> examples/illustrated.ledger
> Can't parse date 03/28 at ./bin/ledger2beancount line 161.

You have to use --config examples/illustrated.yml because of the
non-standard date foramt used. I used that because of of a bug in
ledger but I'll see if I can remove it.

> (This is out of the box, probably an easy fix.)
> Idea: You may want to add a unit test on the running of the conversion on
> each of the examples provided.

I thought about doing that but illustrated.ledger won't pass
bean-check after conversion because of the lot reduction (i.e. showing
an example of something that's allowed n ledger but not in beancount).
But I think that's ok since it's explained in the file.

> - About the payee_match feature: Just wanted to point out the fix_payees
> plugin:
> https://bitbucket.org/blais/beancount/src/4c0eeea4c6c4f406c5400d3fb245087042293844/beancount/plugins/fix_payees.py?at=default&fileviewer=file-view-default
> I'm not sure if it can do what Ledger does; but if you think it can be
> modified to match your needs, let me know.

Ah, this is very cool. I wasn't aware of that. I'll add it to the
documentation.

> - About "tag foo"; you can use
> pushtag #foo
> ...
> poptag #foo
> to achieve something similar (I think it's similar?)

I completely forgot about pushtag. Thanks, I'll use that instead.

Thanks for the feedback.

Martin Blais

unread,
Mar 31, 2018, 1:03:20 PM3/31/18
to Beancount
On Sat, Mar 31, 2018 at 9:38 AM, Martin Michlmayr <t...@cyrius.com> wrote:
* Martin Blais <bl...@furius.ca> [2018-03-30 23:56]:
> - Found a bug in the example file:
>
>   bergamot [hg|]:~/src/ledger2beancount$     ./bin/ledger2beancount
> examples/illustrated.ledger
>   Can't parse date 03/28 at ./bin/ledger2beancount line 161.

You have to use --config examples/illustrated.yml because of the
non-standard date foramt used.  I used that because of of a bug in
ledger but I'll see if I can remove it.

Ah! Cool, thx.
Perhaps adding that command as an example (with the --config option) helps too.


> (This is out of the box, probably an easy fix.)
> Idea: You may want to add a unit test on the running of the conversion on
> each of the examples provided.

I thought about doing that but illustrated.ledger won't pass
bean-check after conversion because of the lot reduction (i.e. showing
an example of something that's allowed n ledger but not in beancount).
But I think that's ok since it's explained in the file.

I think you can adapt your converter to handle all these conversions completely automatically.
The context is that you have postings with essentially just one type of conversion (@ and {} and used interchangeably in Ledger AFAIK).
For every usage of @, classify whether it's a currency conversion or an investment.
You can do this by looking at the pairs of commodities.

For example, first preprocess the entire ledger and to fetch the whole list of commodities and separate them into two groups:
- commodities which occur by themselves
- commodities which have a @ conversion
Now define the subset of investment commodities as: the set of commodities which (a) never occur by themselves, and (b) which are never seen as the price or cost of another.
For instance, you would never see units of MSFT moved around without a price (a), and you would never see MSFT used to price another commodity.
Another view: You have three possible cases:

1. just using a currency
  <account>     <units> <ccy>

2. currency conversion
  <account>     <units> <ccy1> @ <ccy2>

3. investment
  <account>     <units> <comm> @ <ccy>

The way you classify the third one is that <comm> never shows up on the right of @ (e.g., 100 USD @ 2 MSFT) and is never used by itself (2 MSFT).
(1) translates trivially.
(2) becomes a Beancount currency conversion (@)
(3) becomes a Beancount posting held at cost ({})

(And since you're doing a text-to-text translation, you can take advantage of the automated lot booking when Beancount will parse your file.)



> - About the payee_match feature: Just wanted to point out the fix_payees
> plugin:
> https://bitbucket.org/blais/beancount/src/4c0eeea4c6c4f406c5400d3fb245087042293844/beancount/plugins/fix_payees.py?at=default&fileviewer=file-view-default
> I'm not sure if it can do what Ledger does; but if you think it can be
> modified to match your needs, let me know.

Ah, this is very cool.  I wasn't aware of that.  I'll add it to the
documentation.

To be fair it's a bit of a prototype.
It could be greatly expanded.

 

> - About "tag foo"; you can use
> pushtag #foo
> ...
> poptag #foo
> to achieve something similar (I think it's similar?)

I completely forgot about pushtag.  Thanks, I'll use that instead.

Thanks for the feedback.
--
Martin Michlmayr
http://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 beancount+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages