Margin Attribution

Attribute initial margin to specified groups e.g. currency, book, trading division, strategy etc

Parameter Description Default Options
portfolios
Required
Input portfolios. Can be trades in QuickTrade, FPML5, LCH, CME or SDR format. Or risk sensitivities in CRIF, LCH or CME format. Or portfolioIds of previously loaded portfolios Or any combination of these
whatif
Optional
Whatif portfolios. Can be trades in QuickTrade, FPML5, LCH, CME or SDR format. Or risk sensitivities in CRIF, LCH or CME format. Or portfolioIds of previously loaded portfolios Or any combination of these
valueDate
Optional
The value date in YYYY-MM-DD format. 2024-12-13
model
Optional
Margin model to calculate with select CCP (CME or LCH) or SIMM - else Default will use the default CCP for the portfolio specified (e.g. CME for CME register). Compare will compare all models LCH LCH
attributeBy
Optional
The trade attribute to attribute by - can be an X attribute e.g. Book, Business, Strategy Currency
import clarus

response = clarus.margin.attribution(attributeBy='Book',portfolios='1H',model='LCH')
print (response)
import com.clarusft.api.model.margin.AttributionRequest
import com.clarusft.api.model.margin.AttributionResponse

ApiClient clarus = ApiClient.getDefault();
AttributionResponse response = clarus.request(new AttributionRequest().withAttributeBy("Book").withPortfolios("1H").withModel("LCH"));
System.out.println(response);
import Clarus

response = Clarus.Margin.attribution(attributeBy="Book",portfolios="1H",model="LCH")
print(response)

##
##Need to install packages once, if not already installed
##install.packages('httr')
##install.packages('readr')
##

library('httr')
##library('readr')

## Manually edit and set key/secret here ##
apiKey <- '...'
apiSecret <-'...'

request <- function(category, functionName, ...){
  restUrl  =  paste0('https://apieval.clarusft.com/api/rest/v1/', category, '/',functionName, '.csv')
  response <- POST(url=restUrl, body=list(...), encode='json', authenticate(apiKey, apiSecret, type='basic'))
  if (response$status_code!=200){
      stop(paste0('Request to ', category, '/', functionName, ' failed with status code: ', response$status_code))
  }
  return (response)
}

dataframe <- function(response){
  return (read.csv(text=content(response, 'text'), sep=',', head=TRUE))
}
## filename <- file.path('C:', 'Temp', 'myfile.csv')
## myvalue <- <- read_file(filename)

r <- request('margin', 'Attribution', attributeBy='Book', portfolios='1H', model='LCH')
df <- dataframe(r)
print (df)

import requests
import sys
import pandas
import io
#import os

# Example of REST API call to Clarus Microservices #

# Manually edit and set key/secret here #
apiKey = ''
apiSecret = ''

print (sys.version)

def request(category, functionName, **params):
  restUrl = 'https://apieval.clarusft.com/api/rest/v1/' + category + '/' + functionName + '.json'
  r = requests.post(restUrl, json=params, auth=(apiKey, apiSecret))
  r.raise_for_status()
  return r.json()

def dataframe(results):
  return pandas.DataFrame(results['results'])

# filename = os.path.join('C:\\', 'Temp', 'myfile.csv')
# myvalue = open(filename).read()

r = request('margin', 'Attribution', attributeBy='Book', portfolios='1H', model='LCH')
df = dataframe(r)
print(pandas.DataFrame.head(df))


use strict;
use warnings;
use MIME::Base64;
use JSON;
use REST::Client;

# Example of REST API call to Clarus Microservices #

my $client = REST::Client->new();
$client->addHeader('Content-Type', 'application/json');

# Manually edit and set key/secret here 
my $apiKey = '';
my $apiSecret = '';

my $encoded_auth = encode_base64("$apiKey:$apiSecret", '');
$client->addHeader('Authorization', "Basic $encoded_auth");

my %params = ('attributeBy' => 'Book','portfolios' => '1H','model' => 'LCH');

my $urlBase = 'https://apieval.clarusft.com/api/rest/v1/';
my $category = 'margin/';
my $name = 'Attribution';
my $outputFormat = '.csv'; #can also be '.json' or '.tsv'
my $fullRESTUrl  =  $urlBase . $category . $name . $outputFormat;

$client->POST($fullRESTUrl,encode_json(\%params));

print 'Response: ' . $client->responseContent() . "\n";
print 'Response status: ' . $client->responseCode() . "\n";


printf('Example of REST API call to Clarus Microservices\n');

function r = request(category, functionName, params)

# Manually edit and set key/secret here #
  apiKey = ''
  apiSecret = ''

  restUrl = ['https://' apiKey ":" apiSecret  "@" 'apieval.clarusft.com/api/rest/v1/' category '/' functionName '.csv'];
  [r, status, message] = urlread (restUrl, 'get', params);
  if (status!=1)
      error(['Failed on ' category '/' functionName ': ' message]);
  endif
end

function ca = toCellArray(csvStr)
  header_row = textscan (csvStr, "%s", 1, 'delimiter','\n');
  headers = strsplit(char(header_row), ",");
  numCols = size(headers)(2);
  format = repmat('%s ', [1 numCols]);
  ca = textscan (csvStr, format, 'delimiter',',', 'endofline',"\n");
end

params = {'attributeBy', 'Book', ...
          'portfolios', '1H', ...
          'model', 'LCH'}

r = request('margin', 'Attribution', params)
ca = toCellArray(r);

ca

Request Body

Submit to generate...
Response

Submit to generate...

{
  "portfolios" : "1H",
  "model" : "LCH",
  "attributeBy" : "Book"
}