• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

TUTORIAL: Boost 1.37.0 + QuantLib 0.9.6 and Visual Studio 2008

Building Boost 1.35.0 + Quantlib 0.9.0 with Visual Studio 2008

These instructions are for building Boost 1.35.0 + Quantlib 0.9.0 with Visual Studio 2008 (VS2008). The instructions have been successfully tested on Team Edition, Professional Edition and Express version of VS2008.

WARNING: We assume that you have VS2008 (for Team Edition) or Visual C++ 2008 (Express version) fully working before attempt to use this guide.

To use Quantlib, you have to build Boost first.

STEP 1: Install and build Boost 1.35.0

To build Boost you will need The Microsoft Windows SDK for VS2008 . This is available as an option when installing Visual Studio 2008.
You can also download it from Microsoft website at http://www.microsoft.com/downloads/...23-93ca-479a-867c-04dc45164f5b&displaylang=en
The file you want to download is VsSDK_sfx.exe (96.5 MB)

To run Visual C++ (vc++) from the command prompt you will need some msvc related environment variables. Msvc comes with a batch file that sets these environment variables. An easy way to use this batch file is to copy the "Start/All Programs/Accessories/Command Prompt" short cut from the start menu to your desktop and then change the short cut target property to %SystemRoot%\system32\cmd.exe /K call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
After doing this, this short cut should bring up a command environment ready to run vc++. All the command line work described in the remainder of this post should be done using a cmd window in which vcvarsall.bat has been run ( whether through the shortcut just described or by some other means ).

Download boost 1.35.0 from sourceforge.net and uncompress. I used the zip file here:

http://internap.dl.sourceforge.net/sourceforge/boost/boost_1_35_0.zip

Download and unzip Boost into your C: drive. You should have a new directory called C:\boost_1_35_0
Now it's time to build bjam (the boost build tool) from the cmd shell as follows:

Code:
cd boost_1_35_0\tools\jam\src
build.bat
This should build src\bin.nt\bjam.exe, the command that you will use to build the rest of boost. You may see a few errors which you can ignore as long as bjam.exe gets built.

After making these changes, go to the top level directory: C:\boost_1_35_0 (THIS IS VERY IMPORTANT) and type:
Code:
tools\jam\src\bin.ntx86\bjam.exe --build-type=complete
All of the boost libraries will get built. This may take several hours depending on the speed of your computer. When complete, type:
Code:
tools\jam\src\bin.ntx86\bjam.exe --build-type=complete install
This will take a few more minutes. When done, this will build the boost libraries and install them in C:\Boost

When you want to build a program that uses the boost toolkit, you will need to let the compiler and linker know where to find the boost files. Do this from within VS2008, by selecting "Tools/Options/Projects and Solutions/VC++ Directories" (starting from the menu bar and ending up in a dataform), and adding C:\Boost\include\boost-1_35 to the include directories and C:\Boost\lib to the Library directories.

STEP 2: Install and build Quantlib 0.9.0
Quantlib will not work without Boost. Attempt this step only AFTER you complete STEP 1 above.

Download quantlib 0.9.0 from here:
http://superb-east.dl.sourceforge.net/sourceforge/quantlib/QuantLib-0.9.0.zip

Unzip and extract it to your C:\ drive. When done, you should have a new folder: C:\QuantLib-0.9.0

The quantlib 0.9.0 code needs some changes to work with VS2008.

A patch is attached to this message that can be used to make all the code changes necessary for quantlib 0.9.0 to compile and link under VS2008. Save it to text file called patch.txt on your C:\ drive (THIS IS IMPORTANT).

To apply the patch you will need to have the patch program in your %PATH% or use the full path name to the patch program. The patch program can be downloaded from:
http://internap.dl.sourceforge.net/sourceforge/gnuwin32/patch-2.5.9-7-setup.exe
Download and install this as a regular program.

To apply the patch using a dos command shell, move to C:\ directory and type the following command:

Code:
C:\type patch.txt | "c:\Program Files\GnuWin32\bin\patch.exe" -p0
If done correctly, you will see the following output:
Code:
patching file QuantLib-0.9.0/QuantLib_vc8.vcproj
patching file QuantLib-0.9.0/ql/auto_link.hpp
patching file QuantLib-0.9.0/ql/config.msvc.hpp
patching file QuantLib-0.9.0/ql/utilities/tracing.hpp
At the top level of the quantlib source code tree (QuantLib-0.9.0) is a "msvc solution" file: QuantLib_vc8.sln . Open this with VS2008. You will be asked if you want to convert older solutions/projects to the latest version. Answer yes and let the conversion proceed.


