Skip to main content

High-performance TensorFlow library for quantitative finance.

Project description

TF Quant Finance: TensorFlow based Quant Finance Library

Making TF Quant Finance working again: since the official repo has not been mantained for year and achieved, the following fork is making this library alive again. Feel free to contribute to the library fixing bugs and implementing new features.

Table of contents

  1. Introduction
  2. Installation
  3. TensorFlow training
  4. Development roadmap
  5. Examples
  6. Contributing
  7. Development
  8. Community
  9. Disclaimers
  10. License

Introduction

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:

  1. Foundational methods. Core mathematical methods - optimisation, interpolation, root finders, linear algebra, random and quasi-random number generation, etc.

  2. Mid-level methods. ODE & PDE solvers, Ito process framework, Diffusion Path Generators, Copula samplers etc.

  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 that can run independently of higher-level components.

Installation

The easiest way to get started with the library is via the pip package.

Note that the library requires Python 3.10 and Tensorflow >= 2.18.

First, please install the most recent version of TensorFlow by following the TensorFlow installation instructions. For example, you could install TensorFlow

pip3 install --upgrade tensorflow tf_keras

Then run

pip3 install --upgrade tf-q-finance

You maybe also have to use the option --user.

TensorFlow training

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

Development roadmap

We are working on expanding the coverage of the library. Areas under active development are:

  • Ito Processes: Framework for defining Ito processes. Includes methods for sampling paths from a process and for solving the associated backward Kolmogorov equation.
  • Implementation of the following specific processes/models:
    • Brownian Motion
    • Geometric Brownian Motion
    • Ornstein-Uhlenbeck
    • One-Factor Hull-White model
    • Heston model
    • Local volatility model.
    • Quadratic Local Vol model.
    • SABR model
  • Copulas: Support for defining and sampling from copulas.
  • Model Calibration:
    • Dupire local vol calibration.
    • SABR model calibration.
  • Rate curve fitting: Hagan-West algorithm for yield curve bootstrapping and the Monotone Convex interpolation scheme.
  • Support for dates, day-count conventions, holidays, etc.

Examples

See tf_quant_finance/examples/ for end-to-end examples. It includes tutorial notebooks such as:

The above links will open Jupyter Notebooks in Colab.

Contributing

We're eager to collaborate with you! See CONTRIBUTING.md 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

This section is for developers who want to contribute code to the library. If you are only interested in using the library, please follow the instructions in the Installation section.

Development dependencies

This library has the following dependencies:

  1. Python 3 (Bazel uses Python 3 by default)
  2. TensorFlow version >= 2.19
  3. TensorFlow Probability version >= 0.25.0
  4. Numpy version 2.1.3
  5. Attrs
  6. Dataclasses (not needed if your Python version >= 3.7)

You can install TensorFlow and related dependencies using the pip3 install command:

pip3 install --upgrade tf-nightly tensorflow-probability==0.12.1 numpy==1.21 attrs dataclasses

Commonly used commands

Clone the GitHub repository:

git clone https://github.com/paolodelia99/tf-quant-finance.git

After you run

cd tf_quant_finance

you can execute tests using the run_tests script in the scripts folder. For example,

source scripts/run_tests.sh

will run tests in sobol_test.py .

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

Building a custom pip package

The following commands will build custom pip package from source and install it:

# sudo apt-get install bazel git python python-pip rsync # For Ubuntu.
git clone https://github.com/paolodelia99/tf-quant-finance.git
cd tf-quant-finance
source scripts/build_wheel.sh # scripts/build_wheel.ps1 if you are on windows
pip install --user --upgrade dist/*.whl

Community

  1. GitHub repository: Report bugs or make feature requests.

  2. TensorFlow Blog: Stay up to date on content from the TensorFlow team and best articles from the community.

  3. TensorFlow Probability: This library will leverage methods from TensorFlow Probability (TFP).

License

This library is licensed under the Apache 2 license (see LICENSE). This library uses Sobol primitive polynomials and initial direction numbers which are licensed under the BSD license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tf_q_finance-0.0.1.dev35.tar.gz (538.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tf_q_finance-0.0.1.dev35-py3-none-any.whl (769.6 kB view details)

Uploaded Python 3

File details

Details for the file tf_q_finance-0.0.1.dev35.tar.gz.

File metadata

  • Download URL: tf_q_finance-0.0.1.dev35.tar.gz
  • Upload date:
  • Size: 538.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for tf_q_finance-0.0.1.dev35.tar.gz
Algorithm Hash digest
SHA256 9230f5a29a6c69b25ca60b476a4079d0ed61bcf27f1d5004817e5eff3fe793d8
MD5 f713c983ffd2ed6011debd397cdb79e2
BLAKE2b-256 3d161d83c2e03a176a636136f911067daeac412e6841d0ba6f9667d72761e481

See more details on using hashes here.

File details

Details for the file tf_q_finance-0.0.1.dev35-py3-none-any.whl.

File metadata

File hashes

Hashes for tf_q_finance-0.0.1.dev35-py3-none-any.whl
Algorithm Hash digest
SHA256 2714919942da3e779ff2e3a876617d3f79be2e42631382c6c9d6fb23da44f93f
MD5 2cb97669f9f5367a6ee5b302f6985aad
BLAKE2b-256 2bb1bfbb0498e7a25fbacfdaf211c9aeb33836ad8968a411982f7026bb476011

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page