Latest Posts

Installing IronSpread - Python Driven Excel 2012-07-16


Have installed Windows 7, its updates, and Microsoft Office.

Python(x,y) and lxml

Download and install Python(x,y) (currently version Use the default recommendations in the installer. Additional Python plugins are available here. In particular, download and install lxml.


A nice free text editor for editing Python code is Notepad++. Download and install it.


Download and install Mercurial. Download the 32-bit installer that does not need admin rights to install.

Clone mint and clove

Setup a directory structure to store our Python projects. Open the Command Prompt by going to the Start Menu --> All Programs --> Accessories. The directory structure is


Make a folder called autonomy and clone the golden repositories of clove and mint

C:\Users\winuser\hgdev\org.bitbucket\autonomy>hg clone
C:\Users\winuser\hgdev\org.bitbucket\autonomy>hg clone

Modify PythonPath

We need to modify our PYTHONPATH to inform python of the location of our Python projects. Open up the Control Panel by going to Start Menu --> Control Panel. Click on System and Security --> System. On the left side, click on Advanced system settings. Click on the Environment Variables button. In the lower half of the window, under System variables, click New and enter a new System variable.

Variable name: PythonPath
Variable value: C:\Users\winuser\hgdev\org.bitbucket\autonomy\mint;C:\Users\winuser\hgdev\org.bitbucket\autonomy\clove

Click OK to save the new settings. To test that the changes have taken effect, open up a new instance of the Command Prompt, and execute the following.

>>> import clove

Installing QuantLib Python 2012-07-11


First install QuantLib with the Python bindings:

sudo apt-get install quantlib-python

To access QuantLib in a virtual environment:

export LD_LIBRARY_PATH=/usr/lib/python2.7/dist-packages/QuantLib:$LD_LIBRARY_PATH
export PYTHONPATH=/usr/lib/python2.7/dist-packages/QuantLib:$PYTHONPATH

Using the Object-Oriented Finance Object Model 2012-06-28

The following demonstrates some examples of how the concepts in the OOF object model interact with one another and can be used to solve real problems in finance.

Calculating the present and anterior value of a future payment

A Payment is the future transfer of ownership of a certain amount of some Asset. This Payment is defined by four things: the Asset involved, the amount of the Asset involved, the Payor (an Agent), and the Date we will transfer the Payment. Imagine the Asset is just our Currency, that we are considering the payment of 100 units of it, that our payor is the Sovereign (assume no credit risk), and that the payment will take place on 1/1/2017 (5 years from now).

As with any Asset, a Payment has some present value and some anterior value. An Asset's present value is the amount of Currency we would need to exchange on today's Date to receive 1 unit of the Asset on a future Date. We need to know (1) the future payment Date and (2) the Market with which we are dealing. The need for a future Date is obvious. The Market is useful because anyone who uses it can access any of the Market's DiscountFactorCurve. A DiscountFactorCurve is a function that takes as input an Interval and provides a DiscountFactor. A DiscountFactor is the present value of 1 unit of Currency received on a future Date with respect to a Reference Date.

To calculate the present value of a Payment, I can go to my Market and ask it for its DiscountFactorCurve. I can then ask the DiscountFactorCurve for its DiscountFactor for 1/1/2015, a possible transfer Date, with respect to today. I finally ask the DiscountFactor for its level and it tells me 0.98. I then multiply this value by my 100 units of Currency and conclude that the Payment's present value is 98 units.

Note that nowhere in my calculation did I use the date on which we transferred ownership of the Payment. It won't matter if we transfer ownership in 2014 or 2015, or at the actual moment of the payment. It will, however, matter if the transfer Date occurs after the payment Date since this doesn't make sense. The present value of the Payment for any date strictly greater than the Payment Date is zero.

The Payment's anterior value behaves differently. The anterior value for today's Date is the same as today's present value. The anterior value on the payment Date is equal to the size of the Payment, the face value. In between, the anterior value is equal to the amount of the payment times the inverse of the DiscountFactor level from today to the transfer date. After the payment Date, the anterior value is zero.

xmldb Tutorial 2012-06-22

We'll use the example document books.xml from

In [1]: import clove.xmldb.XmlDbKit as XmlDbKit

In [2]: db = XmlDbKit.make('dev')

In [3]: db.env.list_documents()
Out[3]: []

In [4]: with open('/home/ubuntu/Dropbox/books.xml') as f:
   ...:     content =

We'll use db.env.put_document to add the XML content to the database for now, instead of using db.create, which is used for sifting out quoteEvent events, and which will not add anything if there are no quoteEvent tags.

In [5]: db.env.put_document('document_uuid', content)

In [6]: import clove.xmldb.XPathQuery as XPathQuery

In [7]: query = XPathQuery.make('/bookstore/book')

In [8]: db.query(query)
['<book category="COOKING">\n  <title lang="en">Everyday Italian</title>\n  <author>Giada De Laurentiis</author>\n  <year>2005</year>\n  <price>30.00</price>\n</book>',
 '<book category="CHILDREN">\n  <title lang="en">Harry Potter</title>\n  <author>J K. Rowling</author>\n  <year>2005</year>\n  <price>29.99</price>\n</book>',
 '<book category="WEB">\n  <title lang="en">XQuery Kick Start</title>\n  <author>James McGovern</author>\n  <author>Per Bothner</author>\n  <author>Kurt Cagle</author>\n  <author>James Linn</author>\n  <author>Vaidyanathan Nagarajan</author>\n  <year>2003</year>\n  <price>49.99</price>\n</book>',
 '<book category="WEB">\n  <title lang="en">Learning XML</title>\n  <author>Erik T. Ray</author>\n  <year>2003</year>\n  <price>39.95</price>\n</book>']

Object-Oriented Finance Data Model 2012-06-20

Below is a list of the different entities in the Object-Oriented Finance (OOF) data model. This is an attempt to organize all of the relevant concepts in the financial universe into a coherent and consistent system. Once this clarity is achieved (and only then), our goal is to translate this model into software.

The primary tool we will use is the Class-Responsibility-Collaborator (CRC) method. Each entity in our model has a "card" outline the (1) name of the entity, (2) the entity's definition and its responsibilities, and (3) the other entities that it must reference to fulfill these responsibilities.

We will start with a very fundamental concept: time.

Class: TimeLine

Provides a single index of all time in Julian dates and UTC milliseconds.


Is the only instance of itself (a singleton). Locations on the TimeLine are Instants and are denoted by a unique timestamp in the following format


which represents 23:59:59.999 on December 31, 1999 using the Julian Date - UTC convention.

Class: Instant

A single location on the TimeLine.


Can tell me its unique location, expressed in the Julian Date - UTC format.



Class: Interval

A closed interval (containing its endpoints) on the TimeLine.

Site Map 2012-06-18

Install Xubuntu

Install Xubuntu

Install Source Control

Install Xubuntu --> Source Control

Install Mint

Install Source Control --> Install Mint

Install Python Numerical Packages

Install Xubuntu --> Python Numerical Packages

Install Ruhoh

Install Source Control --> Install Ruhoh

Install BDB XML

Install Source Control --> BDB XML

Installing Ruhoh 2012-06-12

Ruhoh is a blogging platform based on Markdown.


Have installed Xubuntu 12.04 in a Virtual Machine.

Have version control software installed.


Install Ruby, using the instructions here. You will also need to add libyaml

sudo apt-get install libyaml-dev

The following assumes that you already have a GitHub account and an SSH key associated with it. If you do not have an SSH key, follow the instructions here.

Make sure that any SSH keys you make will be saved by moving them to the Dropbox config folder and replacing their folder with a link

mkdir ~/Dropbox/config/ssh
mv ~/.ssh/ ~/Dropbox/config/ssh
ln -s ~/Dropbox/config/ssh/.ssh ~

Setting up a Ruhoh repository

Now follow the instructions for setting up your ruhoh repository at You will be cloning the ruhoh repository and then installing ruhoh. The instructions will guide you through the process of testing and drafting posts. To actually push a post to the web, you will have to use git

git add .
git commit

You will then be prompted for a message. Provide this, save, and close the file. Finally, push the change

git push

You will use for updating any posts or pages, or to change your configurations. For example, this blog uses a customized version of the sunburst theme, which comes with ruhoh. Edit the config.yml file and change the theme under google_prettify. Commit and push this change.

Installing Numerical Packages in Python with Pip 2012-06-12


Have installed Xubuntu 12.04 in a Virtual Machine.


One of the advantages of Python is the availability of a large number of numerical packages. Installing these, particularly pandas, can be frustrating because of certain dependencies.

To install these packages you will first need to execute the following

sudo apt-get install libamd2.2.0 libblas3gf libc6 libgcc1 libgfortran3 liblapack3gf libumfpack5.4.0 libstdc++6 build-essential gfortran python-all-dev libatlas-base-dev libfreetype6-dev libpng12-dev

This installs

  • libamd2.2.0 - an approximate minimum degree ordering library for sparse matrices
  • libblas3gf - the Basic Linear Algebra reference implementations, shared library
  • libc6 - the Embedded GNU C Library, shared libraries
  • libgcc1 - the Embedded GNU C Library, shared libraries
  • libgfortran3 - a runtime library for GNU Fortran applications
  • liblapack3gf - the Library of Linear Algebra Routines 3, shared version
  • libumfpack5.4.0 - a sparse LU factorization library
  • libstdc++6 - the GNU Standard C++ Library v3
  • gfortran - the GNU Fortran 95 compiler
  • python-all-dev - a package depending on all supported Python development packages
  • libatlas-base-dev - the Automatically Tuned Linear Algebra Software, generic static
  • libfreetype6-dev - FreeType 2 font engine, development files
  • libpng12-dev - PNG library - development

Installing BDB XML 2012-06-12


Have installed Xubuntu 12.04 in a Virtual Machine.


Read this for a little introduction to BDB XML.

Download and install


sudo apt-get install bbdbxml

You will need to modify your PYTHONPATH and to point to /opt/bbdbxml/current/lib. Create a script with the following content to launch iPython.

#!/usr/bin/env bash

export PYTHONPATH=/opt/bbdbxml/current/lib:$PYTHONPATH


Installing Version Control Software 2012-06-11

Installing Version Control Software


Have installed Xubuntu 12.04 in a Virtual Machine.

We use source control as explained here.

Mercurial and Git

We're going to use two version control software packages, Mercurial and Git. Differences between the two can be found here.


Install mercurial:

sudo apt-get install mercurial


Install git

sudo apt-get install git-core

File Structure

Create a file structure to store your repositories:

mkdir -p ~/hgdev/org.bitbucket/asmith
mkdir -p ~/gitdev/com.github/asmith

Git SSH key

Git requires you to use an SSH key. If you do not have an SSH key, follow the instructions here.

Make sure that any SSH keys you make will be saved by moving them to the Dropbox config folder and replacing their folder with a link