Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions .github/workflows/quantlib-risks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# - OR pushes of tags starting with v*
# - OR manual dispatch on repo
# publishes to test pypi if:
# - in auto-differentiation/QuantLib-Risks-Py repository AND
# - in auto-differentiation/QuantLibAAD-Py repository AND
# - pushes of tags starting with v*
# - OR manual dispatch on repo
# publishes to real PyPI if:
# - publish to Test PyPI worked (with all build conditions above)
# - and if it's a version tag (starting with v*)
#
# cibuildwheel config: [tool.cibuildwheel] in pyproject.toml
# cibuildwheel config: [tool.cibuildwheel] in pyproject.toml; shim/ is built alongside

name: QuantLib-Risks wheels
name: QuantLibAAD wheels
on:
pull_request:
branches:
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
- name: Upload wheels
uses: actions/upload-artifact@v7
with:
name: cibw-wheels-${{ matrix.platform.name }}-${{ matrix.python }}
name: dist-wheels-${{ matrix.platform.name }}-${{ matrix.python }}
path: ./wheelhouse/*.whl
if-no-files-found: error

Expand All @@ -110,26 +110,44 @@ jobs:
- name: Upload sdist
uses: actions/upload-artifact@v7
with:
name: cibw-sdist
name: dist-sdist
path: dist/*.tar.gz
if-no-files-found: error

build_shim:
name: QuantLib-Risks shim
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Build sdist and wheel
run: pipx run build --outdir dist shim
- name: Check metadata
run: pipx run twine check --strict dist/*
- name: Upload shim
uses: actions/upload-artifact@v7
with:
name: dist-shim
path: dist/*
if-no-files-found: error

test-publish:
needs: [build_wheels, build_sdist]
needs: [build_wheels, build_sdist, build_shim]
if: >-
github.repository == 'auto-differentiation/QuantLib-Risks-Py' &&
github.repository == 'auto-differentiation/QuantLibAAD-Py' &&
(github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')))
environment:
name: testpypi
url: https://test.pypi.org/p/QuantLib-Risks
url: https://test.pypi.org/p/QuantLibAAD
permissions:
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v8
with:
pattern: cibw-*
pattern: dist-*
path: dist
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@v1.14.3
Expand All @@ -145,13 +163,13 @@ jobs:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
environment:
name: pypi
url: https://pypi.org/p/QuantLib-Risks
url: https://pypi.org/p/QuantLibAAD
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v8
with:
pattern: cibw-*
pattern: dist-*
path: dist
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@v1.14.3
Expand Down
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# ChangeLog

This log is to be read in conjunction with [ChangeLog.txt](./ChangeLog.txt).
It lists the QuantLib-Risks specific changes on top of what is already listed in
It lists the QuantLibAAD (formerly QuantLib-Risks) specific changes on top of what is already listed in
the underlying QuantLib-SWIG changelog.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.41.0] - Unreleased

- Renamed QuantLib-Risks -> QuantLibAAD: `pip install QuantLibAAD`, `import QuantLibAAD`
- `QuantLib-Risks` 1.41.0 is a deprecated shim (`shim/`) that requires `QuantLibAAD==1.41.*` and
re-exports it as `QuantLib_Risks` with a `DeprecationWarning`
- Anyone pinned to `QuantLib-Risks==1.33.3` must also pin `xad<2`
- Matches QuantLib and QuantLib Python bindings version 1.41
- Builds against QuantLibAAD 1.41 (formerly QuantLib-Risks-Cpp) and the shared libxad of the installed xad 2.2 package (`xad>=2.2,<2.3`), which is not bundled
- Tapes are shared with xad through libxad, thread-local per Python thread; QuantLib no longer patches `xad.adj_1st.Tape`
- Tapes are shared with xad through libxad, thread-local per Python thread
- Builds the unmodified QuantLib 1.41 release, no QuantLib patches
- One-step build with scikit-build-core; wheels for Python 3.10-3.14 on Linux, macOS and Windows
- `tools/sync-swig.sh` syncs `SWIG/` with a QuantLib-SWIG release, re-applying the XAD changes in `SWIG/patches/`
Expand All @@ -32,7 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Initial release, matching QuantLib Python bindings version 1.33


[1.41.0]: https://github.com/auto-differentiation/QuantLib-Risks-Py/compare/v1.33.3...v1.41.0
[1.41.0]: https://github.com/auto-differentiation/QuantLibAAD-Py/compare/v1.33.3...v1.41.0

[1.33.3]: https://github.com/auto-differentiation/QuantLib-Risks-Py/compare/v1.33.2...v1.33.3

Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
##############################################################################
# CMake file for QuantLib-Risks, driven by scikit-build-core (pyproject.toml).
# CMake file for QuantLibAAD, driven by scikit-build-core (pyproject.toml).
# Keep the version in sync with pyproject.toml.
#
# This file is part of QuantLib-Risks, a Python wrapper for QuantLib enabled
# This file is part of QuantLibAAD, a Python wrapper for QuantLib enabled
# for risk computation using automatic differentiation. It uses XAD,
# a fast and comprehensive C++ library for automatic differentiation.
#
Expand All @@ -24,7 +24,7 @@
##############################################################################

cmake_minimum_required(VERSION 3.18...4.2)
project(QuantLib_Risks LANGUAGES CXX VERSION 1.41.0)
project(QuantLibAAD_Py LANGUAGES CXX VERSION 1.41.0)

set(QLR_VERSION ${PROJECT_VERSION})
set(QLR_HEX_VERSION "0x014100f0")
Expand Down
13 changes: 8 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Note that this fork is importing all changes from the QuantLib-SWIG repository o
release. Changes related to QuantLib's own Python bindings will be included in each new
release.
Contributions to this repository should only be made if they are related to building
the Python bindings for QuantLib-Risks (enabled with XAD).
the Python bindings for QuantLibAAD (enabled with XAD).

1. Fork, then clone the repository with its submodules:

```bash
git clone --recurse-submodules https://github.com/yourusername/QuantLib-Risks-Py.git
git clone --recurse-submodules https://github.com/yourusername/QuantLibAAD-Py.git
```

2. Follow the [Build Instructions](#build-instructions) below to build the software.
Expand Down Expand Up @@ -54,7 +54,7 @@ The package is built in one step by [scikit-build-core](https://scikit-build-cor
(see `pyproject.toml`): CMake builds QuantLib as a static library together with
[QuantLibAAD](https://github.com/auto-differentiation/QuantLibAAD) from the `lib/` submodules,
against [XAD](https://github.com/auto-differentiation/xad) from the installed
[xad](https://pypi.org/project/xad/) package (`xad.get_cmake_dir()`), then the SWIG module from `SWIG/` and `Python/QuantLib_Risks/`.
[xad](https://pypi.org/project/xad/) package (`xad.get_cmake_dir()`), then the SWIG module from `SWIG/` and `Python/QuantLibAAD/`.

Requirements: Python 3.10+, and a C++17 compiler.
CMake, Ninja and SWIG are installed as build dependencies.
Expand All @@ -67,7 +67,7 @@ python -m venv .venv
source .venv/bin/activate
pip install -v . pytest
# run the tests from outside the source tree, against the installed package
cd /tmp && python -m pytest --import-mode=importlib /path/to/QuantLib-Risks-Py/Python/test
cd /tmp && python -m pytest --import-mode=importlib /path/to/QuantLibAAD-Py/Python/test
```

Notes:
Expand All @@ -88,8 +88,11 @@ Notes:
- Wheels for all supported Python versions are built with
[cibuildwheel](https://cibuildwheel.pypa.io) (`pipx run cibuildwheel`, configured in
`pyproject.toml`), the source distribution with `pipx run build --sdist`.
- `shim/` is the pure-Python `QuantLib-Risks` distribution, a deprecated alias that requires
`QuantLibAAD` and re-exports it as `QuantLib_Risks`. Build it with `pipx run build shim`
and keep its version and `QuantLibAAD` requirement in sync with `pyproject.toml`.


[pr]: https://github.com/auto-differentiation/QuantLib-Risks/compare/
[pr]: https://github.com/auto-differentiation/QuantLibAAD-Py/compare/

[cla]: https://gist.github.com/auto-differentiation-dev/5c6121c3f341e2de710fa034e9ff3263
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# License Terms

QuantLib-Risks is published under the AGPL, version 3, with the terms
QuantLibAAD is published under the AGPL, version 3, with the terms
[given below](#gnu-affero-general-public-license).

It contains code from [QuantLib](https://www.quantlib.org)
and is based on [QuantLib-SWIG](https://github.com/lballabio/QuantLib-SWIG),
which are shipped with a different (compatible) license.
The license terms for these packages [are given below](#quantlib-swig-license).

## QuantLib-Risks License
## QuantLibAAD License

### GNU AFFERO GENERAL PUBLIC LICENSE

Expand Down
4 changes: 2 additions & 2 deletions Python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##############################################################################
# Main CMake file for the Python extension.
#
# This file is part of QuantLib-Risks, a Python wrapper for QuantLib enabled
# This file is part of QuantLibAAD, a Python wrapper for QuantLib enabled
# for risk computation using automatic differentiation. It uses XAD,
# a fast and comprehensive C++ library for automatic differentiation.
#
Expand Down Expand Up @@ -30,4 +30,4 @@ include(UseSWIG)
set(PYBIND11_FINDPYTHON ON)
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/pybind11 ${CMAKE_BINARY_DIR}/pybind11)

add_subdirectory(QuantLib_Risks)
add_subdirectory(QuantLibAAD)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##############################################################################
# Build and install the SWIG binary module and the Python package.
#
# This file is part of QuantLib-Risks, a Python wrapper for QuantLib enabled
# This file is part of QuantLibAAD, a Python wrapper for QuantLib enabled
# for risk computation using automatic differentiation. It uses XAD,
# a fast and comprehensive C++ library for automatic differentiation.
#
Expand Down Expand Up @@ -30,31 +30,36 @@ set_property(SOURCE ${QLR_SWIG_SOURCE} PROPERTY COMPILE_OPTIONS
-DQLR_VERSION=\"${QLR_VERSION}\"
-DQLR_HEX_VERSION=${QLR_HEX_VERSION})

# builds _QuantLib_Risks and generates QuantLib_Risks.py
swig_add_library(QuantLib_Risks
set_property(SOURCE ${QLR_SWIG_SOURCE} PROPERTY SWIG_MODULE_NAME QuantLibAAD)

# builds _QuantLibAAD and generates QuantLibAAD.py; the target name avoids a clash
# with the C++ QuantLibAAD target
swig_add_library(QuantLibAAD_Python
LANGUAGE python
OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${QLR_SWIG_SOURCE} converters.cpp)
target_link_libraries(QuantLib_Risks PRIVATE QuantLib::QuantLib XAD::xad pybind11::module)
target_compile_definitions(QuantLib_Risks PRIVATE
target_link_libraries(QuantLibAAD_Python PRIVATE QuantLib::QuantLib XAD::xad pybind11::module)
target_compile_definitions(QuantLibAAD_Python PRIVATE
QL_XAD=1
QLR_VERSION=\"${QLR_VERSION}\"
QLR_HEX_VERSION=${QLR_HEX_VERSION})
target_include_directories(QuantLib_Risks PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(QuantLib_Risks PROPERTIES SUFFIX "${PYTHON_MODULE_EXTENSION}")
target_include_directories(QuantLibAAD_Python PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(QuantLibAAD_Python PROPERTIES
OUTPUT_NAME QuantLibAAD
SUFFIX "${PYTHON_MODULE_EXTENSION}")
# libxad from the installed xad package (on Windows, importing xad adds its DLL directory)
if(APPLE)
set_target_properties(QuantLib_Risks PROPERTIES INSTALL_RPATH "@loader_path/../xad/lib")
set_target_properties(QuantLibAAD_Python PROPERTIES INSTALL_RPATH "@loader_path/../xad/lib")
elseif(UNIX)
set_target_properties(QuantLib_Risks PROPERTIES INSTALL_RPATH "$ORIGIN/../xad/lib")
set_target_properties(QuantLibAAD_Python PROPERTIES INSTALL_RPATH "$ORIGIN/../xad/lib")
endif()
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug|RelWithDebInfo")
pybind11_strip(QuantLib_Risks)
pybind11_strip(QuantLibAAD_Python)
endif()

get_property(QLR_SWIG_PY TARGET QuantLib_Risks PROPERTY SWIG_SUPPORT_FILES)
install(TARGETS QuantLib_Risks
LIBRARY DESTINATION QuantLib_Risks COMPONENT python
RUNTIME DESTINATION QuantLib_Risks COMPONENT python)
get_property(QLR_SWIG_PY TARGET QuantLibAAD_Python PROPERTY SWIG_SUPPORT_FILES)
install(TARGETS QuantLibAAD_Python
LIBRARY DESTINATION QuantLibAAD COMPONENT python
RUNTIME DESTINATION QuantLibAAD COMPONENT python)
install(FILES __init__.py ${QLR_SWIG_PY}
DESTINATION QuantLib_Risks COMPONENT python)
DESTINATION QuantLibAAD COMPONENT python)
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
Copyright (C) 2024 Xcelerit Computing Limited.

This file is part of QuantLib-Risks, a Python wrapper for QuantLib enabled
This file is part of QuantLibAAD, a Python wrapper for QuantLib enabled
for risk computation using automatic differentiation. It uses XAD,
a fast and comprehensive C++ library for automatic differentiation.

QuantLib-Risks and XAD are free software: you can redistribute it and/or modify
QuantLibAAD and XAD are free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

QuantLib-Risks is distributed in the hope that it will be useful,
QuantLibAAD is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
Expand All @@ -33,16 +33,16 @@

import xad # loads libxad, which the binary module links against

from .QuantLib_Risks import *
from .QuantLibAAD import *

if XAD_ENABLED:
from xad.adj_1st import Real, Tape
from typing import Union, Tuple, List

# as part of the input at the top, we'll have _QuantLib_Risks in scope
DoubleVector = _QuantLib_Risks.DoubleVector
DoublePairVector = _QuantLib_Risks.DoublePairVector
DoubleVectorVector = _QuantLib_Risks.DoubleVectorVector
# as part of the input at the top, we'll have _QuantLibAAD in scope
DoubleVector = _QuantLibAAD.DoubleVector
DoublePairVector = _QuantLibAAD.DoublePairVector
DoubleVectorVector = _QuantLibAAD.DoubleVectorVector

def Concentrating1dMesherPoint(
x1: Union[Real, float, int], x2: Union[Real, float, int], v: bool
Expand All @@ -54,16 +54,16 @@ def PairDoubleVector(
) -> Tuple[List[Real], List[Real]]:
return ([Real(x) for x in x1], [Real(x) for x in x2])

if hasattr(_QuantLib_Risks, "__version__"):
__version__ = _QuantLib_Risks.__version__
elif hasattr(_QuantLib_Risks.cvar, "__version__"):
__version__ = _QuantLib_Risks.cvar.__version__
if hasattr(_QuantLibAAD, "__version__"):
__version__ = _QuantLibAAD.__version__
elif hasattr(_QuantLibAAD.cvar, "__version__"):
__version__ = _QuantLibAAD.cvar.__version__
else:
print("Could not find __version__ attribute")

if hasattr(_QuantLib_Risks, "__hexversion__"):
__hexversion__ = _QuantLib_Risks.__hexversion__
elif hasattr(_QuantLib_Risks.cvar, "__hexversion__"):
__hexversion__ = _QuantLib_Risks.cvar.__hexversion__
if hasattr(_QuantLibAAD, "__hexversion__"):
__hexversion__ = _QuantLibAAD.__hexversion__
elif hasattr(_QuantLibAAD.cvar, "__hexversion__"):
__hexversion__ = _QuantLibAAD.cvar.__hexversion__
else:
print("Could not find __hexversion__ attribute")
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Type converters and checks for the SWIG interface, interacting with XAD's
* Pybind11 based bindings.
*
* This file is part of QuantLib-Risks, a Python wrapper for QuantLib enabled
* This file is part of QuantLibAAD, a Python wrapper for QuantLib enabled
* for risk computation using automatic differentiation. It uses XAD,
* a fast and comprehensive C++ library for automatic differentiation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Type converters and checks for the SWIG interface, interacting with XAD's
* Pybind11 based bindings.
*
* This file is part of QuantLib-Risks, a Python wrapper for QuantLib enabled
* This file is part of QuantLibAAD, a Python wrapper for QuantLib enabled
* for risk computation using automatic differentiation. It uses XAD,
* a fast and comprehensive C++ library for automatic differentiation.
*
Expand Down
Loading
Loading