On building an integrated QuantLib/Lua platform on the world's most popular computer.

Sunday, December 5, 2010

A sample Lua/QuantLib program

This example is a rip of the Python Lua example for European options:

It returns the values 0.030342732609191 and 0.030027071770314 respectively

-- Mostly ripped from Python European Example

-- makes life a little simpler







riskFreeRate = QL.FlatForward(sD, 0.05, QL.Actual365Fixed())

exercise = QL.EuropeanExercise(Date(17,5,1999))

payoff = QL.PlainVanillaPayoff(QL.Option_Call, 8.0)

underlying = QL.SimpleQuote(7.0)

volatility = QL.BlackConstantVol(tD, QL.TARGET(), 0.10, QL.Actual365Fixed())

dividendYield = QL.FlatForward(sD, 0.05, QL.Actual365Fixed())

process = QL.BlackScholesMertonProcess(QL.QuoteHandle(underlying),QL.YieldTermStructureHandle(dividendYield),QL.YieldTermStructureHandle(riskFreeRate),QL.BlackVolTermStructureHandle(volatility))

option = QL.VanillaOption(payoff, exercise)


-- Analytic

print ("Analytic Price",option:NPV())

-- Finite Difference

-- method: finite differences

timeSteps = 801

gridPoints = 800


print("finite diff.",option:NPV())

Friday, October 8, 2010

iPhone QuantLib stuff

Is being consolidated at this website

I have done a lot of stuff and just haven't had time to put it all together in one place.

Wednesday, September 1, 2010

Sunday, August 22, 2010

Daycounter progress

I've had a review of my daycounter app. Much has improved and it's much closer to launch. New images at http://daycountiphone.blogspot.com

Thursday, July 15, 2010

Day counter

The most extensive financial daycounter available on the iPhone. See images at

This is to appear soon on iTunes

Sunday, April 4, 2010

QuantLib-Python + R-Python

Is it possible to have these three objects work seamlessly? Can I move the SWIG objects pointed to in Python to R?

Saturday, April 3, 2010

Fixed QuantLib R error

Needed to chage the Date function in QuantLib.R.

The simple function: todaysDate <- Date(15, "May", 1998)
refused to run because Date (line 2088) was buggy.

Date needed to be changed. It called functions
extends(argtypes[1], 'integer')

That integer should be changed to numeric in all three cases.

Saturday, March 20, 2010

Installing MayaVi2

Spent hours installing mayavi from enthought. Everything installed but it refuses to run. With command

from enthought.tvtk.tools import mlab
fig = mlab.figure()

it gives error

ImportError: No module named carbon_render_window

No idea how to fix it yet. It seems to come from tvtk.

Friday, March 19, 2010

Fibonacci observation

The highly inefficient fibonacci algorithm is still quite interesting.

When computing fib(n), for k less than n fib(k) is called fib(n-k) times, except when k is 0. This is called n-2 times. The total number of calls for fib(n) is

[sum (for k less than n) fib(k)]+fib(n-2)

Quick python script to check:


def fib(n):
if d.has_key(n):
if n==0: return 1
if n==1: return 1
return fib(n-1)+fib(n-2)

Saturday, March 13, 2010

NumPy, matplotlib

Installed numpy and matplotlib. Unfortunately I upgraded my python to 2.6, so I have to recompile QuantLib-SWIG. I'd forgotten it took this long as the main file is 200k lines.

And it fails with the architecture problem, much like my matplotlib failed.

Tuesday, March 9, 2010

Monday, March 8, 2010

Notes on using QuantLib-Python

I have a few notes on using QuantLib in python and (roughly) showing how it all works. I am hoping this will be useful to someone else other than me.

Wednesday, March 3, 2010

QuantLib wikipedia page

The QuantLib wikipedia page is coming up slowly. Just need more time to list all it can do.

Saturday, February 27, 2010

QuantLib R

Things seemed to go well but somehow Date is not working. I do not understand R enough to know what's wrong.

Date(15,'May',1998) produces the error

Error in Date(15, "May", 1998) : could not find function "f"

I'm running QuantLib 1.0, R version 2.10.1.

I've looked at the QuantLib.R file and the problem seems to be at lines about 2087--2108 with the following code.

`Date` <- function(...) {
argtypes <- mapply(class, list(...))
argv <- list(...)
argc <- length(argtypes)
# dispatch functions 4
if (argc == 0) {
f <- Date__SWIG_0
} else if (argc == 1) {
if (extends(argtypes[1], 'integer')) {
f <- Date__SWIG_2
} else if (argc == 2) {
if (extends(argtypes[1], 'character') && extends(argtypes[2], 'character')) {
f <- Date__SWIG_3
} else if (argc == 3) {
if (extends(argtypes[1], 'integer') && extends(argtypes[2], 'character') && extends(argtype\
s[3], 'integer')) {
f <- Date__SWIG_1

Somehow f failes to be defined here.

QuantLib python

Installed QuantLib-Python. Was relatively easy. I just followed the instructions for each package. Everything was installed in /usr/local, and /Library/Python/2.5/site-packages/QuantLib

1. Installed boost

2. Installed Quantlib

3. Installed QuantLib-SWIG (the python part)

Things seem to be going swimmingly.

Tuesday, February 23, 2010

I've started the wikipedia page for QuantLib. I hope it survives.

Building QuantLib on the Mac

My latest project is building QuantLib on the Mac using XCode.

It's now working, details are forthcoming very soon.

Another interesting addition to the project would be to recompile QuantLib for Mathematica to work on the Mac. Original Windows source is at http://www.nielses.dk/quantlib/mma/