Some help on Inventory/Commodity/Revenue booking questions please!

389 views
Skip to first unread message

vess...@gmail.com

unread,
Mar 8, 2016, 4:50:39 PM3/8/16
to Beancount
I'm checking out Beancount for use in some financial forecasting for a mining business.

The mining business works like this: 

1) Large capital expenditure
2) Ongoing operating expenses
3) Commodity is put into inventory
4) Optionally the commodity is hedged
5) Commodity is sold at some point.

While there are different ways of booking a business like this, management generally wants to think of this in one of two ways:

1) Cost Basis. The commodity is booked at cost (opex + depreciated capital expense).
2) Market Basis: The commodity is booked at market value on day it's put into inventory.

In either event, P&L and Balance Sheet reports will need to show mark-to-market adjustments for different periods so that the team can understand what the current value of the business is.

During the planning process, the team would like to be able to assess FIFO, LIFO and AVCO inventory tracking methods for the commodity. But, that's not a requirement -- I understand that beancount has some of these features but don't understand how to use them.

Can someone on this list opine as to how this should be booked in beancount? The sample I have put together doesn't seem to play nicely with beancount-web or fava on reporting, and I think I'm just too uneducated as to how beancount works to get a good file format together.


ad...@vyomtech.com

unread,
Mar 8, 2016, 8:46:30 PM3/8/16
to Beancount, vess...@gmail.com
You can do it using bean-query to generate LIFO, FIFO and AVCO analysis reports, check the documents at:

How Inventories Work
Beancount Query Language
Generating beancount reports

Indeed using option you can write a plugin to fetch the market prices of commodities. So indeed your whole workflow can be automated and generated reports can be used by end-user.

vess...@gmail.com

unread,
Mar 9, 2016, 3:31:21 PM3/9/16
to Beancount, vess...@gmail.com, ad...@vyomtech.com
Thanks for the pointers. I had read two of those documents, and re-read them. I am getting some errors from beancount that I don't understand. I made a simple file that miens some gold, pays people for the labor and then eventually sells some gold. The beancount file is at this gist: https://gist.github.com/vessenes/c1540554b707450ffb55

I first got an error: Reducing position results in inventory with positive and negative lots: -5.0 AU. 

Some research turned up the inventory module and some instructions on lines to add. These are added to the gist above. Adding in the plugin incantations to my file yields the following errors.

onerun.beancount:3: 
Invalid token: '“beancount.plugins.book_conversions”'
onerun.beancount:3: 
Invalid token: '“Assets:Inventory:AU,Income:AU”'
onerun.beancount:6: 
Invalid booking method: FIFO
  2016-01-08 open Assets:Inventory:AU                             AU "FIFO"

It seems clear to me that I don't know how to install the book_conversions module, get my Assets marked as FIFO, and reduce inventory.

Can anyone advise?

vess...@gmail.com

unread,
Mar 9, 2016, 6:24:29 PM3/9/16
to Beancount, vess...@gmail.com, ad...@vyomtech.com
I have this working, and the working file recorded at the gist.

Here are the things I needed to do:

1) I reinstalled from a fresh mercurial pull and direct install. Previously I had used pip3. Not sure if this had an impact.

2) At least one version of my file had text open and close quotes (“ vs " ). This came from pasting text in the google docs document

3) I had specified currencies for each open account, I think this caused some problems.

4) I used the example bitcoin transactions in the book_conversions documentation as a template, (but beware the quotes!)

5) I had used cost basis notation in the purchase { 250 USD } and switched to the @ notation. This fixed the "positive and negative lots" error. I am not clear conceptually why this would be so. It seems to me that booking something at cost basis should not preclude it from being matched, so I would suggest this is a bug in the book_conversions plugin, but Martin could opine on this.

Peter

Martin Blais

unread,
Mar 9, 2016, 11:39:28 PM3/9/16
to Beancount, vess...@gmail.com
On Tue, Mar 8, 2016 at 8:46 PM, <ad...@vyomtech.com> wrote:
You can do it using bean-query to generate LIFO, FIFO and AVCO analysis reports, check the documents at:

How Inventories Work
Beancount Query Language
Generating beancount reports

Two points:
1. LIFO, FIFO, AVCO, etc. booking methods aren't supported yet.
This work is being done in the "booking" branch.
It's approx. 80% complete (gut feeling); I'll be finishing work on integrating ledgerhub's code before resuming on that.
(I'm really keen to finish it, before that's the point where I feel Beancount 2.0 is "done" and move my weekend energy to other projects.)

2. Regardless, the booking method is used to deduce which lot is in effect.
It's done at processing time, not at reporting time.
In order to change the booking method, one would have to reprocess the stream of entries.
Haven't thought about that eventuality too much yet.



