CppCast - QuantLib
Episode Date: July 12, 2024Luigi Ballabio joins Phil and Matt Godbolt. Luigi talks to us about QuantLib, an open-source library for financial models that he co-founded and now maintains. News WG21 St. Luis trip reports...: "Official" report, collated by Inbal Levy Herb Sutter's trip report Links QuantLib home page Episode about borrow-checked C++ with Sean Baxter "QuantLib Python Cookbook" - book by Luigi "Implementing QuantLib" - book by Luigi
Transcript
Discussion (0)
Episode 386 of CPP Cast, with guest Luigi Bellabio. Recorded 9th of July, 2024.
In this episode we talk about the recent WG21 meeting in St. Louis.
Then we're joined by Luigi Balabio.
Luigi talks to us about his work on Quantlib. Welcome to episode 386 of CppCast, the first podcast for C++ developers by C++ developers.
I'm your host, Phil Nash, joined by my guest co-host, Matt Godbolt.
Matt, how are you doing today?
I'm doing just great thank you
very much phil how about you yeah i'm okay um i think i've just finished all of my almost all of
my traveling for uh for the first part of the year you've been extremely busy haven't you you've been
on the road for a number of weeks yeah well we're just saying in the pre-show that i seem to be
saying every episode that i've just finished some travelling
I've got some more coming up, but
yeah, I did C++ on C
last week, then was travelling at the weekend
as well, just got back late last night
but I've no more travelling for the next few weeks
so I won't be saying that next episode
at least. So you claim.
We'll see how that pans out, you seem to be
a very busy man.
Yeah, well, how you, though, Matt?
Yeah.
I mean, things have been pretty chill here.
I've not really been doing very much,
just concentrating on my day job and my hobby job.
And yeah, otherwise, but I'm looking forward.
I'm actually coming to the UK.
So unfortunately, I missed C++ on C this year
with my sort of annual go see the parents
try not to be disinherited yeah trip uh you know um but um but yeah that's just going to be a
holiday and i'm looking forward to it so right well c++ on c missed you as well oh and uh talking
to missing people obviously we don't have tima here today as we said in the last episode he's
taking a couple of months off, so he won't be here
until at least September.
But we will keep the show going.
Guest co-hosts such as Matt stepping in very kindly, sometimes at the last minute.
I don't know what you mean.
Anyway, at the top of every episode, we usually like to read a piece of feedback.
We didn't have that much, and because of being a little bit short of time i didn't get to dig in too much to to find
anyways any so if you have any feedback about this show or any of the others please let us know
you can always reach out to us to to share your thoughts on x mastered on linked LinkedIn or email us at feedback at cpbcast.com. Now joining us today is Luigi
Balabio. Luigi is a co-founder and the current maintainer of the open source Quantlib project,
a C++ library for quantitative finance exported to several programming languages. He lives in
Milan with his wife and four children. And during the day he works at Confluence Technologies Incorporated.
That's the financial analytics company and not the wiki.
Luigi holds a PhD in applied nuclear physics from the University of Uppsala in Sweden.
In his hometown near Milan, though, he's best known for playing the baritone saxophone in the local concert band, and he wouldn't have it any other way.
Luigi, welcome to the show.
Hello. Thanks for having me here.
So, Luigi, I see that you have a nuclear physics background.
How on earth did you go from nuclear physics to finance?
Well, it was by being in the right place at the right time,
like a lot of things in my life, I'm happy to say.
Well, I did the switch in the late 1990s.
Right.
And quantitative finance was already in full swing in other countries. But in Italy, it was just starting to be used
and teams were starting to be formed in investment banks and so on.
And there was no formal education for that yet.
And, well, basically basically people in banks realized that they could uh take mathematicians
or phys or physicists and and uh right a little bit of the work and and no instead of tracking
the particle positions you're like well these are just these financial instruments they're all the
same really it's just that one one makes more money than the other really i mean i'm a bit exaggerating but job interviews were like oh what did you study okay
physics you're hired yeah yeah yeah and they're both used atomic pointers oh well nowadays it's
a lot different i mean i always say i i'm not sure i would get a job in in quant finance nowadays i mean there are
academic programs and and a lot of competition and and as i say that was in the right place
at the right time so i don't know how these things happen yeah well we're definitely going to dig
into that more in just a few minutes but first we do have a well usually say a couple of news
articles talk about really just one that of news articles to talk about really just
one that we're going to talk about this week but it's quite a big one but do feel free to comment
on any of this so the that big news item is that wg21 the standards committee meeting happened in
st louis um it was just starting as we were recording the last episode so a teamer and
in peterson were actually in st louis as we recorded at the last episode. So Tima and Ian Peterson were actually in St. Louis
as we recorded at the start of that week.
So nothing had happened at that point.
It all happened since then.
In fact, as we released the last episode,
that was the final day before the plenary.
So this really is sort of up to the minute.
So there is a big,
there's a number of trip reports you can find on Reddit.
There's usually sort of one, like an official one,
recently been written by Inbal Levy.
So we'll put a link to that one in the show notes.
I'll also put a link to one from Herb Sutter.
That's quite a good one as well.
The one from Inbal is very big, very in-depth.
So if you don't get through it all, don't worry too much.
I think it's mostly front-loaded anyway.
The big news there is that Stood execution is in.
So that was actually the subject of the previous episode.
So great timing there on our part.
It was all completely planned that way, I assure you.
So yeah, go back to the previous episode for more background on that.
But yeah, plus the plan to revote.
There were some concerns that were raised
and i'm sure we will see that come back up uh with with various sort of fixes and and so on but i'm
hoping it's going to stay in at least because it's uh being proposed for the to being included
in the working draft but we know from previous experience that's not necessarily final and the other big one is reflection which has been
approved by ewg so the evolution working group forwarded on to the cwg for for wording so that
means it's being design approved and it's really just the wording now sometimes it can get thrown
back but that's obviously a big milestone for another big feature so i think inbar said that
we expect the work to continue
over the next few meetings.
So quite a lot of work there.
But they are still expecting that to make it into 26 as well.
It's amazing how much work goes into this.
You know, like the way that you just described it
makes it sound like it's more like a political thing.
You know, like it's the House of Lords or the, you know,
the House of Representatives and the Senate going back and forth wording and legal stuff it's quite something it really is yeah
yeah i mean we've we've talked a little bit about how that's all structured before but you do have
these different working groups and that the main ones are the evolution groups where they just talk
about the design and then the the core groups where they talk about the wording sometimes it
backwards and forwards between between those two but there's various other groups as well so the specialized study
groups as incubators and so on so it's um it is quite a big process i mean it's literally designed
by committee taken to the extreme but it does work for some definition of working just a little bit
slow for some people talking of things that are slow contracts continues to
to make progress that is one of the ones that were famously was in and then was out and then
was taken out yeah yeah and now here we are in the c++ 26 time frame it is still on track for c++ 26
at least optimistically um i think the the conservative estimate is going to be 29.
But right now there were a lot of objections to consensus
when it was talked about in EWG last time.
And now they've got for about half of those.
So they are making steady progress.
But it's not over yet.
I'm still hopeful.
And then SG23, the safety and security study group obviously it's been a big
topic at least out here in the real world for the last um year or two now um there's a dedicated
study group for on the committee they actually saw the presentation from sean baxter so we had
sean on a few shows ago episode episode 383, talking about his implementation
of a borrow checker in Circle.
And he's presented that to the committee.
And there was a strong consensus
in SG23 to actually spend
more committee time
investigating the whole thing.
So, so far,
that's being taken quite seriously.
Be interesting to see
what comes of that.
It is a massive directional change.
So I'm still hesitant to get too hopeful.
But it's fascinating because this is, you know, Sean is the, well, I mean,
Sean is amazing as a single human being being able to do what he's able to do.
But he's also an indication of like how one could potentially move the committee forward.
You mentioned how slow
it is but like sometimes if you have somebody go off on an offshoot to one side and show that
something's possible that can actually steer the whole thing yeah which is fascinating absolutely
yeah what one thing is often complained about is that things get into the standard without
implementation experience and while it could be argued circle is not strictly c++ it's got a lot
of extra things in there already.
And he doesn't always go in the same direction
that the standard would.
But it is an implementation.
It shows it can be done built on top of,
I think still C++ 17 at the core.
But I could be wrong about that.
But it is C++ at the core.
So I'm watching that with interest,
as I'm sure many people are.
There was obviously lots of other things
that got in or made progress.
I'm not going to go through them all,
read those trip reports.
Just some honorable mentions to in-place vector that got in.
I think Tim was one of the people that worked on that.
And is that the vector that holds elements
in the object itself,
where people always
people always call it stack memory drive used to drive me bonkers but i'm glad to say they've gone
for like in place that makes sense to me yeah yeah and it's been around for quite a while as a
proposal i think it was noted as the the lowest numbered proposal that got in which means it's
been sat the longest yeah yeah um which for quite a small simple
non-controversial paper it's um interesting shall we say uh structured binding declaration
as a condition seemed to be talked about a lot i didn't actually look into exactly what that is so
i can't say more about it but um that seemed to be interesting uh stood ignore as a first class object so we've had that
since c++ 11 i believe but uh there there's certain things that were left to implementation
details and this is the um the object that you can you can assign anything to so if you've got a
a function that returns something but you're not interested in the return value you can
assign it assign it to std ignore
and it would do nothing.
It should get optimized out.
Sounds like a teenager.
No comment.
But because of certain implementation-defined aspects to it,
it couldn't always be used portably in all cases.
And it turned out that all the implementations
did the same thing anyway
so that's just been standardized and i know you can now you could ignore more of c++ than you
could before so that so that's good and um and finally uh stood print you can now stood print
more types faster with less memory that's got to be a good thing so lots of other little things
like that all going in so overall i think it's a very
productive week in st louis yeah it sounds like it there's a lot of as i say there's so many people
involved and so much hard work goes into it and you know i'm i'm just a beneficiary of this stuff
so i'm very grateful to anybody who's involved in that process now talking of matt being a
beneficiary of stuff he did mention just before the show that execution,
not std execution, but executing your code on MSVC, I believe,
is now back and working in Compiler Explorer.
So if that's something that you've been waiting for, that's good news.
For a long time, we had it disabled, and then finally we've got it back.
We're now confident enough that our sandboxing is okay.
Obviously now announcing it to the world,
we'll find out the hard way if that's true or not.
But we've gained execution,
but we've lost library support for MSVC,
but we're working on that.
We'll get it back.
Well, well done on that and good luck.
Thank you.
That's all the news items that we have for this week.
So it was quite a lot just in that first one.
So we are going to talk to Luigi now about Quantlib.
So Luigi, welcome to the show again.
Thank you.
In order to explain what Quantlib actually is, we first have to explain what a quant library is and perhaps before even that
because not everybody here listening is familiar with the world of finance what is a quant
maybe we should start there yeah well when we say quant library that's quant is short for a
quantitative financing which i always struggle to say it's got too many t's in it hasn't it yeah well imagine
what we imagine english is not even my first language so imagine and well that basically
means uh well can mean different things for instance when when people think of programming in finance, it's often what you might mention in the pre-show that was high-frequency trading and that kind of algorithms.
Quantitative finance is, in our sense, though, is more a set of mathematical methods and models to figure out in some way the price of financial instruments,
so financial products, especially derivatives.
That would be financial products that depend on some other underlying.
It's, well, figuring out the value is not entirely true.
I mean, the value of a financial instrument is whatever people is willing to pay for that.
But the idea is that you usually do the inverse process, so to speak. So by observing the prices of financial instruments, you try to figure out the behavior of the
underlying drivers for them.
So for instance, you may see prices for bonds or stock options.
And from those, you can infer the underlying what the market thinks about future interest rates or how
volatile is the underlying stock and this kind of drivers.
And well, once you have that in place, then you start answering questions like, OK, today
this bond is worth this much because that's the market value.
But what happens if tomorrow interest rates raise or go down?
Or what happens if short-rate interest rates go up
and long-term rates go down?
These kind of questions so that you can,
well, basically hedge your risks.
Right.
So you're not overly exposed to movements of the market.
And yeah, there's a lot of models for that.
And a quant library like Quantlib translates those in code so that they can be used in uh well in your
processes at uh at work right yeah or well ideally also in in research i'm not seeing a lot of that
but well okay but essentially it's like a toolkit of bits and pieces that you can put together
or is it like a whole product?
Is it there's a program I run or?
No, it's a library.
It's a library.
So it's bits and pieces that you put together, as you said.
And there are applications using Quantlib.
So there is another project which is also open source,
which is based on Quantlib,
and packages some of the most currently used applications
of all these models into an application which is ready to go,
ready to take input data and do the processing
and give you the outputs.
Quantlib per se is a library.
So yeah, a bunch of functions and classes that you can use.
And you mentioned obviously it's open source,
which I think is really unusual in the world
of finance finance is typically pretty secretive and holds its cards close to its chest yeah so
it's very surprising that there is something out there like that so you mentioned research but
is is the is the license available for like could it be used by commercial companies is
is that yeah it's basically a bsd license so yeah that's very for for whatever
yeah very brave yeah you're right that that's not usual the the the reason is uh well historical i
would say it's it started in in 2000 and yeah so it's so it's been old enough
to vote and drink for a while now.
And well, basically,
I was one of the first few employees
of a newly founded company.
We're just a bunch of us.
We were just founded.
We were not on the map in any meaningful way.
And so one of us, not me, had the idea of, well, since we need to, we just started, we
need to rewrite basically all the code we need for pricing and modeling.
And why don't you, well, at the time he was reading of open source, he was very into the idea.
And he proposed to the boss, why don't we use this as we write this code?
Why don't we put it out there as open source as a way of getting some publicity and showing
that we know what we're talking about?
And well, we were lucky enough that the boss saw that.
I mean, he liked the idea.
He gave us the green light and we started putting it out there.
And this is how it started, really.
And we started having some contributors.
In the beginning, we did, I mean, most of the work was inside the company.
Of course, after a while we started keeping some of the code proprietary and some more specific things.
So, yeah, we still have Quantlib, the open source project and some additional pieces
that we have in-house, which is common, I think. But yeah, this is how the open source thing
started. And well, it grew from there and well, we're still here after 24 years.
That's quite an achievement to have a project running that long.
I mean, obviously it's written in C++,
but obviously in 2000,
pretty much the only choice of C++ you had
was whatever the compiler supported.
So it was 98 era.
So what kind of C++ versions are you targeting
or can you support these days?
And how has the code evolved?
Nowadays, well, I'm putting out a release next month
and it will be the last release to require C++ 14.
I mean, we're not using C++ 17 features in the library yet.
And this next month's release in June, no, sorry, this month, we are in July already.
We are in July, yeah, I know.
Where the hell the time is going, I don't know, but here we are.
This release will be the last to not allow C++ 17.
Starting from next release,
we'll start that.
That's mostly because, well,
banks and our financial institutions
are usually kind of conservatives.
I mean, I wouldn't be surprised that,
I mean, most of those don't have the latest version available
for the compiler they're using, not by alongside.
So, yeah, we stay kind of conservative
and we are two free versions of the standard behind.
And we try to stay that way.
Right.
But it sounds like obviously you've had to take the code
from 2000 era C++ and slowly move it even to get to 11 and then 14.
How was that journey?
How have you been able to do that in a way?
It was a lot less complicated than what we had to do
at the beginning in
2000 to support
different compilers.
I remember having,
I mean, moving for, at the time
we had the Visual
Studio 6, I think,
on the Microsoft world.
And
I don't remember what was the compiler for Linux.
I think there was still the split between GCC and the other version.
EGCS.
Right.
2.95.
Classic.
Who then...
And there were some compilers that died, like MetroWorks or something.
So, yeah, it was more difficult to support all those compilers at that time
because I remember we used to have different macros
that expanded to different syntax for each of those. And, well, in comparison,
going from C++ 98 to 11,
well, it was not that difficult.
Well, mostly because we,
well, most of it was enabling an automated build
with Clang Tidy and looking at the suggestions
and putting them in the code.
And that did most of the work,
I would say, in modernizing.
I mean, auto, replacing iterators
with range four and this kind of stuff.
I mean, when we, I don't remember exactly in what year
we did the switch a few years ago but clank tidy was already good enough to do most of those
on its own so what you weren't like manually carefully laboriously going over every sort of
for loop and changing it you're able to use tooling. We didn't, yeah.
I mean, we do some of that, but it's more like the Boy Scout rule,
as in your editing file, you see something that could be modernized
and you do it.
But in no way we started going through all the code
and doing that manually. I mean we we have day jobs and
families and so one of the sort of bigger things that came in with c++ 11 was obviously all of the
smart pointers and you know to the extent that obviously um from my own vague understanding of
how this stuff might fit together there's quite a complicated graph of instruments that relate to other instruments and things that are part of some
other thing all this kind of stuff and that that to me smells like a whole bunch of like
dynamic allocations at least at startup and that's all that stuff so so is there was that a a manual
project that you had to go through to to like how were you doing it before? It wasn't because we were using the boost shared pointer before.
Ah, I see.
So it was relatively.
Almost since the beginning.
So, yeah, what we did was, well,
we still have the possibility in the code to use boost or stood shared
pointer.
Okay.
Basically we are remapping.
I mean, std shared pointer okay basically we are we are remapping i mean there's a big using somewhere given a compilation switch exactly we map either uh either the boost or std version to to a twin
a namespace inside quantlib and then we use that in the code and and uh yeah for some of the c++ of the modern facilities like stood function
like stood bind to tie this kind of stood tuple we have the switch but we are about to remove it and just use the standard version. Right. And for SharePoint, for smart pointers, we're still thinking about it
because it would be nice to just migrate to pointer and be done with it.
One consideration is we are Quantly Business C++
library, but we also
exported it to
Python, to
some other languages,
Java, C Sharp,
a few other languages,
by wrapping the library.
So it's not a port, it's just
a true-true SWIG, which is a
tool you probably know.
We wrap it and export to those.
Now, the one difference between Boost SharePointer and Stoots SharePointer we're concerned about
is that with Boost SharePointer, you can switch a compilation flag and provide a function
so that if you access a null pointer,
instead of just crashing, you get an exception and an error message.
I see.
Which is not the case with std share pointer, of course.
So in Python, having your program crash because of memory access
is kind of frowned upon.
So, I mean, it's not as expected as it might be in C++.
Right.
So, yeah, we have to figure out how to manage this. It should be possible by ensuring that in input
that you don't get any null pointers or do something like that.
But, well, it's still something we need to think about.
Yeah.
So just so I understand, with the boost one,
you're able to set a null pointer handler kind of thing
that can throw a Python exception instead and you get like, a hey you did something silly rather than a segful yeah i see
and presumably swig doesn't give you the option of like running a little function beforehand as
like a binding to check the null nullity of the point it might we will i see we should research
it there's probably some some check that you can add when you create,
when you pass an argument to a function or a method so that you can say,
okay, check that this, perform this check when you pass the argument
while you convert it.
So, yeah, it should be possible to.
But then, of course, we should be possible to but then of course we should be the problem at that point would be to mark
what pointers should be not non-null when you pass them to a function i see because not everything
yeah maybe you do pass nullable things to like hey this is a this takes a secondary instrument
or something and it may be not and that's different maybe not some kind of optional thing and in that case it can be null in other cases it's supposed to not to be that so
yeah so it's a problem with conflating pointers with optionality yeah we're stuck with that now
although when i was working in finance um you know i did what a lot of other people did and
just created my own smart pointer which solved those problems and we actually had a separate type for a non-nullable smart pointers
you always have to assign it to something but um not sure i'd recommend that approach these days
i was gonna say that ship has unfortunately long since sailed it's like oh yeah it's funny actually
one of the things that comes up a lot with with junior programmers is like the idea of like taking
uh you know if we can only had optional ref then we could have those semantics that are more clearly defined as either this
exists or it doesn't exist and i mean that those two big things to be separate um or else a pointer
where you're like well it's not it is allowed to be null or it's not allowed to be null it's yeah
yeah if only yeah so um i think you you mentioned the c++ 14 is your current target
yeah but can you uh if you're using an earlier version can you use quantlib at all at the moment
or you'd have to use an earlier version quantlib now quantlib is the other way around quantlib
contains the code of quantlib contains the c++ 14 features. So you need at least that version of the standard.
We check that it compiles.
And, well, ideally without warnings.
Also, if you compile it under C++ 17 or 20,
we have CI builds for that.
So you've got like early warning of anything you might be doing
that might cause you trouble in 10 years time yeah yeah because moving between language versions
and that that could be hard enough but in some ways that's the easy problem because when you've
got a library that's been existing over 20 years it's not just the language that changes but the the idioms the actual approach to
how you solve problems has changed i mean have you been able to evolve in that sense or is it
still sort of very much 2000 era architecture not not a lot not a lot. The architecture is more or less the one we had.
The big problematic piece of it being the notifications going on between the various objects.
As in, we designed the library so that, I mean, it's not just a set of mathematical functions,
as in you pass all your inputs, you get the output.
It's more of a reactive setup
in which you create your instruments,
you create your interest rate curves,
your term structure for, I don't know,
the full probability or whatever that is,
and your market values,
you pass them to the instrument when you create them,
and then you're able to change them.
So, for instance, change the interest rates or some stock values,
and the instrument gets notified that something changed
and recalculates, well, basically on demand, but it recalculates.
Yeah.
And that, well, so basically we implemented
the observer pattern from the Gang of Four book, basically.
Yeah.
And this, we looked into, I mean,
there are probably other solutions for that nowadays.
Yeah.
Probably things like boost signal or something like that.
It's going to be hard to extricate the library code from that.
No, exactly.
So, yeah, it will probably remain that that way same thing was with other
architectural decisions uh as i said we started in 2000. so in 2000 the idea was a computer said
well most computers had one core summit started having two yeah and and there was still the most low going in full swing so
processor were getting faster and faster and so that unfortunately we baked into the library
things like global a global evaluation data which is used throughout instead of instead of
threading it through all the functions calls that and that we get
it was convenient at the time nowadays it means you can't really do multi-threading calculations
with with quantlib so that the the common way people distribute work is a multi-process instead
right right yeah i think that phrase it was convenient
at the time that does a lot of work it's it's always the case anytime you have a singletoon
every time you have like a global every time you in actually many cases every time you use a shared
pointer there comes a point where you come to regret that decision and it's usually about a
year yet beyond and you're like,
it's too late now.
We're stuck with it.
So,
I mean,
the other way of phrasing that question is if you were to start
Quantlib today,
fresh Greenfield project using everything you now know,
would you do a lot of things differently?
Maybe.
I mean,
this, this observer thing that, well, I would try to stay,
to steer clear of globals, that's for sure.
So I would try to have, I would try to find some other way to,
it's not convenient if you have to pass the evaluation dates
to each call
and then each call has to thread it through all the calls
that come below so I would try some other
way to do that maybe it would be set
in some kind of context to an instrument or associated in an instrument with
some kind of context but not globals
so that and yeah I would probably sitting in an instrument with some kind of context, but not globals.
Yeah.
So that, and yeah, I would probably rethink this whole notification thing.
But otherwise, I think, I mean,
the choice of having instruments,
not recreating instruments, but creating them
and then having them react to to changing
market values i think i would keep i would keep that then of course another question i get a lot
of times is is uh would you still use c++ which is uh well yeah maybe, yeah, maybe.
I mean, it's, I mean, having it in C++
and exporting it to other languages is probably a convenient choice.
I mean, we use, I mean, where I work now,
well, which is still where I was working in 2000,
it's just that we got acquired a few times in the meantime.
We got acquired two or three times.
And we use Quantlib, of course, which is a boon for me
because this way I'm still allowed to work on Quantlib on company time
because I wouldn't be able to manage it if I had to do it on my own time.
And we use Quantlib, but we use it from Python. So the application code is in Python
because, well, the ecosystem is so much more convenient,
I mean, for talking to databases, for networking,
there's a module for that.
And also things like Jupyter for prototyping are great.
Yeah.
And so, well, having it in C++ for speed of calculation,
well, not that I'm that confident that our calculations go at the maximum speed.
We don't have a lot of expertise in that area.
But, well, having it in C++
and then using it from other languages
is probably a good compromise.
Right.
And with Swig, at least,
you've got access to quite a lot of other target languages.
You mentioned Python is only one of them, for example.
I'm not actually sure how well that works with, say, Rust or Zig
or some other languages.
I haven't tried.
Nowadays with Swig, we export, I mean, with the same set of interfaces,
we export to Python, we export to C Sharp, to Java, and to R.
The pirate language?
Yeah, R.
Yeah. and to R. The pirate language? Yeah, R. Yeah, even though there is another wrapper for R,
which is more idiomatic.
I see, okay.
But we still export to R as well.
We used to have other languages.
There was a time when I was young, when I kept learning and forgetting languages.
So we had Ruby, we had a couple of dialects of schema.
Oh, gosh.
Something like that at some point.
I mean, nobody was using them and maintaining the wrapper was just too much work.
So we let them go.
But yeah, SWIG gives access to a number of languages.
So we talked a lot about the application of Quantlib within finance,
which is what it's intended for.
Obviously, a lot of people listening are not in finance,
and this has been a useful background,
but are there any parts of the library that are not specifically
finance-related but represent problems you've had to solve along the way?
Well, the parts which are not finance-related,
well, it's probably the notification thing we talked
about or something like that
but it's not something that
you would use Quantlib for
if you're not in finance
well first because
the implementation is
tailored to
our specific use case
like cold pattern
implementation in a way.
No, I'm just more interested
in the type of problems you have to solve.
It's interesting to see the same problems
coming up in different domains
and how different people approach them.
Yeah, I would say the main one is this notification.
How do I manage notification between objects?
And yeah, for otherwise it's it's um
well it's mostly mathematics yeah yeah right and then financial models yeah my my experience has
always shown there's a lot of graph theory type stuff hiding in finance and so what i've seen
parallels there where you know trying to find shortest paths through a graph, which is, you know, works equally well on your mapping algorithm where you're trying to like do a star algorithm as it is to try and find a set of arbitrages between two points or trying to find the cheapest way of getting into a new position from where you are now.
So there's often a lot of things like that.
So is there anything like that in the world that you have to deal and model with?
No, it's not in the scope of the library right now.
This is where, yeah, the sort of difference of my background in this world.
Yeah, I mean, there's a lot which is not in the library.
The library is more the basic bits and some more common algorithms like like
bootstrapping a curve of interest rates given a set of market quotes this kind of i see more more
complex uh calculations that that you do on top of this, like, as I said, hedging, like calculating sensitivities, more calculation of margins,
stuff like this.
Quantlet gives you the tools to do that,
but then that is more application code,
which might be different depending on the requirements you have.
There's also a lot of
regulations in this field.
I see.
A European institution might do it differently
from a US one
or something like this.
It's more left to
applications.
Some of it is in
this other open source
project I mentioned that this open source
risk engine some is in other applications like for instance what we do in in our company
and stuff like this but there's no there's no it's not in quantlib got it so if i've sort of
my mental model now has gone back to my, the other thing that I have
any understanding of,
which is like the games industry.
And so if Quantlib
is like the sort of the game engine,
it gives you the ability
to draw triangles
and do some amount of collisions
and interaction between entities,
but you have to build the game
on top of it
and your game is different
to someone else's game.
And so layering on
the extra complexities.
Yeah, something like that.
Yeah. Interestingly, because I worked in finance as well i left that
eight years ago now so some of this is a little bit dated but um i know things move slowly
but um like compiler versions for example as paul luigi has to put up with yeah
um but we actually moved to a model where instead of all those notifications between objects because
we had the same the same thing originally and sometimes that was cause of a lot of the complexity
or issues particularly in debugging we moved to a model where we we captured the whole graph of
objects so we're getting matt's graph theory as its own entity uh store that all in a persistent
data structure so that when we
did something which changed the graph we could get a new version of the graph and we could do
a diff between the two and see which objects have been changed and so rather than the objects being
notified themselves we could do that all externally and leave that up to the application level
that's interesting here yeah that could be a big rabbit hole that we don't have time to get into now.
No, but it's fascinating.
Yeah.
It does solve a lot of problems for us.
So I wonder how many other people do something like that.
Yeah.
Debugging is something I don't think that people talk about so much with these kind of more complicated things, you know, like having the tooling and the visualizations.
And, you know, Luigi, you mentioned Jupyter Notebook.
That's kind of like for those in the C++ world who aren't used to it,
it's a way of running Python in like a browser.
I mean, maybe there are ways of running C++ in a browser.
I don't know.
But, you know, and so it's a very iterative, incremental, exploratory kind of feel to it.
And so that's a very different way of developing.
And certainly the quants that I work with want to play and tinker and tweak.
Which, by the way, is also available for C++.
There are...
Right.
Cling, I think, it uses with this.
Yeah.
They're using Cling to implement Jupyter.
But, I mean, in honesty, there's only so much interactivity.
I mean, I speak from personal experience here.
Only so much interactivity you can get out of a modest-sized piece
of C++ code before you're waiting too long for the builds
compared to Python, which is slow to execute, but quick to at least do something.
Oh, yeah.
Although to give you an idea of how far some people go, one bank I worked at, and I won't
mention the name of it, but they actually implemented something where, what was it?
It was an Excel plugin that the traders can actually write C++ in a cell, and then it
would go to a back end where
it compiled that c++ run it against the the quant library and give back a result and put it back in
the in the spreadsheet i i can neither confirm nor deny that similar things have happened in
my career in finance too yeah well the security people must have been ecstatic about that
they probably never knew oh yeah talking about debugging as well on my very
first day in a company that i worked in i was talking to a friend and i said what do you so
tell me what you're doing here he said i'm debugging a spreadsheet and i'm like uh where's
the door i've come to the wrong company this is not what i signed up for but because of exactly
that so obviously we have talked a lot about finance some some people have been curious
about that and um and hopefully this has given them some some insights for other people who are
thinking that's not something i'm ever going to be interested in obviously that's that's fine but i
want to inject one sort of personal opinion on this which is particularly at this level the the
sort of the quantitative finance level really it's just about a mathematical model
of the flow of value in the real world and to some extent taking advantage of that for you know
personal gain or the corporate gain or whatever but that's but fundamentally it's just purely
about how things work and the more you are involved in that domain or look into it the
more you actually understand just how things work in the world and it's not necessarily about the application of it so if
you'd never looked into it before i would advise at least some sort of cursory look into some of
the the models that underpin this all so that's my uh my opinion over your little soapbox moment
there but no I do agree.
I mean, from my own personal experience, I had no interest in finance,
and then I fell into it much as Luigi did.
You know, it was right place, right time.
And then over the years, I've learned to become fascinated by, as you say,
what it reveals about the real world and the interrelationships between things.
And admittedly, some of the things that are very obscure seem to have no actual real economic value,
but a lot of other
stuff does right and it's fascinating to learn how how the real world works and how things get
financed i mean in in principle finance could do i mean finance gets a bad name and it's partly
well deserved but in principle it could could do good i mean the possibility of giving credit
to to to companies uh for for for doing things that they might not be able to do otherwise.
I mean, that's a good thing that, well, unfortunately, it gets twisted.
Lost in the narrative sometimes.
But that's how the whole thing started a few centuries ago.
Right.
Right.
Or even just the idea that, you know, I've got some money.
You know, where do I put it?
Do I put it in a sock under the bed?
Well, if you do that, it's going to lose value over time.
You know, we're all aware of inflation and interest rates and things.
And because of the smell.
There are definitely smells involved.
But, yeah, if you turn a blind eye to it,
then you're going to be worse off.
It's not necessarily about taking advantage of other people,
although that happens as well.
But that lets you understand that the boy you're going to be
the one taking advantage of, unfortunately.
Right, the whole poker table analogy.
Yeah, exactly.
Yeah, so just one last question i have of it you know from from for
phil and i we've worked in the sort of traditional finance industry but there's there's a lot of
novel finance things coming up in the world um specifically i mean they're not that new now but
like the cryptographic um you know world has come with to us um and so you know with world has come to us. And so, you know, with Bitcoin and the 300 other things
that work a bit like it, but are different.
Does Quantlib support anything to do with crypto
or is it purely old school?
It's mostly old school.
We have some, I mean, we have a list of currencies
in the library and they're not used for much,
but well, there are some parts of the library and they're not used for much but well the the there are some some parts of the library which seem to be a good idea but then
yeah and we have a list of currencies and we have a few cryptocurrencies in there but there's not
really there's not really support for doing calculation with those
or something like that.
Got it.
Incidentally, the one who had the idea of Quantlib is now working in cryptocurrency.
So sort of ironic that Quantlib doesn't specifically uh go out of its way to support
it but that's how things change yeah it's just from my own experience of like using uh github
co-pilot like things you know ais every time i'm writing regular code in my boring day job
of like no boring in terms of like old school stuff you know and i put a list of like nasdaq
comma and whatever it wants to auto complete with all of the uh the bitcoin exchanges because that's
all it's been trained on right it's all the code in the universe this ever seen is about you know
uh crypto stuff so i wondered if if quantlib was responsible for this but no i can't tell you with
that brush okay yeah i haven't had that much interaction with Copilot or stuff like that.
Well, mostly because you can probably guess my age by the number of glasses
I'm hanging around my neck.
You and me both.
I'm still stuck with Emacs for editing.
Oh, I'm sorry to hear that.
I hear there's a really good editor hiding inside that operating system.
Yeah.
All right.
Okay, enough of the war.
Yeah, they should look into it.
There's probably some plug-in for Emacs.
I mean, there certainly is a plug- Plug it for e-mails, of course there is.
So if you are interested in learning Quantlib,
learning how to use it, what's the best way to do that?
Because if you go to the website,
most of the docs are just the class diagrams and things.
Yeah, that's not really the way to go.
There are examples around.
One of the books I have out about Quantlib is one which I co-wrote with another author.
It's just a collection of examples in Python,
but they can be translated into C++ easily enough.
Right.
Well, you have to add smart pointers,
which are hidden in the Python wrappers.
Right.
Because, well, most Python people wouldn't know what to do with those
and why they're there.
But there are a series of examples.
Some of those I recorded as YouTube videos.
I mean, the videos would be me going through the notebook
because they started as Jupyter notebooks
and running them and talking about what they do.
Well, the other book is more about the internals of quantlib so it's more if you're interested in
extending it so you need to know that the classier keys and and how those work in order to extend it
that that would be the other book right and uh then yeah in for instance, on my blog, I try to post other notebooks from time to time as more examples and so on.
Other people do the same way.
In fact, if you go to the website and go to – there's a page that collects some documentation from around the web.
So there are a number of blogs from other people as well,
which provide examples and so on.
But yeah, we don't have at this time, while I'm thinking about it,
and this is probably something I should give some time to,
we don't have some kind of manual where you, okay,
let's start from this and, and, and go through,
through Quantlib in some kind of more didactic way.
I mean, that takes you from, from zero to 2.8 MB and C and,
and that's probably something I should think about.
And I mean, might be,
some of the material is probably already in my notebooks,
but I should structure it
so that there's a progression for something,
for something who's learning.
Yeah, it's a lot of work.
So, yeah.
Yeah.
It's a whole other person's
job to write yeah good documentation it's really difficult to do and it's not to say one shouldn't
aspire to it but i don't think you should give yourself a hard time about not having it there
and it's not something i would do on company time so right right that's the other that's the other
difficulty yeah that's that's a tricky thing yeah of course your company yeah there's even
though you've got time to work on quantlib it's like well for the bits that benefit the company
as well as they do the wider world but not the ones that specifically for new people yeah
interesting yeah we'll put some of those links in the the show notes anyway so people have a place
to start so thank you for that so outside of um finance though is what kind of is there anything
else in the c++ world that
that has piqued your interest recently is there anything you know do you spend much time writing
c++ that isn't financey uh no not not really i mean that's because i don't program a lot outside
of the my day job right and it's um i mean some, well, apart from family hobbies and whatever,
what little I do is mostly some documentation for Quantlib,
so notebooks, examples.
I had a couple of books on that.
I was going to say, when I was doing research,
I noticed that you kind of had some blog posts that grew and grew and grew and actually became
a book by the looks of it.
Yeah, well, and
something like that. It started
as a book
and then at a certain
point it was going
very slow, so I started
posting it as
blog posts so that
in a way to shame me into into into a more regular
posting schedule and and so in in the end i could i could finish the thing yeah as i said when i was
younger and i was doing more more researching besides all those different languages, I was trying to keep more up to date with C++.
I was very into, well, I tried to cram as much of those into
quantlib as i could then and then thought better of it yeah i can see some of them still in the
in the docs here and uh yeah but uh yeah nowadays i i mean i try to keep abreast of what's happening in c++ but uh well not as much as as
as i used to right yeah yeah it's it's tricky to keep up with it it's why you know listening to
your local family run uh c++ podcast is one way of while you're walking the dog trying to keep
track of what the heck's going on that's how it works in my life anyway. Yeah, or better still, actually hosting one, yeah.
That's a good way as well.
Oh, yeah.
So thank you for coming on the show today, Luigi,
telling us all about Quantlib and the world of finance.
Thank you for reaching out.
It was great.
Is there anything else you want to tell us before you go,
such as where people can find you if they want to find out more?
Well, the main site for Quantlib is quantlib.org,
so that's easy enough to find.
But really, if you just search for Quantlib, you'll find it.
My own website is www.implementingquantlib.com but again is is because that that's the title of
the of the book right but again it's easier to search for luigi ballabio and and you'll get
there but well i'll send you the links for for your for your show notes anyway well thank you
and thank you again and thank you matt for coming on as our guest co-host.
Thank you for having me.
And Luigi, it's been a pleasure
chatting with you.
I'm really interested to spend some time
looking at Qualib myself now
just to sort of see a sort of parallel,
another implementation of something
that I've done a little bit of myself.
So I'm fascinated.
And thank you for your time.
No problem.
Thank you.
Thanks so much for listening in
as we chat about C++.
We'd love to hear what you think of the podcast.
Please let us know if we're discussing the stuff you're interested in.
Or if you have a suggestion for a guest or topic, we'd love to hear about that too.
You can email all your thoughts to feedback at cppcast.com.
We'd also appreciate it if you can follow CppCast on Twitter or Mastodon.
You can also follow me and
phil individually on twitter or mastodon all those links as well as the show notes can be found on