quantra.io

A JSON API for QuantLib.

What is Quantra?

A JSON API for QuantLib.

Quantra's main features include:

  • Curve construction
  • Bond pricing
  • Option pricing
  • Interest Rate Swap pricing
  • Volatility surfaces
  • Financial calendars and dates
Go to API docs for more detail on the API. You can also check QuantLib's documentation for extensive details and examples on how to use the library's concepts www.quantlib.org/docs.shtml

Using the online API

To start using the API register and get an authorization token to use in your calls. Tokens expire after one hour. Log in and renew it once has expired.

Set your request authorization header with the token value.

Request example

Request example to price an option. cURL and Python examples.

curl -X POST \
  https://api.quantra.io/optionPricing \
  -H 'authorization: your_token_value' \
  -d '{
  "Option": {
    "Style": "European",
    "EuropeanOption": {
      "Type": "Call",
      "Underlying": 36,
      "Strike": 40,
      "Calendar": "TARGET",
      "Maturity": "1999/05/17",
      "Settlement": "1998/05/18",
      "DayCounter": "ActualActual",
      "RiskFreeRateTermStructure": "RiskFreeRateTermStructure",
      "DividendYieldTermStructure": "DividendYieldTermStructure"
    }
  },
  "Curves": [
    {
      "Id": "RiskFreeRateTermStructure",
      "FlatTermStructure": {
        "DayCounter": "ActualActual",
        "Rate": 0.06,
        "Date": "1999/05/15"
      }
    },
    {
      "Id": "DividendYieldTermStructure",
      "FlatTermStructure": {
        "DayCounter": "ActualActual",
        "Rate": 0.06,
        "Date": "1999/05/15"
      }
    }
  ],
  "Pricing": {
    "AsOfDate": "1999/05/14"
  },
  "VolTermStructure": {
    "Volatility": 0.2,
    "VolatilityType": "BlackConstantVol",
    "Calendar": "TARGET",
    "DayCounter": "ActualActual",
    "Date": "1999/05/14"
  }
}'

import requests

url = "https://api.quantra.io/optionPricing"

payload = "{
  "Option": {
    "Style": "European",
    "EuropeanOption": {
      "Type": "Call",
      "Underlying": 36,
      "Strike": 40,
      "Calendar": "TARGET",
      "Maturity": "1999/05/17",
      "Settlement": "1998/05/18",
      "DayCounter": "ActualActual",
      "RiskFreeRateTermStructure": "RiskFreeRateTermStructure",
      "DividendYieldTermStructure": "DividendYieldTermStructure"
    }
  },
  "Curves": [
    {
      "Id": "RiskFreeRateTermStructure",
      "FlatTermStructure": {
        "DayCounter": "ActualActual",
        "Rate": 0.06,
        "Date": "1999/05/15"
      }
    },
    {
      "Id": "DividendYieldTermStructure",
      "FlatTermStructure": {
        "DayCounter": "ActualActual",
        "Rate": 0.06,
        "Date": "1999/05/15"
      }
    }
  ],
  "Pricing": {
    "AsOfDate": "1999/05/14"
  },
  "VolTermStructure": {
    "Volatility": 0.2,
    "VolatilityType": "BlackConstantVol",
    "Calendar": "TARGET",
    "DayCounter": "ActualActual",
    "Date": "1999/05/14"
  }
}"
headers = {
    'content-type': "application/json",
    'authorization': "your_token_value",
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

Response

{
    "message": {
        "ThetaPerDay": -2.12926e-9,
        "StrikeSensitivity": -2.9443e-9,
        "Rho": 6.45326e-10,
        "DividendRho": -6.47238e-10,
        "Theta": -7.77179e-7,
        "Gamma": 2.99843e-8,
        "Vega": 6.38789e-8,
        "Delta": 3.28114e-9,
        "NPV": 3.48912e-10
    },
    "response": "ok"
}

Building quantra

Clone the repository from Github and create a Docker container or compile it from scratch.

A working example using quantra

Volatility surface and greeks from quantra

The sourcode for this example is available at GitHub

Google Sheets scripts

Use some quantra functionalites from Google Sheets with these scripts. Follow the instructions here on how to use custom functions.

About

Built by Josep Rubio Pique.

Send an email to josep@datag.es if you need something and feel free to open an issue in github if you would like to see more features or something is wrong.