7
$\begingroup$

I am thinking of writing a VaR framework for my existing system, using quantlib to do the bulk of the calculations.

Despite several searches, I have not as yet come across a quantlib VaR implementation. Is anyone aware of a quantlib based VaR implementation that I may be able to use a s a starting point (to prevent reinventing the wheel)?

Assuming that such a library/framework does not exist - could someone please outline the main steps involved in putting together such a system - so I can make sure that I am not missing anything obvious/ I am on the right track.

For instance, I will have to map my current rate curves and instruments to the Quantlib objects. I will write adaptors to doing the mapping between the classes so assuming that is out of the way, it would be useful to get an outline of the steps required to put a VaR system together using quantlib (assuming there is no such library/framework to build from).

$\endgroup$
3
  • 1
    $\begingroup$ There's no public QuantLib-based implementation as far as I know. What kind of VaR methodology will you be using? And on what kind of system would you bolt it? $\endgroup$ Commented May 3, 2012 at 10:35
  • $\begingroup$ @LuigiBallabio: re type of VaR: historical simulation VaR. The system is a proprietary (internally developed) one we use for trading. HTH. $\endgroup$ Commented May 4, 2012 at 15:08
  • $\begingroup$ My impression was that quantlib is mostly bare pricing code. I think an good VaR framework comes from efficiently managing the dependency graph of instruments and risk factors to avoid computing anything twice or having to load data too often. And this is facilitated by exposing the pricing code to some sort of modelling language more suitable for VaR simulation. I'd be interested to know if you find anything out about the Quantlib framework as a VaR tool. I had a look about a year ago and did not find anyone writing about it. $\endgroup$
    – safetyduck
    Commented May 8, 2012 at 12:56

3 Answers 3

7
$\begingroup$

I'm guessing you're simulating rate curves etc. inside your system, and you want to reprice your instruments over the simulated curves using QuantLib. In this case, most of the logic is in your system already, and you have to plug pricing functionality in.

If so, I don't think there's many steps involved besides, well, pricing the instrument on the simulated scenarios. My suggestion for doing that is to use the facilities provided by QuantLib (like quotes and the observer/observable pattern) to avoid repeat all the mapping work on each scenario. For instance, you can instantiate a given instrument just once; for each scenario, you can then relink the relevant handles to the simulated curves and ask the instrument for its new price. The machinery is already in place; you can look at the test suite (say, to testGreeks in the europeanoption.cpp file, where we perturb market quotes to trigger changes in price) to see it in action. For a description of the framework, you can see http://implementingquantlib.blogspot.com/p/the-book.html.

For what is worth, the library provides the basic VaR functionality in its Statistics class; it's just the stats calculation given a set of numbers, but still it's one less small wheel to reinvent.

If you think that QuantLib might help somehow in simulating the curves, please comment here and I'll try to extend the answer. But since you already have a trading system, you already have a curve builder, so I guess you want to keep using that.

$\endgroup$
1
  • $\begingroup$ We already have a curves defined within our system, so as much as possible, I would like to reuse that. My initial thought is to use quantlib for the pricing. I'll take a look at the link you posted and see if it generates any further ideas. Thanks for your input. $\endgroup$ Commented May 7, 2012 at 20:40
7
$\begingroup$

There is experimental code available under https://sourceforge.net/tracker/?func=detail&atid=312740&aid=3413982&group_id=12740

Basically I tried to answer the question if you should do the riskfactor shifts on the level of the pricing engine or on the level of the market data. For me the answer is that one has to do it on the level of the market data. The code implements the shift on the level of the pricing engine. Its very experimental. Nevertheless I've checked the results with the output of some commerical software and found agreement. So it might be a starting point.

$\endgroup$
1
  • $\begingroup$ +1 for the link. I'll download it and take a look at it for some ideas. As an aside, our portfolios are largely non-linear, we trade options almost exclusively, but I hope your codebase could be a useful starting point. Thanks $\endgroup$ Commented May 10, 2012 at 15:56
2
$\begingroup$

Why don't you try to contact them

http://quantlib.org/mailinglists.shtml

I've worked with them in the past, they're very nice people and will help you for sure if they can.

$\endgroup$
4
  • 2
    $\begingroup$ If you want to reach out, the QuantLib mailing list is a better option. If you use the StatPro contacts listed on their page you're going through sales. It might be what you want; just be aware of the difference between QuantLib (the open source project) and StatPro (the for-profit company). $\endgroup$ Commented May 3, 2012 at 10:34
  • $\begingroup$ Apologies for the mistake $\endgroup$
    – mepuzza
    Commented May 3, 2012 at 12:34
  • $\begingroup$ @LuigiBallabio: Which list do you recommend - 'users 'or 'dev' for VaR implementation related questions? $\endgroup$ Commented May 4, 2012 at 15:10
  • $\begingroup$ I'd say 'users', to reach more people. In hindsight, having two lists was probably not much of an idea. The traffic is not nearly large enough for specialized forums... $\endgroup$ Commented May 7, 2012 at 14:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.