9
$\begingroup$

I want to include the QuantLib function for option greeks calculations in my own C++ code. My question is: can I just include those functions? I don't want to use the rest of their stuff.

I obviously cannot just write:

QuantLib::europeanOption.delta()

I have included the header:

#include <ql/quantlib.hpp>

using namespace QuantLib;

I wish they had some good documentation.

$\endgroup$
11
  • 1
    $\begingroup$ Since this is a programming-specific question, isn't this more appropriate for stack overflow? $\endgroup$ Commented Aug 26, 2011 at 0:39
  • $\begingroup$ ok, I'll ask there.. $\endgroup$ Commented Aug 26, 2011 at 1:25
  • 1
    $\begingroup$ @sheegaon This question is about a specific quant library. The user is asking about how to include a single function. So if anyone knows which header that specific function is in, it would be an existing user of said library. $\endgroup$ Commented Aug 26, 2011 at 1:43
  • 1
    $\begingroup$ Maybe it's worth posting a Community Wiki post on how to actually use QuantLib in a new project? Can we do Wiki posts here on QF SE? $\endgroup$ Commented Aug 26, 2011 at 14:03
  • 2
    $\begingroup$ I think this question is absolutely on topic here as it is. It is about a specific problem with a specific quant lib - so it fits in well in my opinion. $\endgroup$
    – vonjd
    Commented Aug 26, 2011 at 17:43

2 Answers 2

17
$\begingroup$

This is off-topic and maybe belongs to StackOverflow, but here goes.

1. Compile QuantLib

The best way is to open the Visual Studio Command Prompt using a shortcut under Programs→Microsoft Visual Studio→Visual Studio Tools. Now, you need to navigate to the QuantLib folder inside the folder where you have QuantLib (there are other folders such as QuantLibXL – that’s not the one you need.

Now, compile the whole of QuantLib by running the following command: msbuild /t:Rebuild /p:Configuration=Release QuantLib_vc10.sln.

Inside this folder, if you look in the lib folder, you’ll get a lib file called QuantLib-vc<VER>-mt.lib and a corresponding file with a -gd suffix. You need these libs as well as the headers.

2. Configure headers

Right-click the project and choose Properties. Now, make sure you choose All Configurations in the configuration drop-down list box on the top-left of the window. First, navigate to ConfigurationProperties→C/C++→General. In the Additional Include Directories, add the path to QuantLib’s directory. If you add the <QL Root>\QuantLib directory, you will be able to reference QuantLib headers with statements such as #include <ql/someheader.hpp>. If you did it correctly and you’re using VS2010, IntelliSense will kick in immediately, meaning if you type #include <ql/, VS will show you a helper list with headers (which is useful).

3. Configure library references

Now, navigate down to Configuration Properties→Linker→General. In the Additional Library Directories add the path to the QuantLib’s \lib directory.

Now move down to the Input header under the Linker header. Edit the Additional Dependencies field, prepending it with the name of the QuantLib library file — you need to specify the filename (without the full path) of the .lib file you need to include. The -mt.lib file is used for the Release build, and the -mt-gd.lib for the Debug build. If you mess these up, you'll get errors.

4. Run it

By now, assuming you have the boost libraries in your VS \include folder, the following should compile and run without problem:

//first line is required in .NET
#include "stdafx.h"
#include <iostream>
#include <ql/quantlib.hpp>

using namespace std;
using namespace QuantLib;

void main()
{
  boost::shared_ptr<Money> m(new Money);
  cout << m->value() << endl;

  getchar();
}
$\endgroup$
0
7
$\begingroup$

How at ease are you with programming, dynamic linking, Makefiles and the rest?

In essence, there is no magic here. QL has a very liberal license, and you "merely" have to set up your project such that it finds

  • the quantlib headers (and hence Boost headers) during compilation

  • the quantlib library during linking

and both of those can be automated by calling quantlib-config with proper flags --clags and --libs, respectively.

This is really no different than linking to any other external library.

$\endgroup$
1
  • $\begingroup$ from my linux shell, quantlib-config --libs prints out -L/usr/local/lib -lQuantLib telling me to g++ myQL.cpp -L/usr/local/lib -lQuantLib -o my_executable. Docs for quantlib-config helper program: linux.die.net/man/1/quantlib-config $\endgroup$
    – Pete
    Commented Sep 12, 2011 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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