ASP.NET portfolio reporting control

Lord know there are plenty of portfolio management tools on the web, but to my surprise none of them gave me all the features I wanted.  In particular, I wanted the ability to:

  • Retrieve prices for a wide range of assets; ideally any asset (in any currency) whose price is available online.
  • Measure the value of each holding against a reference price (which might be in a different currency from the asset's natural currency).
  • Keep track of cash (in any currency).
  • Produce a valuation report in any currency for all holdings using up-to-date exchange rates.

These are the features that matter most to me.  I must be in a minority because no-one seems to support them, so it was time for a bit of roll-your-own.

Retrieving prices and exchange rates

First of all we need a (preferably free!) way to get prices and exchange rates that bear some resemblance to reality.  And we want to support any asset - NYSE stocks, LSE stocks, unit trusts, gold, oil, whatever.  I have done this through the time-honoured technique of scraping (that is, extracting data from presentation text).  I defined an interface, IPriceRetriever, that exposes a GetPrice method.  Then I implemented a bunch of scrapers that retrieve web pages and pluck the prices from them.  So far I have created scrapers for these fine sites:

Like all scrapers, these scrapers are brittle.  If the maintainers of one of these sites decide to give it a facelift then the scraper code might very well need to be updated.

Using the data

How to make use of all this great data?  There are so many ways, but here I have gone for a bunch of ASP.NET server controls.  As you will see, one of my goals is to give you the option of creating a portfolio with no C# code whatever.

The ASP.NET controls

I have created three controls for your delectation:

  • FXDataSource - a data source control that delivers forex rates
  • AssetPricesDataSource - a data source control that delivers asset prices
  • Portfolio - a data source that consumes an FXConverter and an AssetPricesDataSource and delivers valuation data for a portfolio of assets and cash

You can choose to use whichever of these you like.  Here we will go through them from top to bottom, finishing with a complete portfolio valuation.

Using the controls

To use the controls you can either download and build the source code, or just download the binaries.

To prepare your site to use the controls, follow these two simple steps:

  1. Put the FinancialScrapers.dll and PortfolioControls.dll assemblies in your application's Bin directory
  2. Put this directive at the top of your ASP.NET page:

    <%@ Register Assembly="PortfolioControls" Namespace="CarlJ.Financial" TagPrefix="cgjfin" %>

Next page: The data retrieval classes.

©2009 Carl Johansen