STEP 3: Test Quantlib sample code
If you follow STEP 1 and 2 correctly, now you should be able to build and run your Quantlib code.
When you open Quantlib_vc8.sln, under Solution Explorer, you will see 11 examples:
Code:
BermudanSwaption
ConvertibleBonds
DiscreteHedging
EquityOption
FittedBondCurve
FRA
QuantLib
Replication
Repo
Swap
testsuite
Right click on QuantLib and select Set As Startup Project, then right click and select Build.
This will take a while for Quantlib to build all links. BE PATIENCE.

When the build is complete, right click on one of the other examples (Repo) and repeat the same steps you did for Quantlib. When done, click F5 to run the Repo example.
This should be the output of the code
Code:
Underlying bond clean price: 89.9769
Underlying bond dirty price: 93.288
Underlying bond accrued at settlement: 3.31111
Underlying bond accrued at delivery:   3.33333
Underlying bond spot income: 3.9834
Underlying bond fwd income:  4.08465
Repo strike: 91.5745
Repo NPV:    -2.64151e-005
Repo clean forward price: 88.2411
Repo dirty forward price: 91.5745
Repo implied yield: 5.000060 % Actual/360 simple compounding
Market repo rate:   5.000000 % Actual/360 simple compounding

Compare with example given at
[URL="http://www.fincad.com/support/developerFunc/mathref/BFWD.htm"]Bond Forwards and Futures[/URL]
Clean forward price = 88.2408

In that example, it is unknown what bond calendar they are
using, as well as settlement Days. For that reason, I have
made the simplest possible assumptions here: NullCalendar
and 0 settlement days.

Run completed in 0 s
Thank you, Andy, for proofreading and significantly improving these instructions.
 

Attachments

Hi, thank you for the great instruction.
Now, I can build quantlib solution...

but, i need a few more patches for quantlibxl as well. Can you also add the instruction on how to build quantlibxl on VS2008?(I am using express edition). Thanks,
 
Thank's Dave for your solutions!!!!!!!!!!!!!!!!!!!

Do you have any suggestions about QuantlibXL??????
I can't install it on the rigth way.
Thank's for your help
 
Hi Andrea,

I don't have any suggestions for quantlibxl. I looked at it briefly but I don't have easy access to excel so even if I got it built I wouldn't have a good way to test it.

- Dave
 
Thank you Dave.

Maybe someone could help me to build object handler with visual c++ 2005.
I tried to follow the instructions QuantLibXL but when I'm trying to build log4cxx I have these errors:

1>------ Build started: Project: log4cxx, Configuration: Release Win32 ------
1>Compiling...
1>timezone.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>threadspecificdata.cpp
1>..\..\src\threadspecificdata.cpp(22) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>thread.cpp
1>..\..\src\thread.cpp(20) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>telnetappender.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>system.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>syslogwriter.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>syslogappender.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>stringmatchfilter.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>static.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>socketoutputstream.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>socketnode.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>socketinputstream.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>socketimpl.cpp
1>..\..\src\socketimpl.cpp(20) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>sockethubappender.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>socketappender.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>socket.cpp
1>..\..\src\socket.cpp(20) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>simplelayout.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>serversocket.cpp
1>..\..\src\serversocket.cpp(20) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>semaphore.cpp
1>..\..\src\semaphore.cpp(22) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>rootcategory.cpp
1>c:\build_ql_0_9_0\log4cxx\include\log4cxx/helpers/criticalsection.h(25) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
1>Generating Code...
 
is 'windows.h' in your include directory? It looks it can't find it.
 
Hi Andrea,

Here are a few tips that might be of some help. I'm going by memory here because I don't have Visual Studio 2005 but hopefully what follows is accurate enough to be useful.

As Alain pointed out, windows.h is not being found. This is either because it is not on your computer or the compiler does not know where to find it.

To get it onto your computer, make sure that you have not only Visual Studio installed but the Microsoft Windows SDK also. I don't remember if windows.h itself is included in Visual Studio or the SDK but I'm pretty sure you will need the SDK eventually even if windows.h is in Visual Studio by default. Unlike Visual Studio 2008, VS 2005 does not provide the SDK as an optional component of installation. You need to install it seperately.

However, my guess is that windows.h is present but the compiler is not finding it. If this is the case, there are .bat files provided with the SDK (or maybe Visual Studio) that will configure your cmd environment for the compiler to find the correct include files. In Visual Studio 2008, this file is C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat. and there are instructions on an easy way to use it in boost related portion of the instructions that I posted on April 9 . I don't know what the cooresponding file is in VS 2005 but I remember that there was one.

Good Luck!

- Dave
 
Thank you Dave.

When I install Boost and compiled QuantLib, I got "warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss XXXX.cpp" for many many times. Did anyone have the same situation? Thanks


Raywin
 
Hi,

I downloaded (free) Visual C++ Express but it seems the SDK for VS2008 (provided by the link) will not work with the free version. I understood the instructions to mean that the SDK would work with the free VS++ Express so this means I won't be able to get boost 1.35.0 and quantlib 0.9.0 to compile?

