Testing my new portfolio report

Martijn van Oosterhout Martijn van Oosterhout <kleptog@svana.org>
Sun, 24 Feb 2002 01:04:35 +1100


[Please CC any replies as I'm subscribed no-mail]

Hi,

I've been using gnucash quite successfully for the last few months for my
accounts and it works really well. Except, the portfolio report. It told me
what I had but not how it compared with what I'd put in and stuff like that.
So, I started browsing the source and did a crash course in Scheme (ie, I
read a few websites) and came up with my own portfolio report. It gives much
detail.

Note: there is no guarentee anyone else will find it useful, but it tells me
what I want to know.

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
show.

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 which to shield
their eyes :)

http://svana.org/kleptog/gnucash/portfolio2.scm

Thanks in advance,
-- 
Martijn van Oosterhout <kleptog@svana.org>
http://svana.org/kleptog/
> If the company that invents a cure for AIDS is expected to make their
> money back in 17 years, why can't we ask the same of the company that
> markets big-titted lip-syncing chicks and goddamn cartoon mice?