gists for #plaintextaccounting

Earlier this month, I wrote a blog post  on creating a small and simple plain text accounting system. I was asked if I could make my shell scripts available. I have done so as gists. You can download all the files, and use them.

Note that they were really only intended for my personal use, so you may find them not-so-easy to use yourself. I have approached it from a UNIX toolset viewpoint, rather than as a monolithic package.

All inputs should have their fields delimited by tabs. I recommend my basic approach even if you want to feed your inputs into something like John Wiegley’s ledger program. You can write your own script to generate a suitable format; I had done so in the past, but abandoned the idea when I realised that the program was not quite what I was looking for. You retain maximum flexibiltiy

The two principal inputs are etran (equity transaction) and ntran (“normal” transaction), whose fields are as follows:

etran-2 dstamp folio ticker qty amount way desc
ntran dstamp dr cr amount desc

The meaning of the fields are as follows:

  • dstamp is a date stamp of the form YYYY-MM-DD
  •  folio is a symbolic folio name that you want to associate an equity transaction with
  • ticker is the ticker for an equity (e.g. VOD.L (UK) or VOD (US) for Vodafone)
  • qty is the number of shares bought or sold
  • amount is the transaction value in your currency (e.g. 1234.56)
  • way indicates whether the equity is a B (buy) or S (sell)
  • desc is a description of the transaction
  • dr is the symbolic account name to debit (e.g. “cash”)
  • cr is the symbolic account name to credit

There’s also a few minor record types ones like “pending”; which is basically an uncleared ntran. See, that’s the advantage of using a tab-delimited approach: you can easily invent new structures on an ad-hoc basis, and then generate canonical transactions from that.

A commentary on each of the files in the gist is as follows:

  • derive concatenates all of your input files together, and translates pending transactions into normal ones. Adjust line 5 accordingly
  • etb creates a set of accounts. You can create subtotals, income and expense reports, balance sheets, whatever you want. You will need to set up gaap.txt, which is described in my original post
  • macc is the main driver program. Invoke it to kick off the whole set of computations
  • postify converts ntrans and etrans into simple “posts”
  • sums up the number of shares you have, both by portfolio and in aggregate
  • sort-inputs sorts the inputs by date and entry order
  • stocko.awk is a support program used for creating CSV files in a form usable by Stockopedia
  • is a driver to stocko.awk
  • subtotals posts by accounts. You will need to compile it. I had problems with numerics in awk, but I think that I might have been able to replace the C++ code with an awk program
  • teet a debugging script
  • vacc this runs separately from macc. It shows you all the transactions for an account that you specify on the command line.

I hope that the above proves useful. If there is serious interest in this post, I might be tempted to elaborate further. Remember, it is really something for you to mould yourself, rather than provide an out-of-the-box solution.



About mcturra2000

Computer programmer living in Scotland.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s