I've also tried to make the changes to the files auto_link.hpp, config.msvc.hpp and tracing.hpp manually suggested. For tracing.hpp I get error c2990 without the changes and "C2653: 'Quantlib' : is not a class or namespace name" with the changes.

Has anyone encountered these as well and have a solution?

Thanks.
 
I downloaded (free) Visual C++ Express but it seems the SDK for VS2008 (provided by the link) will not work with the free version.


The free Visual Studio is the only version of VS2008 that I have used and it works fine with the SDK. What symptoms are you seeing that make you think it is not working?


I understood the instructions to mean that the SDK would work with the free VS++
Express .


Correct.

I've also tried to make the changes to the files auto_link.hpp, config.msvc.hpp and tracing.hpp manually suggested. For tracing.hpp I get error c2990 without the changes and "C2653: 'Quantlib' : is not a class or namespace name" with the changes.

I don't think all the changes were made correctly. The easiest and most reliable way to make these changes is to use the patch program as described in the 04-09-2008 post to this thread. If you would like me to check the changes you made, send the modified files to dave4365@gmail.com .

- Dave
 
Hi Dave,

Thanks for your reply.
On trying to install the SDK, I get a popup to say I need to have the MS VS 2008 Standard Edition or above for the install to proceed.

I'll send you my edited files, thanks.
 
The tracing.hpp file that you sent me was not correctly modified. I sent you back a correctly modified version.

The SDK is available as an option when you install VS2008. If you check the "install SDK" box at install time, you will get it. You may already have it.

- Dave
 
Dave,
Thanks for your file. I had QuantLib with a small "l" instead in tracing.hpp which was causing the error. Have some linking errors now that I'll try and fix.
 
Hi Dave,

I've tried building the FittedBondCurve example and got the linking error below. I installed quantlib in D: drive and I have explicitly given the path ("D:\QuantLib-0.9.0\lib"), as a possible workaround, to quantlib-vc80-mt-gd-0_9_0.lib that I've verified is present. Why is the linker not finding the file and why is it looking for "..\..\lib\quantlib-vc80-mt-gd-0_9_0.lib".

Separately I've installed boost to D:drive and I can see the instruction "tools\jam\src\bin.ntx86\bjam.exe --build-type=complete install" didn't work correctly - it was expecting boost to be installed in the C: drive. Is it possible to run the command giving it D: instead for the root directory.

Thanks.


1>------ Build started: Project: FittedBondCurve, Configuration: Debug CRTDLL Win32 ------
1>Linking...
1>LINK : fatal error LNK1104: cannot open file 'QuantLib-vc90-mt-gd-0_9_0.lib'
1>Build log was saved at "file://d:\QuantLib-0.9.0\Examples\FittedBondCurve\build\vc80\Debug CRTDLL\BuildLog.htm"
1>FittedBondCurve - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

the command link from VS is:

/OUT:".\bin/FittedBondCurve-vc80-mt-gd.exe" /INCREMENTAL /NOLOGO /LIBPATH:"D:\QuantLib-0.9.0\lib" /MANIFEST /MANIFESTFILE:".\build\vc80\Debug CRTDLL\FittedBondCurve-vc80-mt-gd.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:".\build\vc80\Debug CRTDLL/FittedBondCurve.pdb" /SUBSYSTEM:CONSOLE /DYNAMICBASE:NO /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "..\..\lib\quantlib-vc80-mt-gd-0_9_0.lib"
 
I've tried building the FittedBondCurve example and got the linking error below. I installed quantlib in D: drive and I have explicitly given the path ("D:\QuantLib-0.9.0\lib"), as a possible workaround, to quantlib-vc80-mt-gd-0_9_0.lib that I've verified is present. Why is the linker not finding the file and why is it looking for "..\..\lib\quantlib-vc80-mt-gd-0_9_0.lib".


This symptom is probably due to QuantLib_vc8.vcproj not being patched correctly. It has to be patched before VS does the automatic conversion to VS2008 format. The change is just a single character edit as follows:

Code:
old:                               OutputFile=".\lib\QuantLib-vc80-mt-gd-0_9_0.lib"
new:                               OutputFile=".\lib\QuantLib-vc90-mt-gd-0_9_0.lib"
Once you have done this the link line will look like this:

/OUT:".\bin/FittedBondCurve-vc80-mt-gd.exe" /INCREMENTAL /NOLOGO /LIBPATH:"..\..\lib" /MANIFEST /MANIFESTFILE:".\build\vc80\Debug CRTDLL\FittedBondCurve-vc80-mt-gd.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:".\build\vc80\Debug CRTDLL/FittedBondCurve.pdb" /SUBSYSTEM:CONSOLE /DYNAMICBASE:NO /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "..\..\lib\quantlib-vc90-mt-gd-0_9_0.lib"

