As mentioned previously, I am now tracking mutual funds in hledger. Since starting this tracking, I have been entering mutual fund transactions using hledger iadd. And this was working well when I had just a transaction here or there to enter.
However, with the end of the first quarter, there was a significantly greater quantity of transactions to enter, and all at the same time. To be honest, it wasn’t that much that I could not have taken care of them using iadd. Still, my thoughts turned to how I could automate the process.
My first idea was to use hledger’s csv converter. However, I discovered that my mutual fund’s csv format didn’t easily lend itself to hledger’s csv converter. There is probably a way to make it work, but after a few unsuccessful tries, I decided to write something in ELisp instead. It would likely take me longer to write the ELisp code, but one of my goals is to become more proficient in ELisp, and this would be some good practice.
The first step, was to import the csv data into a format that ELisp could work with. After a few tries, I was successful. One of the surprising things, is that as I examined the imported csv data from the mutual fund company, it mostly matched the way I had set up the transactions previously. For example, if dividends in a fund are reinvested, I use two transactions for this. First, the dividends are received as cash. Then I do a second transaction to use the cash to purchase additional shares.
I did have to make some changes. For example, my names for the mutual funds didn’t exactly match the imported names. For example, I might have used the name “BigIndex,” but the imported name is “Big Index 2000.” Therefore, I redid my previous transactions so that they matched the names in the csv import.
What to do with the csv data in terms of importing it into hledger? Rather than import the csv data directly, I decided to write ELisp code to generate the transactions ready for pasting in my hledger data file. That is, the output of the command would look something like this:
2026-01-30 dividend received | Acme Mutual Fund:Big Index 2000
income:Acme Mutual Fund:BigIndex -$1.00
assets:Acme Mutual Fund:cash $1.00
2026-01-30 dividend reinvested | Acme Mutual Fund:Big Index 2000
assets:Acme Mutual Fund:cash -$1.00
assets:Acme Mutual Fund:BigIndex 0.1000 BGINX
If the output looks good, I can then copy it into my hledger data file. Finished!