Indeed using option you can write a plugin to fetch the market prices of commodities. So indeed your whole workflow can be automated and generated reports can be used by end-user.

I wouldn't recommend fetch data from the network in a plugin, unless you have pretty good and reliable caching; you risk waiting a lot. Best would be to make the fetching of prices a separate step, potentially writing it to an include file.



On Wednesday, March 9, 2016 at 5:50:39 AM UTC+8, vess...@gmail.com wrote:
I'm checking out Beancount for use in some financial forecasting for a mining business.

The mining business works like this: 

1) Large capital expenditure
2) Ongoing operating expenses
3) Commodity is put into inventory
4) Optionally the commodity is hedged
5) Commodity is sold at some point.

While there are different ways of booking a business like this, management generally wants to think of this in one of two ways:

1) Cost Basis. The commodity is booked at cost (opex + depreciated capital expense).
2) Market Basis: The commodity is booked at market value on day it's put into inventory.

In either event, P&L and Balance Sheet reports will need to show mark-to-market adjustments for different periods so that the team can understand what the current value of the business is.

During the planning process, the team would like to be able to assess FIFO, LIFO and AVCO inventory tracking methods for the commodity. But, that's not a requirement -- I understand that beancount has some of these features but don't understand how to use them.

Can someone on this list opine as to how this should be booked in beancount? The sample I have put together doesn't seem to play nicely with beancount-web or fava on reporting, and I think I'm just too uneducated as to how beancount works to get a good file format together.


--
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 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/c5fb86a0-70e4-4de8-b9ea-875fc6767bac%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Martin Blais

unread,
Mar 9, 2016, 11:54:37 PM3/9/16
to Beancount, vess...@gmail.com, ad...@vyomtech.com
On Wed, Mar 9, 2016 at 6:24 PM, <vess...@gmail.com> wrote:
I have this working, and the working file recorded at the gist.

Here are the things I needed to do:

1) I reinstalled from a fresh mercurial pull and direct install. Previously I had used pip3. Not sure if this had an impact.

Yes. pip3 will install the most recent dist I pushed to PyPI.
Best is to run from source on the default branch, to be honest.
I make sure the full battery of unit tests runs clean before I merge anything on that branch; it's stable.


2) At least one version of my file had text open and close quotes (“ vs " ). This came from pasting text in the google docs document

Ahhh yes. I have a few of those in the docs. Thought I had already replaced all of them. Sorry.

 

3) I had specified currencies for each open account, I think this caused some problems.

It should not have any effect, beyond potentially generating errors if you attempt to post other currencies to those accounts.


4) I used the example bitcoin transactions in the book_conversions documentation as a template, (but beware the quotes!)

Note that this fun plugin was developed to answer a question on the Ledger mailing-list.
It works, but ultimately, the way FIFO and other methods will be supported will be built-in.
Essentially, providing an underspecified cost basis spec will trigger a default booking method per account, and that method could be set to FIFO, LIFO or other.

I rewrote your example using cost basis and removing the book-conversions plugin; see attachment.
The gist of it is that you need to recognize a profit here (whether you report this as a profit to the govt is a separate matter).
I chose some combination of lots as an example.
As I mentioned, when the "booking" branch is complete, you should be able to do this:


2016-01-08 open Assets:Inventory:AU  "FIFO"

...

2016-05-01 * "Sell some Gold"
  Assets:Inventory:AU -5 AU {}
  Assets:Cash    3000 USD
  Income:Profit


The proposed design for this behavior is documented here:

More generally, read this doc for how to use cost basis in Beancount:




5) I had used cost basis notation in the purchase { 250 USD } and switched to the @ notation. This fixed the "positive and negative lots" error. I am not clear conceptually why this would be so. It seems to me that booking something at cost basis should not preclude it from being matched, so I would suggest this is a bug in the book_conversions plugin, but Martin could opine on this.

The error you got existed because there is a constraint that a single account should not contain positive _and_ negative lots at the same time, if you haven't disabled booking (by setting the booking method to "NONE"). The reason for this is that 99% of the time it indicates a user error and it's more useful to spit an error instead of allowing it.

If you ever need short positions in to represent a hedge, you can use a separate account.




--
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 post to this group, send email to bean...@googlegroups.com.
vessenes-booking-modified.beancount

Peter Vessenes

unread,
Mar 14, 2016, 3:57:02 PM3/14/16
to Martin Blais, Beancount
Thanks Martin.

What you attached makes sense to me. It would be nice to not have to track lots directly, lots of room for user error there; I know you're attuned to that risk.

I'll look for the plugin when its released.

Peter
--
Peter J Vessenes  @vessenes http://vessenes.com
Reply all
Reply to author
Forward
0 new messages