Develop Financial Applications with F# and QuantLib

| by Anand Narayanaswamy 0 Followers on Apr 26, 2013. Estimated reading time: 2 minutes |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

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.

Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Cannot open source file "ql/quantlib": no such file or directory

Hi ... just trying to follow the above and have got to the point of building nquantlibc.dll and nquantlib.dll and the above error message is thrown. I'm not familiar with c++ at all so am at a bit of a loss. I assume I need to do something like add a reference/move a file somewhere but I'm not sure quite what. I'm trying to build in vs11. I used the latest boost (1.53.0) but again am unsure whether this would make a difference. The auto_link.hpp seems to already have a change in for x86/x64 vs11. Thx ia.
Close

by

on

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Login to InfoQ to interact with what matters most to you.