Note that this is the same link line as what you had *except* for the last library.

Separately I've installed boost to D:drive and I can see the instruction "tools\jam\src\bin.ntx86\bjam.exe --build-type=complete install" didn't work correctly - it was expecting boost to be installed in the C: drive. Is it possible to run the command giving it D: instead for the root directory.


The bjam option you are looking for is --prefix=d:\Boost .
 
Update for Boost 1.36.0 + Quantlib 0.9.6

These instructions are for building Boost 1.36.0 + Quantlib 0.9.6 with Visual Studio 2008 (VS2008). The instructions have been successfully tested on Express version of VS2008.

These instructions are an updated version of instructions in this thread for building Boost 1.36.0 and Quantlib 0.9.6 . Part of the process outlined in *those* instructions was the application of a patch to Quantlib. In Quantlib 0.9.6, the patch is no longer necessary which makes the process quite a bit simpler. That is the major difference between this version and the earlier version.

WARNING: We assume that you have VS2008 (for Team Edition) or Visual C++ 2008 (Express version) fully working before attempt to use this guide.

To use Quantlib, you have to build Boost first.

STEP 1: Install and build Boost 1.36.0

To build Boost you will need The Microsoft Windows SDK for VS2008 . This is available as an option when installing Visual Studio 2008.
You can also download it from the Microsoft website. The file you want to download is VsSDK_sfx.exe (96.5 MB)

To run Visual C++ (vc++) from the command prompt you will need some msvc related environment variables. Msvc comes with a batch file that sets these environment variables. An easy way to use this batch file is to copy the "Start/All Programs/Accessories/Command Prompt" short cut from the start menu to your desktop and then change the short cut target property to %SystemRoot%\system32\cmd.exe /K call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
After doing this, this short cut should bring up a command environment ready to run vc++. All the command line work described in the remainder of this post should be done using a cmd window in which vcvarsall.bat has been run ( whether through the shortcut just described or by some other means ).

Download boost 1.36.0 from sourceforge.net and uncompress. I used the zip file here:

http://internap.dl.sourceforge.net/sourceforge/boost/boost_1_36_0.zip

Download and unzip Boost into your C: drive. You should have a new directory called C:\boost_1_36_0
Now it's time to build bjam (the boost build tool) from the cmd shell as follows:

Code:
cd boost_1_36_0\tools\jam\src
build.bat
This should build src\bin.nt\bjam.exe, the command that you will use to build the rest of boost. You may see a few errors which you can ignore as long as bjam.exe gets built.

After making these changes, go to the top level directory: C:\boost_1_36_0 and type:

Code:
tools\jam\src\bin.ntx86\bjam.exe --build-type=complete
All of the boost libraries will get built. This may take several hours depending on the speed of your computer. When complete, type:

Code:
tools\jam\src\bin.ntx86\bjam.exe --build-type=complete install
This will take a few more minutes. When done, the boost libraries will be installed in C:\Boost

When you want to build a program that uses the boost toolkit, you will need to let the compiler and linker know where to find the boost files. Do this from within VS2008, by selecting "Tools/Options/Projects and Solutions/VC++ Directories" (starting from the menu bar and ending up in a dataform), and adding C:\Boost\include\boost-1_36 to the include directories and C:\Boost\lib to the Library directories.

STEP 2: Install, build, and test Quantlib 0.9.6
Quantlib will not work without Boost. Attempt this step only AFTER you complete STEP 1 above.

Download quantlib 0.9.6 from here:
http://superb-east.dl.sourceforge.net/sourceforge/quantlib/QuantLib-0.9.6.zip

Unzip and extract it to your C:\ drive. When done, you should have a new folder: C:\QuantLib-0.9.6

At the top level of the quantlib source code tree (QuantLib-0.9.6) is a "msvc solution" file: QuantLib_vc9.sln . Open this with VS2008.

Change the active solution from "Debug CRTDLL" to "Release CRTDLL" by selecting "Build/Configuration Manager" in VS2008

Press F7 to build and test the project.

After pressing F7, Visual Studio will build quantlib, build all of the examples,build the testsuite, and run the test suite inside the VS environment. Once this is done the last thing to appear in your output window should be the following:

Code:
12> 
12>Tests completed in 1 h 1 m 4 s
12>Test suite "Master Test Suite" passed with:
12>  413 assertions out of 413 passed
12>  363 test cases out of 363 passed
12>Build log was saved at "file://c:\QuantLib-0.9.6\test-suite\build\vc90\Release CRTDLL\BuildLog.htm"
12>testsuite - 0 error(s), 0 warning(s)
========== Build: 13 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Note the "363 test cases out of 363 passed" message indicating that all tests in the test suite passed.

Thank you, Andy, for proofreading and significantly improving these instructions.
 
Back
Top