ISDA SIMM™ IN PYTHON

  • The Clarus Microservices API makes it very easy to compute ISDA SIMM™ from Python
  • The input data required is a CRIF file contain risk sensitivities
  • What-if trades can be easily added to determine the incremental change in margin
  • We provide a Sandbox within our API Reference page for you to try the API methods
  • Before moving to Python on your own computer

What is Python?

Python is an interpreted language with a design philosophy that emphasizes code readability and a syntax that expresses concepts in fewer lines of code than Java. It has become increasingly popular and there are many commonly used python packages for specific domains and tasks.

Trying out the API

We provide a Clarus python package to make it super convenient to call the Clarus API.

And our API Reference Page allows you to try in the browser, within a Sandbox environment.

First you need to register for a free trial account here. (Only for potential customers, no competitors please).

Then go to the Clarus API Reference Page, login and try out the examples below.

A Simple Example

To calculate SIMM for a single NDF trade, you just need to execute the following three lines:

import clarus
response = clarus.simm.margin(whatif='Buy 100m USDKRW 2m')
print (response)

Returning:

SIMM         Margin
Margin    7,900,000

Portfolio CRIF Files

ISDA SIMM specifies a Common Risk Interchange Format (CRIF) for the required risk factor sensitivity inputs to the SIMM calculation.

An extract of such as file for three counterparts is shown below:

ProductClass PortfolioID RiskType       Qualifier Bucket Label1 Label2  Amount       AmountCurrency AmountUSD
RatesFX      CptyA       Risk_IRCurve   USD       1      10y    Libor3m  "1,000,000" USD        "1,000,000"
RatesFX      CptyB       Risk_IRCurve   USD       1       5y    Libor1m "  -500,000" USD         "-500,000"
RatesFX      CptyC       Risk_IRCurve   USD       1       2y    OIS        "200,000" USD          "200,000"
RatesFX      CptyA       Risk_Inflation USD                                "-10,000" USD          "-10,000"
RatesFX      CptyB       Risk_IRCurve   EUR       1      10y    Libor3m   "-600,000" USD         "-600,000"
RatesFX      CptyC       Risk_IRCurve   EUR       1      20y    Libor3m     "50,000" USD           "50,000"
RatesFX      CptyA       Risk_Inflation GBP                                 "10,000" USD           "10,000"
RatesFX      CptyB       Risk_IRCurve   JPY       2       6m    Libor3m    "300,000" USD          "300,000"
RatesFX      CptyC       Risk_IRCurve   JPY       2       3m    Libor3m    "100,000" USD          "100,000"


And to work out which of these counterparts to do our NDF trade with,  we just need the following one line:

print (clarus.simm.margin(portfolios=clarus.read('CRIF.txt'), whatif='buy 100m USDKRW 2m'))

Returning:

SIMM          Account        WhatIf       Change         Margin
CptyA      44,982,458     7,900,000    2,743,077     47,725,535
CptyB      39,383,626     7,900,000    2,824,081     42,207,707
CptyC      11,049,380     7,900,000    4,170,195     15,219,575
Margin     95,415,464                  9,737,353    105,152,817

Showing the SIMM margin for our account with each Cpty before the trade, the WhatIf margin of the NDF trade by itself, the Change (+/-) that would result and the new Margin.

In this case trading with CptyC would increase the margin the most, while CptyA and CptyB have lower and similar changes. So if the price from each of these three counterparts is the same, then it would be optimal to trade with CptyA or CptyB as doing so would result in a lower funding cost of margin.

(A similar example is available in the Sandbox, in the file SIMMCalc.py, see Example 3)

Impact Grids

While it is super-easy to run whatIf requests for individual trades, it is often useful to pre-run a grid in standard risk sizes for the impact on our margin with each counterparty.

For interest rate risk, it is most convenient to specify this as product, currency, index, tenor and DV01.

The one line below will do this for USD Libor Swaps in 50k DV01 for the four major tenors.

print (clarus.simm.impact(portfolios=clarus.read('CRIF1.txt'), parSwapTenors='2Y,5Y,10Y,30Y'))

Returning:

Portfolio                  CptyA         CptyB          CptyC
 2Y  Pay 0050K DV01     1,834,182    -1,648,017     2,358,821
 2Y  Rcv 0050K DV01    -1,773,449     1,686,285    -2,309,760
 5Y  Pay 0050K DV01     2,138,494    -1,730,473     2,071,515
 5Y  Rcv 0050K DV01    -2,116,623     1,784,815    -1,959,617
10Y  Pay 0050K DV01     2,202,367    -1,567,388     1,735,091
10Y  Rcv 0050K DV01    -2,198,273     1,601,046    -1,567,247
30Y  Pay 0050K DV01     2,481,752    -1,692,578     1,791,044
30Y  Rcv 0050K DV01    -2,460,933     1,722,969    -1,466,055

Showing that received fixed swaps will reduce SIMM margin with CptyA and CptyC, while pay fixed will reduce SIMM margin with CptyB.

Also while each of these trades has the same 50K DV01 risk, with CptyA the longer tenors show a larger SIMM margin change, while for CptyC the opposite is true; suggesting a further preference in our trading for short tenors vs long tenors.

(See Example 6 in SIMMCalc.py )

SIMM Sensitivity

We expect firms to produce CRIF files from their own risk systems covering the trades with counterpartys with whom they have SIMM margin agreements in place. However we also provide a method to generate CRIF format risk sensitivities, as this can be useful for testing an internal system’s CRIF generation or for ad-hoc analysis purposes.

The one line below will do this for an NDF.

print (clarus.simm.sensitivity(trades='buy 200m BRLUSD 3.3 3m')

Returning:

RiskType  Qualifier Bucket Label1 Label2    Amount  AmountCurrency   AmountUSD  ProductClass   PortfolioID   ValuationDate
Risk_FX         BRL                      621827.71             USD   621827.71       RatesFX         Adhoc      2017-08-02
Risk_FX         USD                     -604190.85             USD  -604190.85       RatesFX         Adhoc      2017-08-02

(See Example 8 in SIMMCalc.py )

Ready for Python

The Sandbox is great for playing and trying out the API, however at some point you will want to move to running python code from your own computer.

Before doing so, you just need to to two things:

  1. Generate an API Key and Secret from the API Reference page menu item
  2. Install our python package, using the following from a command prompt.
pip install clarus

For an introduction and further details on installation and using, see Microservices for Absolute Beginners.

Invitation to Try

Thats it for today.

Thank you for reading to the end.

It just remains for me to invite you to register for the trial. (Standard caveats apply).

Calculate ISDA SIMM from Python.

Begin your journey to Microservices.

Stay informed with our FREE newsletter, subscribe here.