Technical resources

How to get started
Avera AI

    This library provides high-performance components leveraging the hardware acceleration support and automatic differentiation of TensorFlow. The library will provide TensorFlow support for foundational mathematical methods, mid-level methods, and specific pricing models. The coverage is being expanded over the next few months. The library is structured along three tiers:

    3. Pricing methods and other quant finance specific utilities. Specific Pricing models (e.g Local Vol (LV), Stochastic Vol (SV), Stochastic Local Vol (SLV), Hull-White (HW)) and their calibration. Rate curve building, payoff descriptions and schedule generation.

    We aim for the library components to be easily accessible at each level. Each layer will be accompanied by many examples which can be run independently of higher level components.



    Note that library requires Python 3 and Tensorflow >= 2.1.


    pip3 install —upgrade tensorflow

    Then run

    pip3 install —upgrade tf-quant-finance

    You maybe also have to use the option —user .

    TensorFlow training

    If you are not familiar with TensorFlow, a good place to get started is with the following self-study introduction to TensorFlow notebooks:

    Development roadmap


    • Implementation of the following specific processes/models:
      • Brownian Motion
      • Geometric Brownian Motion
      • Ornstein-Uhlenbeck
      • Single factor Hull White model
      • Heston model
      • Local volatility model
      • Quadratic Local Vol model
      • SABR model
    • Copulas: Support for defining and sampling from copulas.
    • SABR model calibration:
      • Dupire local vol calibration.
      • SABR model calibration.


    The above links will open Jupyter Notebooks in Colab.


    We’re eager to collaborate with you! See for a guide on how to contribute. This project adheres to TensorFlow’s code of conduct. By participating, you are expected to uphold this code.



    Development dependencies

    This library has the following dependencies:

    • Bazel Python 3 (Bazel uses Python 3 by default)
    • TensorFlow nightly build (most functions should work with TensorFlow 2.1)
    • TensorFlow Probability nightly build
    • Numpy version 1.16 or higher
    • Attrs

    This library requires the Bazel build system. Please follow the Bazel installation instructions for your platform. You can install TensorFlow and related dependencies using the pip3 install command:

    pip3 install —upgrade tf-nightly tfp-nightly numpy==1.16.0 attrs
    Commonly used commands

    Clone the GitHub repository:

    git clone

    After you run

    cd tf_quant_finance


    bazel test tf_quant_finance/math/random_ops/sobol:sobol_test

    will run tests in .

    Tests will be run using the Python version 3. Please make sure that you can run import tensorflow in the Python 3 shell, otherwise tests might fail.

    Docker images

    The official TF Quant Finance Docker images are located in the container repository.

    Images are tagged using the GitHub release version. Images contain all development dependencies. See Dockerfile for details.

    You can pull the latest Docker image using

    sudo docker pull

    To start a TF Quant Finance container, use the following command:

    sudo docker run -it
    Building a custom pip package


    # sudo apt-get install bazel git python python-pip rsync # For Ubuntu. git clone cd tf-quant-finance bazel build :build_pip_pkg ./bazel-bin/build_pip_pkg artifacts pip install —user —upgrade artifacts/*.whl

    This is not an officially supported Google product. This library is under active development. Interfaces may change at any time.




    View source

    TensorFlow Quantitative Finance volatility surfaces and vanilla options.


    approximations module: Approximations to the black scholes formula.

    class ImpliedVolMethod: Implied volatility methods.

    binary_price(...): Computes the Black Scholes price for a batch of binary call or put options.

    brownian_bridge_double(...): Computes probability of not touching the barriers for a 1D Brownian Bridge.

    brownian_bridge_single(...): Computes proba of not touching the barrier for a 1D Brownian Bridge.

    implied_vol(...): Finds the implied volatilities of options under the Black Scholes model.

    implied_vol_approx(...): Approximates the implied vol using the Stefanica-Radiocic algorithm.

    implied_vol_newton(...): Computes implied volatilities from given call or put option prices.

    option_price(...): Computes the Black Scholes price for a batch of call or put options.

    option_price_binomial(...): Computes the BS price for a batch of European or American options.


    View source

    Experimental modules.


    dates module: Date-related utilities.

    instruments: module: Instruments.

    io module: Utilities to serialize and deserialize dictionaries of numpy arrays.

    lsm_algorithm module: LSM algorithm methods.


    View source

    TensorFlow Quantitative Finance general math functions.


    integration module: Numerical integration methods.

    interpolation module: Ops related to interpolation.

    optimizer module: Optimization methods.

    pde module: PDE solver methods.

    piecewise module: Piecewise utility functions.

    random module: Ops related to random or quasi random sampling.

    root_search module: Root search functions.

    segment_ops module: Element wise ops acting on segments of arrays.


    diff(...): Computes the difference between elements of an array at a regular interval.

    fwd_gradient(...): Computes forward mode gradient.

    gradients(...): Computes the gradients of func_or_y wrt to *xs.

    make_val_and_grad_fn(...): Function decorator to compute both function value and gradient.

    value_and_gradient(...): Computes f(*xs) and its gradients wrt to *xs.


    View source

    TensorFlow Quantitative Finance tools to build Diffusion Models.


    euler_sampling module: The Euler sampling method for ito processes.

    hull_white module: TensorFlow Quantitative Finance tools to build Hull White type models.


    class GenericItoProcess: Generic Ito process defined from a drift and volatility function.

    class GeometricBrownianMotion: Geometric Brownian Motion.

    class HestonModel: Heston Model with piecewise constant parameters.

    class ItoProcess: Interface for specifying Ito processes.

    class JoinedItoProcess: Join of Ito Processes with specified time dependent correlations.

    class MultivariateGeometricBrownianMotion: Multivariate Geometric Brownian Motion.


    View source

    Functions to handle rates.


    cashflows module: Collection of functions to compute properties of cashflows.

    constant_fwd module: Constant forward interpolation.

    forwards module: Collection of functions to compute properties of cashflows.

    hagan_west module: Hagan West algorithm for rate interpolation and bootstrapping.


    class SwapCurveBuilderResult: SwapCurveBuilderResult(times, rates, discount_factors, initial_rates, converged, failed, iterations, objective_value)


    swap_curve_bootstrap(...): Constructs the zero swap curve using bootstrap method.

    swap_curve_fit(...): Constructs the zero swap curve using optimization.

    Example Notebooks

    Examples demonstrating usage of TFF methods.

    In order to start the examples on Google Colab, please follow the link "Run in Google Colab" provided with the examples. To run the code without issues, connect to a GPU runtime (Runtime -> Change runtime type -> Choose GPU in Hardware accelerator section).

    AI Platform Notebooks instance was used to create the precomputed results (VM with 8 vCPUs and TESLA v100 GPU).

    List of examples:

    TensorFlow training
