QuantLib-SWIG Language Bindings

repository·master·Indexed 19 days ago

https://github.com/lballabio/quantlib-swig

Language bindings for the QuantLib quantitative finance framework, enabling the use of its modeling and risk management capabilities in Python, C#, Java, Scala, and R. Includes instructions for building wrappers from source, configuring environment variables for different platforms, and installing language-specific modules.

Tokens
1.6K
Snippets
12
Records
17
Agent score
64%

What's inside QuantLib-SWIG

  1. Overview of QuantLib-SWIG

    master

    QuantLib-SWIG provides language bindings for the QuantLib project, which is a comprehensive open-source software framework for quantitative finance (modeling, trading, and risk management).

    Currently, QuantLib-SWIG supports the following languages:

    • Python
    • C#
    • Java
    • Scala
    • R
  2. Use the QuantLib-Scala interface

    master
    The QuantLib-Scala interface is built upon the QuantLib-Java module. To use QuantLib in Scala, you should treat it as an extension of the Java bindings. For instructions on how to build the underlying module, refer to the README.txt file located in the Java/ directory of the repository.
  3. Build the QuantLib R bindings

    master

    The R interface to QuantLib is created using SWIG (Simplified Wrapper and Interface Generator).

    Requirements:

    • SWIG version 1.3.32 is required.
    • Note: SWIG 1.3.31 generates QuantLib_wrap.R instead of QuantLib.R. If using 1.3.31, you must uncomment the relevant sections in Makefile.am and makeRData.R.

    Build Process: Run the make command to generate the following files:

    • QuantLib.so (the R library)
    • QuantLib_wrap.R (the wrapper script)
    • QuantLib.RData (the compiled wrapper)
    make
  4. Configure QuantLib environment for building

    master

    The build process requires that QuantLib headers and libraries are accessible to the compiler. Configuration varies by platform:

    Unix-like platforms

    • Ensure quantlib-config is in your PATH.
    • Use CXXFLAGS and LDFLAGS to set appropriate compiler and linker flags.
    • If Boost is required for compilation, set the INCLUDE environment variable to point to the Boost include directory.

    Windows

    • Define the QL_DIR environment variable pointing to your QuantLib directory (e.g., C:\Lib\QuantLib).
    • If you are building against a debug version of QuantLib and intend to debug the library from Python, set the QL_DEBUG environment variable to TRUE.
  5. Set up QuantLib-SWIG for Visual Studio .NET

    master

    To use the provided Visual Studio .NET projects, you must define an environment variable QL_DIR before launching the IDE. The value of QL_DIR must be the absolute path to your QuantLib installation directory.

    Example value: C:\Lib\QuantLib

    setx QL_DIR "C:\Lib\QuantLib"
  6. Install dependencies for QuantLib Python examples locally

    master

    To run the examples on your local machine, you must install the required Python modules. The dependency list is maintained in the requirements.txt file located in the binder folder at the root of the repository. Navigate to that directory and use pip to install them.

    pip install -r requirements.txt
  7. Load the compiled QuantLib R library

    master

    Once the library has been compiled using make, you can load it into your R session using the following sequence.

    Important: You must call cacheMetaData(1) after loading to work around a bug that prevents S4 methods from loading correctly.

    dyn.load('QuantLib.so')
    load('QuantLib.RData')
    cacheMetaData(1)
  8. Build the Java module on Linux

    master

    To build the Java bindings on a Linux system, you must provide the location of the JDK include directories during the configuration step. This allows the build system to locate the necessary Java headers.

    Follow these steps:

    1. Run ./autogen.sh to generate the configuration scripts.
    2. Run ./configure with the --with-jdk-include and --with-jdk-system-include flags pointing to your JDK installation.
    3. Run make to compile the module.
    ./autogen.sh
    ./configure --with-jdk-include=/usr/lib/jvm/java-1.5.0-sun-1.5.0.08/include \
      --with-jdk-system-include=usr/lib/jvm/java-1.5.0-sun-1.5.0.08/include/linux
    make
  9. Run QuantLib Python examples online with Binder

    master

    You can execute the QuantLib Python examples in an interactive environment without local installation by using Binder. Click the 'Launch Binder' badge in the repository to open the examples in a hosted Jupyter environment.

    https://mybinder.org/v2/gh/lballabio/QuantLib-SWIG/binder?urlpath=lab/tree/Python/examples
  10. Build QuantLib-SWIG interfaces for Linux or macOS

    master

    The .NET interfaces are compatible with Linux and macOS. To build them, navigate to the CSharp directory and execute the following sequence of commands after you have already completed the ./autogen.sh and ./configure steps in the main QuantLib-SWIG root directory:

    1. Run make in the CSharp directory.
    make