SERVING THE QUANTITATIVE FINANCE COMMUNITY

• 1
• 2

mtsm
Topic Author
Posts: 350
Joined: July 28th, 2010, 1:40 pm

### Quantlib design and usage

I have had to turn my attention towards quantlib lately, in view of using it as a base for a system in a buy-side context, that is able to handle both valuation, risk, pnl as well as research in time series and scenario context. One important question I am trying to answer for myself, is how I should end up using it, meaning at what level and how much of it should I use and how much should I stay away from?

When I compare the library to what I have seen in top IBs or large buy side firms, I can't help but feel that it's quite poorly designed. It has a pretty academic feel to it and I have the feeling that many who have had a hand in its design aren't really market professionals. I can see that the authors took C++ design principles to heart, but this isn't really the problem you are trying to solve when writing a financial engineering library. I am happy to elaborate on what I think are pretty flaky aspects of quantlib.

But what I am trying to figure out is how people who use library in a professional production context use it? Are they using only failry low-level components of it and go from there or do they actually buy into the design pattern nonsense that comes with it? I am also thinking about overlays like quant_ext and ORE btw.

Thanks,
m

Cuchulainn
Posts: 59377
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Quantlib design and usage

My views.

Classic OOP and the legendary GOF Gamma Design Patterns are the lynchpins of QL. 25 years ago GOF was hot (I used them with success in CAD and process-control because OOP was a good paradigm). Things have moved on because the GOF is for 90% redundant and C++ has become a multiparadigm language. For finance, algorithmic design is more important and GOF is more like fluff. I have used GOF (appropriately, I would hope)  since 1992 (I even used them iin Algorithmics' RiskWatch 1,0) and at one stage it became an objective in itself by many developers. GOF can force you into thinking about a non-optimal solution before you even understand the problem.

I don't know what your (final) goal is, but if QL does not satisfy you (it's free..) then there are various options such as wrapping it in something else etc. Or write your own code,  time permitting.. C# is  as fast as C++ and much higher productivity rates.

The active senior QL guys I know do work in finance.

One scenario: wrap QL in your own code. One option is to expose just what you need from QL and hide the rest (this is not a new idea by any stretch of the imagination).

https://www.datasim.nl/blogs/22/softwar ... -and-excel

I would redesign it all over again. But you need time  + \$ so it probably won't happen given the fact that most contributors have famlies and day jobs.. What is very nasty: undocumented GOF-style code; it's like wading through a swamp.

One more thing; it is impossible (and undesirable) to try to parallelise classic OOP code. Why?
Most developer don't/won't/can't do top-down decomposition, so you end up with OO objects in great balls of mud. GOF introduces many layers into the design.

I agree pretty much with your concerns.
hth, my 2 cents

Cuchulainn
Posts: 59377
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Quantlib design and usage

I can see that the authors took C++ design principles to heart, but this isn't really the problem you are trying to solve when writing a financial engineering library. I am happy to elaborate on what I think are pretty flaky aspects of quantlib.

A good idea is to approach QL on these issues; Maybe become a contributor.

edit
Plan B is to purchase a commercial package, with the well-known usual caveats..

berndL
Posts: 171
Joined: August 22nd, 2007, 3:46 pm

### Re: Quantlib design and usage

I have had to turn my attention towards quantlib lately, in view of using it as a base for a system in a buy-side context, that is able to handle both valuation, risk, pnl as well as research in time series and scenario context. One important question I am trying to answer for myself, is how I should end up using it, meaning at what level and how much of it should I use and how much should I stay away from?

When I compare the library to what I have seen in top IBs or large buy side firms, I can't help but feel that it's quite poorly designed. It has a pretty academic feel to it and I have the feeling that many who have had a hand in its design aren't really market professionals. I can see that the authors took C++ design principles to heart, but this isn't really the problem you are trying to solve when writing a financial engineering library. I am happy to elaborate on what I think are pretty flaky aspects of quantlib.

But what I am trying to figure out is how people who use library in a professional production context use it? Are they using only failry low-level components of it and go from there or do they actually buy into the design pattern nonsense that comes with it? I am also thinking about overlays like quant_ext and ORE btw.

Thanks,
m
if you are looking to use QL from higher level languages (R or python for example) this is also available. Then you dont have to deal with the C++ part too much. You then build your application with those "high level" tools. But, the real difference to commercial packages is probably you have to take a bit a look yourself. Not many consultants around to help you here. But of course some specialised people are available. You can find them easily if you look for that.

Cuchulainn
Posts: 59377
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Quantlib design and usage

berndl,
is there a site for 'Available QL "consultants"?

berndL
Posts: 171
Joined: August 22nd, 2007, 3:46 pm

### Re: Quantlib design and usage

berndl,
is there a site for 'Available QL "consultants"?
Hi Daniel,

https://www.quantlib.org/mailinglists.shtml shows a mailing list for "QuantLib-jobs". Goes in both directions (supply, demand).
You know of course the ORE guys?!
And some well known consultency firms offer also support. But only if asked explicitly i think.

And no: A generall website is not there to my knowledge.

rmax
Posts: 6079
Joined: December 8th, 2005, 9:31 am

### Re: Quantlib design and usage

We tried here to rewrite it, and it was very difficult. Good times and good conversations though!

Cuchulainn
Posts: 59377
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Quantlib design and usage

We tried here to rewrite it, and it was very difficult. Good times and good conversations though!
I suppose there are many roads to Rome. Would be curious to know to how you did it. QL is based on public work so it could have been rewritten from scratch by mining the algorithms and test data? But you need a budget ::-) Technically,.it's not rocket science but it does not appeal to everyone..

