Instead of a simple switch statement …

This is Luke‘s kind of code. I might be catching the virus …

abstract class QIFParserBase {

    public enum LoadOptions {

    static readonly Dictionary<LoadOptions, Action<QIFParserBase, string[]>> parseFuncs =
                                        new Dictionary<LoadOptions, Action<QIFParserBase, string[]>> {

        {LoadOptions.All, (q,c) => q.ParseAll(c)},
        {LoadOptions.Prices, (q,c) => q.ParsePricesBlocks(c)},
        {LoadOptions.Securities, (q,c) => q.ParseSecurityBlocks(c)},
        {LoadOptions.Transactions, (q,c) => q.ParseTransactionBlocks(c)}

    public QIFParserBase(string fileName, LoadOptions opt) {

        string content = File.ReadAllText(fileName);

        string[] blocks = content.Split(new string[] { "!Type:", "!Option:" },



Parsing QIF Quicken files in C#

I’m slightly prouder of the structure of this code than the one in the previous blog post. You can simply inherit from QIFParserBase and override a couple of abstract methods to customize the behavior. Still, I just tested it on a couple of test QIF files. It is not production quality at all.

Notice that I don’t even have Quicken. I’m producing these test file with FundManager, which I use for my investments. If your software generates QIF files differently, than you have to modify the code. It shouldn’t be too hard.

It works with VS 2008 beta 2.

Retrieve prices, dividends and splits for a stock in C#

I wrote this code very quickly and I’m kind of ashamed of it, but it gets the job done (I think). You need the HTML Agility Pack for the stock splits retrieving code. You can download it from here or you can simply comment out the code. I wrote it against Visual Studio 2008 beta 2, but it should be trivial to port it to previous versions.

You run it from a command window like this: “priceretriever msft 1/1/1990 2/3/2003”. The last two parameters are optional and default to 1/1/1980 and today.