QuantLib Installation for .NET
前言
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
- QuantLib:http://sourceforge.net/project/showfiles.php?group_id=12740
- Boost C++ Libraries:http://sourceforge.net/project/showfiles.php?group_id=7586
Compile Your Boost C++ Library(Using bjam.exe)
- Extract Boost to any directory.
(for example, “C:\Documents and Settings\deduce\Desktop\QuantLib\”) - Extract BoostJam to any directory.(There would be 2 files: bjam.exe & LICENSE file)
- Copy bjam.exe to your Boost source code directory.(i.e. \boost_1_33_1\bjam.exe)
- 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
- In Visual Studio 2005, TOOLS->Options->Projects and Solutions->VC++ Directory
- Show directories for “Include Files”, and add the directory c:\boost\include\boost-[version], such as “C:\Boost\include\boost-1_33_1”
- For “Libraries Files”, add the directory “c:\boost\lib”
Compile Your QuantLib
- Extract QuantLib.
- Open “QuantLib_vc8.sln” in QuantLib directory.
- Change “Debug CRTDLL” to “Debug”
- Set any example project as a startup project for build up your QuantLib and run example project.
Setting up QuantLib SWIG
- Extract QuantLib-SWIG
- Add a system Environment Variable “QL_PATH” to your QuantLib path, such as
“D:\My Documents\Documents\MIS Project\QuantLib-0.4.0” - Open QuantLib.sln in QuantLib-SWIG\CSharp
- Try to run BermudanSwaption.
Create a new QuantLib project for yourself
- Create a new project
- Right click on the “Reference” in solution explorer and “Add Reference”
- 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” - Copy “NQuantLibc.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” - Add a new line of code“Using QuantLib;” in the head of your source code and enjoy QuantLib programming!
Reference
- Boost Installation: http://www.boost.org/more/getting_started.html