Up: Martijn's Homepage  
Prev: The towers of Hanoi   Next: Scanning with the HP5470C  

I didn't like the default investment report that came with GnuCash, so I made one up that produced the numbers I wanted to know. Fetch it here.

It is actually very similar to the table my online broker shows me when I view my shares. It shows the amount of money spent on shares and charges, how much gained from sales and dividends, gets the current value and so gives an estimated rate of return over the whole exercise.

Very good for getting an overall view of your portfolio. To make it work you will need to save this file in the reports directory (on Debian that's /usr/share/gnucash/guile-modules/gnucash/report/). Then you need to add the following line to /usr/share/gnucash/scm/report/report-list.scm. This will make it actually see the report. GnuCash needs to be restarted to affect the change.

(use-modules (gnucash report advanced-portfolio))

This is the text that accompanied the original announcement:

For each stock you select it displays:

Money In: How much have you paid in total for these stocks, ever.
Brokerage: Total fees paid
Dividends: Total dividend received  
Units: How many stock you currently have
Value: How much these are worth right now
Money Out: How much you have received in total in sales of these stock, ever
Gain: Total gain/loss, including unrealised. Value + Money Out - Money In
Total margin: % gain. Gain / MoneyIn 
Avg Age: Average number of days holding this stock. May be used to estimate
          annual return

Note: it can only pick up stuff that appears in transactions attached to the
account. So for dividends you have to put a zero value split to get it to

It does work right now but since I couldn't work out how to add a new report
to the system, you actually have to copy it over the old portfolio.scm to
get it to load. Some help here would be nice.

Known bugs:
- If you give it an empty account, it dies
- It doesn't deal will multiple currencies at all
- It ignores the date you give it
- It probably gets a divide by zero error sometimes

The reason I'm emailing now is:
- Is anyone else interested in this? Should I fix these problems or am I the
  only one who cares?
- I'm unhappy about the number of variables I had to add. I wanted to use an
  ADT but once I saw mention of 6 different types of hash tables I skipped it.
  There's something to be said for Perl's just-give-me-a-hash approach.
- If anyone sees a way to replace the large chunks of code with a few
  filter/map expressions, I'd be very interested.

Anyway, the code is here. Experienced scheme coders may wish to shield
their eyes :)

Let me know if you like it, hate it, etc...

Up: Martijn's Homepage  
Prev: The towers of Hanoi   Next: Scanning with the HP5470C  
By Martijn van Oosterhout (kleptog (at)
Copyright © 2000-2006 - Last modified 11/04/2002