GithubHelp home page GithubHelp logo

auto-differentiation / quantlib-risks-cpp Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 6.0 150 KB

Fast risks with QuantLib in C++

Home Page: https://auto-differentiation.github.io

CMake 4.66% C++ 95.34%
algorithmic-differentiation quantitative-finance risk-analysis

quantlib-risks-cpp's Introduction

QuantLib-Risks: QuantLib with XAD Automatic Differentiation in C++

GitHub Workflow Status PRs Welcome

As a demonstrator of integration of the XAD automatic differentiation tool with real-world code, the latest release of QuantLib can calculate risks with the help of XAD. The performance achieved on sample applications is many-fold superior to what has been reported previously with other tools. This demonstrates production quality use of the XAD library in a code-base of several hundred thousand lines.

This repository contains integration headers, examples, and tests required for this integration. It is not usable stand-alone.

Getting Started

For detailed build instructions with XAD and QuantLib, please refer to the XAD documentation site.

Getting Help

If you have found an issue, want to report a bug, or have a feature request, please raise a GitHub issue.

For general questions about XAD, sharing ideas, engaging with community members, etc, please use GitHub Discussions.

Contributing

Please read CONTRIBUTING for the process of contributing to this project. Please also obey our Code of Conduct in all communication.

Related Projects

  • XAD Comprehensive automatic differentiation in Python and C++
  • QuantLib-Risks: Fast risk evaluations in Python and C++

Planned Features

  • Gradually port more of the QuantLib tests and add AAD-based sensitivity calculation
  • Add more Examples

Authors

  • Various contributors from Xcelerit
  • See also the list of contributors who participated in the project.

License

Due to the nature of this repository, two different licenses have to be used for different part of the code-base. The tests and examples folders are containing code taken and modified from QuantLib where the QuantLib license applies. The ql folder contains adaptor modules for XAD, where the GNU AGPL applies. This is clearly indicated by having separate license files in each folder.

quantlib-risks-cpp's People

Contributors

auto-differentiation-dev avatar niallosullivan avatar xcelerit-squad avatar xcelerit-team avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

quantlib-risks-cpp's Issues

Fix linking user applications against installed QuantLib with XAD support

When building QuantLib with XAD support using this repository, the examples and tests inside the repository work fine. However, when installing QuantLib with CMake into a prefix and building a third-party application against this installation is currently broken.

The idea is that, after installing XAD-enabled QuantLib into a prefix in CMake's search path, the following should work in CMake:

find_package(QuantLib REQUIRED)
add_executable(my_user_application source1.cpp ...)
target_link_libraries(my_user_application PRIVATE QuantLib::QuantLib)

In order to fix this, the install exports here should be modified to:

  • also install XAD itself
  • import this XAD dependency in the installed targets file
  • import (or define) the quantlib-xad interface target
  • amend the QuantLib target that is already created by QuantLib itself with the extra link library quantlib-xad to get all the settings right

Failed to build with Quantlib CMAKE_CXX_STANDARD set to 20

CXX_STANDARD 14 and 17 builds fine, however with 20 I got the following error on Windows with VS2022 17.9.6:

>------ Build started: Configuration: windows-xad-msvc-release -------
  [1/862] Building CXX object ql\CMakeFiles\ql_library.dir\experimental\catbonds\catrisk.cpp.obj
  FAILED: ql/CMakeFiles/ql_library.dir/experimental/catbonds/catrisk.cpp.obj 
  "C:\PROGRA~1\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\bin\Hostx64\x64\cl.exe"  /nologo /TP -DBOOST_ALL_NO_LIB -DNOMINMAX -DQL_COMPILATION -DQL_INCLUDE_FIRST=ql/qlrisks.hpp -D_CRT_SECURE_NO_WARNINGS -D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING -ID:\QuantLib\build\windows-xad-msvc-release -ID:\QuantLib -ID:\QuantLib-Risks-Cpp\ql\.. -ID:\XAD\src -ID:\QuantLib\build\windows-xad-msvc-release\xad\src -external:IC:\Users\Administrator\source\repos\boost_1_84_0 -external:W0 /DWIN32 /D_WINDOWS /GR /EHsc /O2 /Ob2 /DNDEBUG -std:c++20 -MT -W3 /wd4267 /wd4819 /wd26812 /bigobj /showIncludes /Foql\CMakeFiles\ql_library.dir\experimental\catbonds\catrisk.cpp.obj /Fdql\CMakeFiles\ql_library.dir\ql_library.pdb /FS -c D:\QuantLib\ql\experimental\catbonds\catrisk.cpp
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3348): error C2665: 'sqrt': no overloaded function could convert all the argument types
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\cmath(530): note: could be 'long double sqrt(long double) noexcept'
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3348): note: 'long double sqrt(long double) noexcept': cannot convert argument 1 from 'xad::UnaryExpr<Scalar,xad::scalar_sub2_op<Scalar,int>,xad::UnaryExpr<Scalar,xad::scalar_prod_op<Scalar,QuantLib::Integer>,xad::ADVar<Scalar>>>' to 'long double'
          with
          [
              Scalar=double
          ]
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3348): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\cmath(264): note: or       'float sqrt(float) noexcept'
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3348): note: 'float sqrt(float) noexcept': cannot convert argument 1 from 'xad::UnaryExpr<Scalar,xad::scalar_sub2_op<Scalar,int>,xad::UnaryExpr<Scalar,xad::scalar_prod_op<Scalar,QuantLib::Integer>,xad::ADVar<Scalar>>>' to 'float'
          with
          [
              Scalar=double
          ]
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3348): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
  C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\corecrt_math.h(489): note: or       'double sqrt(double)'
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3348): note: 'double sqrt(double)': cannot convert argument 1 from 'xad::UnaryExpr<Scalar,xad::scalar_sub2_op<Scalar,int>,xad::UnaryExpr<Scalar,xad::scalar_prod_op<Scalar,QuantLib::Integer>,xad::ADVar<Scalar>>>' to 'double'
          with
          [
              Scalar=double
          ]
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3348): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\cmath(674): note: or       'double sqrt(_Ty) noexcept'
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3348): note: 'double sqrt(_Ty) noexcept': could not deduce template argument for '__formal'
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\cstddef(36): note: 'std::enable_if_t<false,int>' : Failed to specialize alias template
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3348): note: while trying to match the argument list '(xad::UnaryExpr<Scalar,xad::scalar_sub2_op<Scalar,int>,xad::UnaryExpr<Scalar,xad::scalar_prod_op<Scalar,QuantLib::Integer>,xad::ADVar<Scalar>>>)'
          with
          [
              Scalar=double
          ]
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3348): note: the template instantiation context (the oldest one first) is
  D:\QuantLib\ql/experimental/catbonds/catrisk.hpp(110): note: see reference to class template instantiation 'std::gamma_distribution<QuantLib::Real>' being compiled
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3311): note: while compiling class 'std::gamma_distribution<QuantLib::Real>::param_type'
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3342): note: while compiling class template member function 'void std::gamma_distribution<QuantLib::Real>::param_type::_Init(_Ty,_Ty) noexcept'
          with
          [
              _Ty=QuantLib::Real
          ]
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3319): note: see the first reference to 'std::gamma_distribution<QuantLib::Real>::param_type::_Init' in 'std::gamma_distribution<QuantLib::Real>::param_type::param_type'
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\random(3362): note: see the first reference to 'std::gamma_distribution<QuantLib::Real>::param_type::param_type' in 'std::gamma_distribution<QuantLib::Real>::gamma_distribution'
  D:\QuantLib\ql\experimental\catbonds\catrisk.cpp(84): note: see the first reference to 'std::gamma_distribution<QuantLib::Real>::gamma_distribution' in 'QuantLib::BetaRiskSimulation::BetaRiskSimulation'

Provide Python bindings for QuantLib with XAD

This should build on the standard QuantLib SWIG, extending it with XAD's tape and its methods as well as the new Real type (XAD active type). With this, Python users can calculate sensitivities of their code directly in Python.

The resulting package could then be published in PyPI for easy installation with pip.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.