1. Introduction
QuantLib is a C++ Open Source library for financial quantitative analysis that contains several kinds of source code; code that perform mathematical operations, such as constrained and unconstrained optimization and/or interpolation, code that generates random numbers sampled from a given probability distribution and code that computes the price of derivative contracts with assigned parameters. QuantLib usually requires another library called the Boost library.
bs_symphony and mc_symphony are packages containing Symphony applications that implement, using the QuantLib API, the evaluation of the price of a call option with the prescribed values of underlying volatility, discount factor and strike price with Black Scholes formula (bs_symphony) and a Monte Carlo method (mc_symphony), respectively.
The two packages have the following structure:
bs_symphony/
README
black.xml: Application profile
client/: Application client code
service/: Application service code
mathlib/: Library of Black and Scholes engine written with QuantLib API.
common/: Message classes used by client and service
mc_symphony/
README
mc.xml: Application profile
client/: Application client code
service/: Application service code
mathlib/: Library of QuantLib Monte Carlo engine written with QuantLib API
tools/: Tools to read files and process user input
common/: Message classes for by client and service
The Symphony environment can be configured to have service code depend on any libraries. In this case, it is necessary to convert the application originally written with C++ QuantLib into a static library with the extension 'a' (for example math.a). This library is put in a bigger library that also contains the Symphony libraries needed for the input/output operations. Note that the input/output instructions must be adapted to the input/output needs of the application.
In Section 2, instructions for the QuantLib installation are briefly explained.
In Section 3, we describe the steps that must be performed to make the pricing engines available in the Symphony environment as services.
2. QuantLib installation
The QuantLib applications were tested on Linux with kernel 2.4 and 2.6. The QuantLib applications were written in QuantLib 0.9.0, Boost 1.34.1 and Symphony DE 5.0 API and compiled with g++ 3.4.3
We assume that Symphony DE is installed in the directory ${HOME}/SymphonyDE
To install two libraries, Boost 1.34.1 and QuantLib 0.9.0, it is necessary to download the following compressed files: boost-1_34_1.tar.gz and boost-jam-3.1.13-1-linuxx86.tar in ${HOME}/boost/ from the website and QuantLib-0.90.tar.gz in /home/quantlib/ from the website
To install Boost 1.34.1 the following commands are necessary (we assume Bash):
>> cd ${HOME}/boost/
>> tar zxvf boost-1_34_1.tar.gz
>> cp boost-jam-3.1.13-1-linuxx86.tar ${HOME}/boost-1_34_1/.
>> tar zxvf boost-jam-3.1.13-1-linuxx86.tar
>> configure prefix = ${HOME}/boost/
>> make install
To install QuantLib-0.9.0 the following commands are necessary:
>> cd ${HOME}/quantlib/
>> tar zxvf QuantLib-0.90.tar.gz
>> configure -disable-shared --with-boost-include=${HOME}/boost/include/boost-1_34_1 --with-boost-lib=${HOME}/boost/lib -prefix=${HOME}/quantlib
>> make install
Finally, update the library path:
>> export LD_LIBRARY_PATH = ${HOME}/boost/
>> export LD_LIBRARY_PATH = ${HOME}/quantlib/
3. How to run bs_symphony
To make the Black Scholes pricing engine in QuantLib available in the Symphony environment as a service, you must perform the following steps:
1) Connect to the server where Symphony, Quantlib and Boost are installed. Source the necessary Symphony environment and start up Symphony through the following commands:
>> . profile.soam
>> soamstartup &
2) Uncompress the bs_symphony package, in ${HOME}/SymphonyDE/5.0/
3) Build the application with following commands;
>> cd ${HOME}/SymphonyDE/5.0
>> export QUANTLIB path_to_the_quanlib_library
>> make
4) In the directory ${HOME}/SymphonyDE/5.0/bs_symphony/output/, compress the file service and deploy the compressed file with the following commands;
>> tar cvf service.tar service
>> gzip service.tar
>> soamdeploy add BlackScholesServicePgk -p service.tar.gz -c /BlackScholes
5) In the directory ${HOME}/SymphonyDE/5.0/bs_symphony/, create the application profile, black.xml.
>> soamreg ${HOME}/SymphonyDE/5.0/bs_symphony/black.xml
6) Confirm that the registration worked by running the following command;
>> soamview app
Verify that the application, BlackScholes, is enabled.
7) Now you can run the client of new Symphony application, BlackScholes (bs_symphony), in the directory ${HOME}/SymphonyDE/5.0/bs_symphony/output/ with:
>>./client [input file name] [number of tasks]
Note:
[input file name] is a text file containing input data. Each line in the file that consists of 4 input parameters, value of underlying, volatility, discount factor and striking price, is separated by comma.
[number of tasks] is a number of splits applied to your tasks input. If the input file contains 10,000 lines and [number of tasks] = 4, then there will be 4 tasks, each containing 2,500 lines of input data.
4. How to run mc_symphony
1) Make sure you did step 1) in section 3.
2) Uncompress the bs_symphony package, in ${HOME}/SymphonyDE/5.0/
3) Build the application with following commands;
>> cd ${HOME}/SymphonyDE/5.0
>> export QUANTLIB path_to_the_quanlib_library
>> make
4) In the directory ${HOME}/SymphonyDE/5.0/mc_symphony/output/, compress the service executable file and deploy the compressed file with the following commands;
>> tar cvf service.tar service
>> gzip service.tar
>> soamdeploy add MonteCarloServicePkg -p service.tar.gz -c /MonteCarlo
5) In the directory ${HOME}/SymphonyDE/5.0/mc_symphony/, create the application profile, mc.xml.
>> soamreg ${HOME}/SymphonyDE/5.0/mc_symphony/mc.xml
6) Confirm the registration by running the following command;
>> soamview app
Verify that the application, MonteCarlo, is enabled.
7) Now you can run the client of new Symphony application, MonteCarlo (mc_symphony), in the directory ${HOME}/SymphonyDE/5.0/bs_symphony/output/ with:
>> ./client
Note: The program will prompt the user for the following parameters: strike price, dividend, risk free rate, volatility. Once all parameters are entered, the client passes the input parameters to the Monte-Carlo engine in the Symphony service and the service will return the result. The user is then prompted for a new set of values. To exit from the program press enter entering an empty line or press ctrl^D.
Example:
>> ./client
connection ID=85ed12c6-ffff-ffff-c000-00096be63153-3033787312-7879
Session ID:104
value of underlying = 42.5
strike_price = 42.5
dividend = 0.8
risk free rate = 0.1
volatility = 0.239
Computing.....
The option discounted value is 3.8345
done
5. Performance implication
Note that bs_symphony is slightly different from mc_symphony in terms of client interface. It takes multiple sets of inputs and creates tasks in larger chunks, because sending small tasks one by one is less efficient due to the network overhead. You may control the size of a chunk by specifying the second argument, [number_of_tasks] to the client command of bs_symphony, to find the optimal task granularity.
6. Acknowledgement
Francesca Mariani (
fra_mariani@libero.it) and Francesco Zirilli (
f.zirilli@caspur.it) from CERI University of Roma have contributed to the implementation of samples.