+ Reply to Thread
Results 1 to 8 of 8

Thread: Simple option pricing applications using Symphony and QuantLib

  1. #1
    Young's Avatar
    Young is offline Junior Member
    Join Date
    March 5th, 2008
    Location
    Toronto, Canada
    Posts
    58
    Blog Entries
    1
    Downloads
    7
    Uploads
    0

    Default Simple option pricing applications using Symphony and QuantLib

    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.
    Attached Files
    Last edited by vbseo; November 19th, 2009 at 03:04 AM.

  2. #2
    alexsahu is offline Junior Member
    Join Date
    August 5th, 2008
    Posts
    1
    Downloads
    19
    Uploads
    0

    Default

    thank you to young for posting this thread
    i am a high school student, currently working at the university of alberta
    for my thesis (IB Extended Essay) i chose to develop a simple options pricing model
    and it looks like if i implement symphony, quantlib, and boost i will have some success

    i do have background in C++, so i should be able to work with this code

    do you think i am going about this the right way, or i have i misunderstood something?

  3. #3
    f.zirilli is offline Junior Member
    Join Date
    May 16th, 2008
    Posts
    6
    Downloads
    0
    Uploads
    0

    Default Trouble Building Sample

    Below some facts and a request for your help.

    Facts:
    1 the bs_symphony available in the Forum for Symphony DE done by Young has been downloaded and compiled in the Symphony DE 4.0 environment installed by David on the ENEA lin4p machines,
    2 the client and service make files of bs_symphony give some compilation errors,
    3 the MyMessage.Cpp and the MyMessage.h files of the Symphony DE 4.0 and of the Symphony 3.0 are different and incompatible.Is this the way it should be?

    Help:
    1 can you give us a version of the work of Young that works in the Symphony DE 4.0 environment installed by David on the ENEA machines ?

    Thank you very much for your help.
    Regards
    Francesco

  4. #4
    Ajith's Avatar
    Ajith is offline Symphony DE Moderator
    Join Date
    February 28th, 2008
    Location
    Markham, Ontario
    Posts
    108
    Blog Entries
    2
    Downloads
    10
    Uploads
    0

    Default Trying Sample

    Quote Originally Posted by alexsahu View Post
    thank you to young for posting this thread
    i am a high school student, currently working at the university of alberta
    for my thesis (IB Extended Essay) i chose to develop a simple options pricing model
    and it looks like if i implement symphony, quantlib, and boost i will have some success

    i do have background in C++, so i should be able to work with this code

    do you think i am going about this the right way, or i have i misunderstood something?
    Hi Alexsahu,

    If you are familiar with coding in C++ and have Windows or a Supported Linux version, then you should have no trouble building our sample.

    If you are just interested in creating an option pricing model, start with Quantlib and see whether you can implement what you want with it. Check the Quantlib community forums for more information about it; Nabble - QuantLib forum

    Symphony will grid-enable Quantlib. This means that if you have 1000's of sets of parameters you want calculated, Symphony will run those calculations in parallel and give you a result faster than running all those calculations on one machine. This project is still in progress, so we still need to do some optimizations to make Quantlib run well on Symphony.

    - Ajith

  5. #5
    Ajith's Avatar
    Ajith is offline Symphony DE Moderator
    Join Date
    February 28th, 2008
    Location
    Markham, Ontario
    Posts
    108
    Blog Entries
    2
    Downloads
    10
    Uploads
    0

    Default Building Sample

    Quote Originally Posted by f.zirilli View Post
    Below some facts and a request for your help.

    Facts:
    1 the bs_symphony available in the Forum for Symphony DE done by Young has been downloaded and compiled in the Symphony DE 4.0 environment installed by David on the ENEA lin4p machines,
    2 the client and service make files of bs_symphony give some compilation errors,
    3 the MyMessage.Cpp and the MyMessage.h files of the Symphony DE 4.0 and of the Symphony 3.0 are different and incompatible.Is this the way it should be?

    Help:
    1 can you give us a version of the work of Young that works in the Symphony DE 4.0 environment installed by David on the ENEA machines ?

    Thank you very much for your help.
    Regards
    Francesco
    Hi Francesco,

    MyMessage.cpp may change, but according to our SDK expert, you should be able to use your 3.0 code with the 3.0 MyMessage and 4.0 code with the 4.0 MyMessage. Just don't mix them up.

    Are you just trying to build Young's sample with no changes? This should work. Can you send me the compile errors?

    Note: Make sure that the TOP variable in each Makefile points to your $SOAM_HOME/4.0 directory.

    - Ajith
    Last edited by admin_soam; August 11th, 2008 at 08:29 PM.

  6. #6
    f.zirilli is offline Junior Member
    Join Date
    May 16th, 2008
    Posts
    6
    Downloads
    0
    Uploads
    0

    Default vanillaDE: a Symphony enabled version of QuantLib Vanilla Option Engine

    The archive vanillaDE.zip contains a Symphony DE 4.0 application named vanillaDE that computes
    the modules of the Vanilla Option Engine of the library QuantLib 0.9.0.

    In particular 25 functions are implemented:

    01. Black-Scholes
    02. Barone-Adesi/Whaley
    03. Bierksund/Stensland
    04. Integral
    05. Finite Differences
    06. Binomial Jarrow-Rudd
    07. Binomial Cox-Ross-Rubistein
    08. Binomial equiprobabilities
    09. Binomial Trigeorgis
    10. Binomial Tian
    11. Binomial Leisen-Reimer
    12. Binomial Joshi
    13. MC (crude)
    14. QMC (Sobol)
    15. MC (Longstaff Svhwartz)
    16. Digital payoff
    17. Discrete dividends
    18. Bates
    19. Ju
    20. FD for dividend options
    21. Heston
    22. Black-Scholes with Hull-White
    23. Heston with Hull-White
    24. MC (crude) Heston
    25. QMC (Sobol) Heston

    The vanillaDE application reads the input data from a file and writes the results on a file named result.txt and
    on the video.

    We provide two files: template_data.txt and example.txt

    a) template_data.txt explains how the user must provide the input data according with the module number (i.e.: 01 (Black Scholes), 02 (Barone Adesi/Whaley,
    ...,25 (QMC (Sobol) Heston)).

    b) example.txt is an input file that contains a test case for each set of input parameters required by the modules.


    Remind that in order to generate the executable version of vanillaDE the user must run the makefile contained in the directories: mathlib, common, service, client.


    Note that in the makefile contained in the directory mathlib the user must change two paths that refer to
    the QuantLib-0.9.0.a:

    LIBF2C = insert the path to /lib/libQuantLib-0.9.0.a

    and that refer to the boost:

    $(G++) -I insert path to Quantlib --> /include -I insert path to boost --> /boost/include/boost-1_33_1 -c EquityOption1.cpp



    Note that in the makefile contained in the directory service the user must change a path that refers to the QuantLib-0.9.0.a:

    MATT= insert the path to /lib/libQuantLib-0.9.0.a

    Regards
    Francesco
    Attached Files

  7. #7
    f.zirilli is offline Junior Member
    Join Date
    May 16th, 2008
    Posts
    6
    Downloads
    0
    Uploads
    0

    Default Option Engine

    We have completed the Symphony enabled Option Engine derived from the Vanilla Option Engines of the software library of QuantLib (QuantLib 0.9.7). The file OptionEngine.zip contains the Symphony enabled Option Engine. In the subdirectory named output we provide a file “example.txt” to test all the 27 routines of the Option Engine. Note that the previous version of the Symphony enabled Option Engine was made of 25 routines.
    Note that the makefiles of the directories “mathlib” and “service” should be updated to define the correct paths.

    The main results obtained are:
    1) the integration in QuantLib of the mathematical software implementing the methods developed by the research team lead by Francesco Zirilli to price variance options (see www.econ.univpm.it/recchioni/finance/w4/) and to price barrier options (see www.econ.univpm.it/recchioni/w3/)
    2) the integration of the QuantLib version 0.9.7 of the software mentioned in 1) in the already available Symphony enabled Option Engine.

    The work in mathematical finance of the authors of the routines mentioned above and of their coworkers in summarized in the website: www.econ.univpm.it/recchioni/finance/ .
    Attached Files

  8. #8
    f.zirilli is offline Junior Member
    Join Date
    May 16th, 2008
    Posts
    6
    Downloads
    0
    Uploads
    0

    Default Option Engine continued

    We discuss some difficulties encountered in the realization of the software package Option Engine and the way these difficulties have been solved. Option Engine implements 27 modules of the QuantLib software library in a grid environment consisting in the Platform Symphony Enterprise Grid package. Moreover we show with an example that computing n modules of the Option Engine software package on a computing grid in the Symphony environment is computationally more efficient than computing the same modules in the LSF environment (for example using a “job-array” instruction). Let us recall that the Option Engine package consists of the following modules:
    01. Black-Scholes
    02. Barone-Adesi/Whaley
    03. Bierksund/Stensland
    04. Integral
    05. Finite Differences
    06. Binomial Jarrow-Rudd
    07. Binomial Cox-Ross-Rubistein
    08. Binomial equiprobabilities
    09. Binomial Trigeorgis
    10. Binomial Tian
    11. Binomial Leisen-Reimer
    12. Binomial Joshi
    13. MC (crude)
    14. QMC (Sobol)
    15. MC (Longstaff Schwartz)
    16. Digital payoff
    17. Discrete dividends
    18. Bates
    19. Ju
    20. FD for dividend options
    21. Heston
    22. Black-Scholes with Hull-White
    23. Heston with Hull-White
    24. MC (crude) Heston
    25. QMC (Sobol) Heston
    26. Heston Variance Option
    27. Perturbative Barrier Option

    A reference for the first 25 modules can be found in QuantLib: Vanilla option engines, a reference for the 26th module can be found in
    QuantLib: IntegralHestonVarianceOptionEngine Class Reference and finally a reference for the 27th module can be found in QuantLib: PerturbativeBarrierOptionEngine Class Reference

    The website Two Symphony Applications in Finance: the Black Scholes formula (bs_symphony) and a Monte Carlo engine (mc_symphony)* contains a detailed description of the Option Engine project. The Option Engine software package can be downloaded from this Forum or from the website Two Symphony Applications in Finance: the Black Scholes formula (bs_symphony) and a Monte Carlo engine (mc_symphony)* .


    DIFFICULTIES
    The development of the Option Engine package has implied: a) the integration of the algorithms that price variance options (module 26) and barrier options with time dependent parameters (module 27) in the Quantlib library and b) the enabling of the 27 modules of the new release of QuantLib under Symphony DE 4.0 environment. The enabled modules can read data from a file and can provide their output on video and on file.
    Some difficulties encountered in pursuing the realization of the Option Engine package are listed below.

    (i-1) The Fortran codes that price variance options in the Heston model framework available in the web-site www.econ.univpm.it/recchioni/finance/w4 and the Fortran code that prices barrier options in the time dependent Black Scholes framework available in the web-site www.econ.univpm.it/recchioni/w3/ have been translated in C++ language to be integrated in QuantLib.
    The main difficulty of the translation work has been the correct implementation of the input operations. In fact the input parameters in QuantLib must be introduced using suitable QuantLib functions. Furthermore the C++ codes implemented (variance options and barrier options) require user supplied functions and these input functions must be introduced as input data. This difficulty has been overcome introducing example codes to run these routines. These example codes are available in the test-suite of QuantLib in the web-site: https://quantlib.svn.sourceforge.net...Lib/test-suite.
    Thank to the work of QuantLib developers the C++ codes resulting from the translation have been integrated in the repository of QuantLib and are available in the website: https://quantlib.svn.sourceforge.net...l/experimental.
    These codes have been tested before being integrated in the new release of the QuantLib library.

    (i-2) The test of the C++ routines for pricing variance options and barrier options as members of the repository of QuantLib has not been an easy task since we had to run the routines with a QuantLib library subversion. This last fact implied that some modifications of the varianceoption.cpp and of the barrieroption.cpp files were necessary because of some troubles with the boost and with some auxiliary QuantLib routines (i.e. FlatRate).

    (i-3) We made Symphony enabled the 25 routines of the Vanilla Option Engine of QuantLib in Symphony DE 4.0 environment. These are the modules 01, 02,…,25 of the Option Engine package. This application reads the input parameters from a file and produces an output file. The reading from a file makes the structure of the file client.cpp independent of the particular module considered simplifying the Symphony enabling procedure of scientific modules. In this phase the main difficulty was the comprehension of the Symphony DE approach to the input/output operations and the realization of the new client.cpp and service.cpp files.

    (i-4) Once available the latest version of QuantLib (version 0.9.7), we added to the 25 routines mentioned (i-3) the two new QuantLib routines (i.e.: modules 26 and 27) to realize the Symphony enabled Option Engine package. The main difficulty in the realization of the C++ code that calls the 27 routines has been the use of the QuantLib “DayCounter” subprogram since the Barrier Option module (module 27) uses a DayCounter different from the others QuantLib modules.
    The service.cpp application has been modified in order to introduce the output of these 27 routines both on a file, named “result.txt” and on video.


    PERFORMANCE
    We have compared the performance of Symphony with the performance of the LSF job array. The LSF job array is a LSF instruction able to submit simultaneously up to 1000 copies of the same code with different input data. This instruction allocates the jobs on the free processors following a sequential order, that is when one of the processors of the grid is free a job is allocated on it. Using the job array instruction no considerations are made about the computing load of the grid at the time when the jobs are submitted. An example of the job array instruction is:

    bsub –m hostname –J”name_we_want”[1-100] $PWD/nome_executable_file

    The previous instruction submits 100 copies of the executable file named “nome_executable_file”.

    Symphony is able to perform a smart allocation of the jobs to be executed thank to a preliminary study of the free resources of the grid and of the computing load present on the grid at the time when the jobs are submitted.

    The following results have been obtained using a Linux machine with 4 processors and kernel 2.4 with LSF system software.
    We have considered has computing load the computation of six or of twelve barrier option prices using module 27. The following tables show the results of a comparison between the results obtained using Symphony environment and the LSF environment.
    Note that the Symphony jobs and the LSF jobs are submitted at the same time.


    Table 1
    No code has to be inserted here.



    Table 2
    No code has to be inserted here.


    We note that the use of the Symphony package reduces the computing time of about 40 seconds in Table 1 and of about a minute in Table 2 that is we have a time reduction of 7.5 per cent and of 6 per cent respectively. This reduction effect increases when we use a larger number of processors. In this experiment Symphony is able to use immediately at least 50% of the resources at our disposal and to distribute suitably the computing load among the resources. On the contrary the distribution of the load in the job-array instruction is fixed a priori by the user that chooses the number and the order of the jobs to be executed and in our experience the job array instruction does not use at least 50% of the available resources as it is done by Symphony. Generally for the job array instruction this percentage is smaller than 50% and this fact probably is the reason of the difference between the execution times. The advantage of using Symphony increases when the computation to be executed, the computing grid used and the load present on the grid become more complex. Note that as shown in Table 1, 2 Symphony performance reduces when the number of tasks increases, in fact the margin for improving the allocation of the jobs on the computing resources reduces when the number of jobs increases due to the heavy load already present on the computing resources.
    Detailed instructions for the use of the Option Engine package can be found at the website: Two Symphony Applications in Finance: the Black Scholes formula (bs_symphony) and a Monte Carlo engine (mc_symphony)*.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts