BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Develop Financial Applications with F# and QuantLib

Develop Financial Applications with F# and QuantLib

This item in japanese

Bookmarks

QuantLib is an open source library for modeling, trading and risk management of quantitative finance that can be used with F# lanugage. In order to access QuantLib, you have to make use of NQuantLib.dll, which is a .NET component and NQuantLibc.dll, which is a native component.

If the above library files are not available, then you can create them from .lib files, C++ source and header files by installing Boost to get the .lib and header files. You can also build the source in the official repositories for Boost or BoostPro.

The next step is install QuantLib to build the .lib and header files using Microsoft Visual C++ by following the instructions provided on the official documentation. After installation, download QuantLib-SWIG zip file, SWIG and run the swig.cmd file located on the QuantLib-SWIG\CSharp directory to generate the C++ wrapper file. You can now build NQuantLibc.dll and NQuantLib.dll using Visual Studio.

If you attempt to build the libraries with Visual C++ 2012, you need to fix auto_link.hpp as shown below

Open auto_link.hpp and locate the following lines

#else
# error "unknown Microsoft compiler"

Insert the following just before the above lines

#elif (_MSC_VER == 1700)
# define QL_LIB_TOOLSET "vc110"

Right click on the QuantLib project and select Properties. In Configuration Properties | General, change the Target Name to QuantLib-vc110-mt or QuantLib-vc110-mt-gd, depending on whether you are building release or debug versions of QuantLib.

The above workaround has been posted by a F# developer nicknamed pmcs on the official Microsoft blog and vetted by the product team.

After the completion of the above steps, place the NQuantLib.dll and NQuantLibc.dll in a directory under your F# scripting directory called references. If you are using a project, add NQuantLibc.dll as a file to the project and set Copy to Output to Copy if Newer.

In order to start working with F# and QuantLib using Visual Studio, you need to set Tools | Options | F# Tools | F# Interactive | 64-bit to False. You can also make use of MonoDevelop, Xamarin Studio or any text editor of your choice.

#I "references"
#r "NQuantLib.dll"
let date = QuantLib.Date.todaysDate()
printfn "today is: %s" (date.ISO())

The above piece of code prints the date on the F# interactive console. As you can see, we have referenced NQuantLib.dll and called todaysDate() function.

In big projects, you can also employ the keyword 'use' instead of 'let' for proper disposal of objects.

use date = QuantLib.Date.todaysDate()

The F# product team led by Don Syme in association with Alexandre Radicchi has examined the steps required to compile the library files with Mono and also covered few additional samples such as pricing a strip of European call options, dates and schedules.

Don recommends the book Implementing QuantLib for those interested to explore QuantLib in detail. The author of the book has provided draft copy of all the chapters which can be accessed free of cost.

Rate this Article

Adoption
Style

BT