Will QuantLib C++, Matlab, Strategy Agent deliver the most powerful and lowest latency quant HFT algo black box architecture on the planet?

(Last Updated On: November 10, 2010)

Will QuantLib C++, Matlab, Strategy Agent deliver the most powerful and lowest latency quant HFT algo black box architecture on the planet?

Below is now appearing to be the ultimate marriage in high frequency trading with powerful algo quant library in C++ at your disposal. So let’s go through this, we have QuantLib written in C++ which is probably the most powerful/fastest possible quant library available on the planet. It is also open source meaning it is FREE!!  Then tie it with the prototyping power of Matlab which we have talked about enough here. If you need a better and powerful front end, might I suggest QuantLibXL or something similar. Now, in the backend, we have talked about SQL Server going against IQFEED for incoming market data and Interactive Brokers for outbound. I am unsure of this but that is what I am thinking. Let me throw in that Marketcetera’s Strategy Agent might be the best in delivering strategies to any broker. That is in Java I believe.

Poweful huh?  I impressed myself. When do I start building?

Here is a blurb on how to tie Quantlib and Matlab potentially together from the Quantlib newsletter group I am part of:

I am trying to use the quantlib library from Matlab. As a test case, I
adapted the EquityOption.cpp example code from the quantlib webpage to a cpp
file which would generate the price of an American Put option with parameters
given by the user, using a few different pricing engines. Before writing the
mex, I had created a standalone version which accepted input from std::cin, and
this ran fine.
However, when I run the code from matlab, the results always come back as 0. I
do not know a lot about the guts of quantlib, and the lazy evaluation methods
being used. However, it seems that when I run the standalone, it takes about 1
second or so (there are some binomial lattice engines being used), whereas when
I run the mex file from matlab, it returns zeros instantaneously. I suspect
somehow that the << operator in the standalone (copied from EquityOption.cpp)
forces the option to be evaluated under the given engine, but this is not being
done in my matlab mex.
Am I wrong about this? Do I have to force evaluation somehow? As a snippet of
code, I have things like this in the mex:

new BinomialVanillaEngine<JarrowRudd>(bsmProcess,timeSteps)));
P[iii] = (double)americanOptionPut.NPV();   //puts the results in the output

whereas in the standalone it looks more like:
new BinomialVanillaEngine<JarrowRudd>(bsmProcess,timeSteps)));
std::cout << “the result is ” << americanOptionPut.NPV() << std::endl;

any hints? thanks,

A real easy way of talking to Quantlib from Matlab is to call the java
wrappers for Quantlib. Matlab is written in Java and so it is easy to
load classes from there and call them.

It sounds like the library thinks the instrument is expired and skips
the calculation.
Are you settings the evaluation date correctly? (Look for where
Settings::instance().evaluationDate() is set in the standalone.)



I do not think that is the problem. I tried an even simpler version of the
code, quoted here:

#ifdef IS_MATLAB
#include <mex.h>

// the only header you need to use QuantLib
#include <ql/quantlib.hpp>
#include <iostream>
#include <iomanip>

using namespace QuantLib;

namespace QuantLib {
Integer sessionId() { return 0; }

#ifdef IS_MATLAB
void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) {
int main(int argc, char* argv[]) {
// set up dates
Calendar calendar = TARGET();
Date todaysDate(15, May, 1998);
Date settlementDate(17, May, 1998);
Settings::instance().evaluationDate() = todaysDate;

// our options
Option::Type type(Option::Put);
Real underlying = 36;
Real strike = 40;
Spread dividendYield = 0.00;
Rate riskFreeRate = 0.06;
Volatility volatility = 0.20;
Date maturity(17, May, 1999);
DayCounter dayCounter = Actual365Fixed();

std::cout << “Option type = ”  << type << std::endl;
std::cout << “Maturity = ”        << maturity << std::endl;
std::cout << “Underlying price = ”        << underlying << std::endl;
std::cout << “Strike = ”                  << strike << std::endl;
std::cout << “Risk-free interest rate = ” << io::rate(riskFreeRate)
<< std::endl;
std::cout << “Dividend yield = ” << io::rate(dividendYield)
<< std::endl;
std::cout << “Volatility = ” << io::volatility(volatility)
<< std::endl;
std::string method;
boost::shared_ptr<Exercise> europeanExercise(
new EuropeanExercise(maturity));
Handle<Quote> underlyingH(
boost::shared_ptr<Quote>(new SimpleQuote(underlying)));

// bootstrap the yield/dividend/vol curves
Handle<YieldTermStructure> flatTermStructure(
new FlatForward(settlementDate, riskFreeRate, dayCounter)));
Handle<YieldTermStructure> flatDividendTS(
new FlatForward(settlementDate, dividendYield, dayCounter)));
Handle<BlackVolTermStructure> flatVolTS(
new BlackConstantVol(settlementDate, calendar, volatility,
boost::shared_ptr<StrikedTypePayoff> payoff(
new PlainVanillaPayoff(type, strike));
boost::shared_ptr<BlackScholesMertonProcess> bsmProcess(
new BlackScholesMertonProcess(underlyingH, flatDividendTS,
flatTermStructure, flatVolTS));

// options
VanillaOption europeanOption(payoff, europeanExercise);

// Analytic formulas:

// Black-Scholes for European
method = “Black-Scholes”;
new AnalyticEuropeanEngine(bsmProcess)));
std::cout << method << “: ” << europeanOption.NPV()
<< std::endl;

#ifdef IS_MATLAB
return 1;

when I compile this as a standalone using the -UIS_MATLAB compiler flag, and
run it, I get the results:

Option type = Put
Maturity = May 17th, 1999
Underlying price = 36
Strike = 40
Risk-free interest rate = 6.000000 %
Dividend yield = 0.000000 %
Volatility = 20.000000 %
Black-Scholes: 3.84431

when I compile with -DIS_MATLAB into a Matlab mex file, and run it from within
Matlab, I get the following:

Option type = Put
Maturity = May 17th, 1999
Underlying price = 36.000000
Strike = 40.000000
Risk-free interest rate = 6.000000 %
Dividend yield = 0.000000 %
Volatility = 20.000000 %
Black-Scholes: 0.000000

everything is the same except the results from NPV(), and the representation of
the price and strike (e.g. 36 vs. 36.000000).



i would like to know what is the latest version of QuantLib available in Java
Could you please forward me a link to download it.

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Subscribe For Latest Updates

Sign up to best of business news, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.


Check NEW site on stock forex and ETF analysis and automation

Scroll to Top