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

Sunday, January 23, 2011

Reading Yahoo/Fed data directly

I can now use Lua to read in Federal-H15 data and Yahoo stock data. directly into QuantLib/Lua. I just wish I could read bond data from somewhere :-(

Thursday, January 6, 2011

Pricing a bond using QuantLib/Lua

Here is an example of pricing a bond using QuantLib/Lua on the iPhone

--Simple bond pricing
--http://tgwena.blogspot.com
ql=QuantLib
Date=ql.Date


local sDD=Date(17,5,1998)
local eDD=Date(17,5,2001)

local r=0.04 --interest rate
local c=0.06 --coupon

ql.Settings_instance():setEvaluationDate(sDD)


sched=ql.Schedule(sDD,eDD,ql.Period(2),ql.NullCalendar(),ql.Unadjusted,ql.Unadjusted,0,false)
ufixQ=ql.SimpleQuote(r)
ufixH=ql.QuoteHandle(ufixQ)
curve=ql.FlatForward(0,ql.NullCalendar(),ufixH,ql.SimpleDayCounter())
flatTS=ql.YieldTermStructureHandle(curve)
bondEngine=ql.DiscountingBondEngine(flatTS)


bond=ql.FixedRateBond(0,100,sched,ql.DoubleVector(1,c),ql.SimpleDayCounter(),ql.Unadjusted, 100, sDD)

bond:setPricingEngine(bondEngine)

print(bond:dirtyPrice())

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

QL=QuantLib

Date=QL.Date



tD=Date(15,QuantLib.May,1998)


sD=Date(17,QuantLib.May,1998)


QL.Settings_instance():setEvaluationDate(tD)

print(QL.Settings_instance():getEvaluationDate())


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)


option:setPricingEngine(QL.AnalyticEuropeanEngine(process))


-- Analytic

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


-- Finite Difference

-- method: finite differences

timeSteps = 801

gridPoints = 800


option:setPricingEngine(QL.FDEuropeanEngine(process,timeSteps,gridPoints))

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

Followers