Creating a Dashboard for Margin Attribution

  • Clarus Microservices make it very easy to create Dashboards
  • Tables, Charts, Panels are easily created with python scripts
  • A complex portfolio analytic such as Margin Attribution is presented
  • Our Browser Sandbox allows you to try yourself

Introduction

Generally a firm will have a single margin account at a CCP, as this is most efficient for netting.

However it is very useful to attribute this margin internally to the owners of risk. For Initial margin this is not a simple task as unlike DV01, IM is not sub-additive, meaning that if I split the account into a number of parts and calculate IM for each part, the sum of these will usually be much higher than the account IM. (See Initial Margin Attribution).

Clarus provides the functionality to attribute IM by any dimension you require.

In this blog I will show you how easy it is to do this.

And to display the results in a simple to understand dashboard view.

Example 1: Margin Attribution by Strategy

Using Clarus Microservices we just need three lines of code to create an IM Attribution Dashboard.

strategy = clarus.margin.attribution(attributeBy='Strategy', portfolios='FCM-1/LCHTrd')
donut = ui.DonutChart(strategy.pivot('Strategy'), colFilter='Margin', excludeRows='Margin', title='By Strategy')
dashboard = ui.Dashboard(donut, style=ui.DarkStyle(), header='Margin Attribution by Strategy')

print(dashboard)

The first line calls the method margin.attribution for a portfolio that we have previously loaded and is referenced by the name FCM-1/LCHTrd and sets a parameter to attribute by Strategy.

The second line creates a Donut chart to which we pass the result of the first line and use parameters to choose rows/columns and set the title.

The third line creates the Dashboard using a dark style and sets the dashboard header.

Lastly, we print the dashboard, which shows:

As easy as that!

Strategy4 has the largest consumption of IM, followed by Strategy5.

Example 2: Margin Attribution by Trading Book

For our next example we will load trades from a csv file.

Clarus understands the common CCP report formats, so it is easy to take an LCH trade file and upload this. However as we want to attribute by a dimension that is not available in LCH files, in our case trading book, we need a mechanism to map trades to trading book.

First here is the code.

trading_book = clarus.margin.attribution(portfolios=clarus.read(['LCHSwapRegister.txt','LCHTradeX.csv']), attributeBy='TradingBook')

donut = ui.PieChart(trading_book.pivot('TradingBook'), excludeRows='Margin', colFilter='Margin', title='By TradingBook', colours='Greens')
dashboard = ui.Dashboard(donut, style=ui.LightStyle(), header='Margin Attribution by TradingBook')

print(dashboard)

In this example we use an LCH trade file and a TradeX file which is shown below.

An extract of the TradeX file is shown below.

XClearedTradeId,TradingBook,Strategy,Business
LCHH10000001,Book-A,Strategy-1,Treasury
LCHH10000002,Book-B,Strategy-2,Rates
LCHH10000003,Book-C,Strategy-3,Markets
LCHH10000004,Book-D,Strategy-4,Treasury
LCHH10000005,Book-A,Strategy-5,Rates
LCHH10000006,Book-B,Strategy-1,Markets
LCHH10000007,Book-C,Strategy-2,Treasury
LCHH10000008,Book-D,Strategy-3,Rates
LCHH10000009,Book-A,Strategy-4,Markets
LCHH10000010,Book-B,Strategy-5,Treasury

This maps each trade id to a trading book, strategy and business.

Looking at the code we see that the first line is the same as example 1, except that we use clarus.read[‘LCHSwapRegister.txt’,’LCHTradeX.csv’], to pass the contents of these files to the portfolios parameter.

The second line is as before, except the pivot and colours used.

The third line uses light style, instead of the dark in the first example.

Returning:

Thats it.

Book A and Book D have the largest consumption of IM.

Try it Yourself

It is really easy for you to try the above examples yourself.

First you need to register for a free trial account here.

(Only for potential customers, no vendors please).

When you have been authorised, login and try out the examples above.

Example 1 is available in our Sandbox under the menu PythonUI.

And you can upload your own files to create a custom dashboard.

All in a few lines of code.

Stay informed with our FREE newsletter, subscribe here.