前言

QuantLib是一套免費且開放原始碼(open-source)的quantitative finance library(財務的函式厙),是用強大的Boost C++ Library所開發的,託SWIG(Simplified Wrapper and Interface Generator)的福,我可以在熟悉的.NET環境底下使用QuantLib這個強大且方便的library。

QuantLib在財務方面提供了許多實用的class,從基本的Random Number Generator到各式各樣的Pricing Engines都有提供,甚至也有Monte Carlo蒙地卡羅的class(不過都還沒有去仔細研究裡面運作的方式orz),或是像Calendar這種可以根據各個國家有不同的Business Day Convention來計算交易日、結算日的class;此外各種金融商品也幾乎都有對應的class來處理,例如選擇權(Option)、期貨(future)等。雖然說我目前對於 QuantLib還不是很熟悉,不過之前花了點時間在嘗試將QuantLib拿來.NET的環境使用,在此分享一下安裝心得。

QuantLib網址:http://quantlib.sourceforge.net/index.shtml

有任何問題歡迎留言給我!Any question are welcomed.

Requirements

  • Microsoft .NET Framework 2.0
  • Microsoft Visual Studio 2005
  • Boost:QuantLib需要用Boost來進行編譯的動作。
  • BoostJam :BoostJam是用來編譯、安裝Boost的。
  • QuantLib
  • QuantLib Extension - SWIG:銜接.NET跟Boost C++之間的橋樑(wrapper)

Where to Download

Compile Your Boost C++ Library(Using bjam.exe)

  1. Extract Boost to any directory.
    (for example, “C:\Documents and Settings\deduce\Desktop\QuantLib\”)
  2. Extract BoostJam to any directory.(There would be 2 files: bjam.exe & LICENSE file)
  3. Copy bjam.exe to your Boost source code directory.(i.e. \boost_1_33_1\bjam.exe)
  4. Run your Command window and type “bjam -sTOOLS=vc-8_0 install” in boost_1_33_1
    (To change directory, type cd “C:\Documents and Settings\Wilmer\Desktop\QuantLib”)**The default directory of Boost is c:\Boost

Add Boost Files in your Visual Studio

  1. In Visual Studio 2005, TOOLS->Options->Projects and Solutions->VC++ Directory
  2. Show directories for “Include Files”, and add the directory c:\boost\include\boost-[version], such as “C:\Boost\include\boost-1_33_1”
  3. For “Libraries Files”, add the directory “c:\boost\lib”

Compile Your QuantLib

  1. Extract QuantLib.
  2. Open “QuantLib_vc8.sln” in QuantLib directory.
  3. Change “Debug CRTDLL” to “Debug”
  4. Set any example project as a startup project for build up your QuantLib and run example project.

Setting up QuantLib SWIG

  1. Extract QuantLib-SWIG
  2. Add a system Environment VariableQL_PATH” to your QuantLib path, such as
    “D:\My Documents\Documents\MIS Project\QuantLib-0.4.0”
  3. Open QuantLib.sln in QuantLib-SWIG\CSharp
  4. Try to run BermudanSwaption.

Create a new QuantLib project for yourself

  1. Create a new project
  2. Right click on the “Reference” in solution explorer and “Add Reference”
  3. Click on the tab “Browse” and find “NQuantLib.dll” in your QuantLib-SWIG\CSharp\csharp\bin\Debug,
    for example, ”D:\My Documents\Documents\MIS Project\QuantLib-SWIG-0.4.0\CSharp\csharp\bin\Debug\NQuantLib.dll”
  4. CopyNQuantLibc.dll” in your QuantLib-SWIG\CSharp\cpp\bin\Debug to “your Project\bin\debug”.
    For example,
    Copy “D:\My Documents\Documents\MIS Project\QuantLib-SWIG-0.4.0\CSharp\cpp\bin\Debug\NQuantLibc.dll
    to “D:\My Documents\Visual Studio 2005\Projects\ConsoleApplication7\ConsoleApplication7\bin\Debug”
  5. Add a new line of code“Using QuantLib;” in the head of your source code and enjoy QuantLib programming!

Reference