One approach in the past was to write a generic interface that subsumes both COM and CORBA so as to learn 1 interface, as sold to management. The new system started leaking from all sides, so 3 interfaces had to be learned.

If only the core algorithms (the rest is fluff I/O) could have been extradited from Ball Of Mud. In fairness, we can attribute it to the OOP hype.

Personally, 90% of GOF patterns is outdated and/or redundant.

Cuchulainn
Posts: 59377
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Quantlib design and usage

Example; SDEs were implemented using Observer pattern a bit AFAIR (why, no idea)  Here is a solution using narrow interfaces in C++11.

https://onlinelibrary.wiley.com/doi/epd ... wilm.10606

rmax
Posts: 6079
Joined: December 8th, 2005, 9:31 am

### Re: Quantlib design and usage

We tried here to rewrite it, and it was very difficult. Good times and good conversations though!
I suppose there are many roads to Rome. Would be curious to know to how you did it. QL is based on public work so it could have been rewritten from scratch by mining the algorithms and test data? But you need a budget ::-) Technically,.it's not rocket science but it does not appeal to everyone..

One approach in the past was to write a generic interface that subsumes both COM and CORBA so as to learn 1 interface, as sold to management. The new system started leaking from all sides, so 3 interfaces had to be learned.

If only the core algorithms (the rest is fluff I/O) could have been extradited from Ball Of Mud. In fairness, we can attribute it to the OOP hype.

Personally, 90% of GOF patterns is outdated and/or redundant.
By we I meant the royal we on Wilmott! And they were good times trying to get that together.

Cuchulainn
Posts: 59377
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Quantlib design and usage

Halcyon days, indeed.

And all the time I'm thinking, wouldn't it be great if it was like this all the time.

finanzmaster
Posts: 112
Joined: March 11th, 2007, 1:04 pm

### Re: Quantlib design and usage

In my current project I use QuantLib as a benchmark to OpenGamma
(due to NDA no futher details, sorry).

If both of them calculate the similar results (it was the case in my project) then... although there is still no formal guarantee that the results are correct but the likelihood of their correctness increases .

As to the over-engineering of QuantLib, I myself expressed  critics to Luigi as we met on QuantLib User Meetings in Duesseldorf.
Actually, he, himself, admits the problem:  take the Black-Scholes formula, which is the most basic in a Quantitative Finance library, if you look for it in QuantLib you'll find no single, simple function which gives you the Black-Scholes price for an option
But what can you do? Re-design the library from scratch? Well, I think it would be indeed a good solution (and one could have taken into account the parallel calculations paradigm) ... but who will sponsor this big project?!

P.S.
How to build QL in VS2019 (and why it is, so far, suboptimal)
https://letyourmoneygrow.com/2019/02/10 ... 9-preview/

P.P.S.
If you want to engage QL power but do not want to dwell into its undocumented guts, hire me as a contractor
My offer is also valid for OpenGamma.

Cuchulainn
Posts: 59377
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Quantlib design and usage

take the Black-Scholes formula, which is the most basic in a Quantitative Finance library, if you look for it in QuantLib you'll find no single, simple function which gives you the Black-Scholes price for an option

A single function is not object-oriented.

Using VS2019 now ==> you become a MSDN beta tester. Better to wait.

What's the rationale for comparing OpenGamma and QL?

finanzmaster
Posts: 112
Joined: March 11th, 2007, 1:04 pm

### Re: Quantlib design and usage

>A single function is not object-oriented.
Well, there are other things. As I wrote in my notes "But  it  seems  that PiecewiseYiledCurvedoes notinherit  from YieldTermStructure!Indeed  it  does,  but  in  a  pretty  complicated  manner. As  we  can  see  from  Figure  3.1a, PiecewiseYildCurveintensively  (ab)uses  templates.  Luigi  explains  this  complex  construction  in  his  book  in detail. Unless  you  are  really  curious,  you  do  not  need  to  spend  your  time  on  them. Just  to  put  it  briefly: PiecewiseYildCurveinherits  fromTraits::template  curve<Interpolator>::type,  which  is  a  template  class."
Luigi does not tell explicitely, why he does such things, but as I supposed at the last QL User meeting: he wants to keep mediocres out of QL
https://www.quantlib.org/slides/qlum17/nekrasov.pdf

>Using VS2019 now ==> you become a MSDN beta tester. Better to wait.
For production, definitely. But as a small contribution to Microsoft, why not?
In recent time they got pretty generous, I mean not only the VS community edition but also their sponsoring of R studio and Microsoft R (which does not suffer from the mess with library versions).

>What's the rationale for comparing OpenGamma and QL?
Just trying to adopt the best practice from my experience as a former artillery
lieutenant (in reserve).
Soviet and then Russian artellerists got used to calculate the targets' coordinates in two ways: once with счислитель (a big backpack-carried computer) and once with ПУО (a kind of mechanical tablett). If both approaches give similar coordinates, they fire. Not a formal mathematical proof, but works well during a war.

Cuchulainn
Posts: 59377
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Quantlib design and usage

OK, And keep ur powder dry.

PiecewiseYildCurveinherits  fromTraits::template  curve<Interpolator>::type,  which  is  a  template  class."

This is standard template design (C# the same). 90% (a guess) of C++ developers probably dream in OOP and have not made the transition to generics. Then an even smaller group use functional programming techniques.