After the futures and options deployable software has been downloaded, clients can start testing the workflow and generating margin responses. This topic includes the following sections related to Margin Software: 

Loading the Risk Parameter Files

Downloading Risk Parameter Files

Please note the deployable margin software version number is tightly coupled to the version of market data file the user selects to load. This user guide indicates compatible market data packages for a given build and how to run with limited backwards/historical file compatibility for SPAN RPFs.

Downloading Risk Parameter Files from Secure FTP

Users requiring access to SFTP for the first time or users requiring entitlements to an existing SFTP username, should contact PostTradeServices@cmegroup.com to request access. Please provide your existing SFTP username, if necessary.

Initializing RPF Data in Deployable Software

Best Practices for Using CME Risk Parameter Files

Limited Backwards Compatibility

Using the SPAN Over-ride Feature

Please note this workflow requires a user to supply a compatible SPAN only RPF file (i.e. cme.span.yyyymmdd.\[cycle\].zip) prior to starting the initialization process. More details regarding the SPAN RPF files can be found in 'Risk Parameter Files' above.

Redis RPF Load

(System.setProperty("cacheMode", "Redis") before initializing the deployable service.

Note: ‘Redis’ in the argument is case insensitive.

Local Redis Cache Load

 

Distributed Redis Cache Load

Please refer to the ExampleCacheLoad class located in the SDK.

Clearing the Redis Cache Load

Margin Request and Input Portfolio


Margin Call and Margin Request


Analyzing the Margin Response Message

Clearing the Redis Cache Load

Freezing a Point in Time and Using Add Market Data

Accessing the API: Best Practices

Appendix

Inputs

Inputs for an futures and options portfolio will contain data definitions for the Risk Portfolio Message. The
Risk Portfolio Message structure will be organized by categories (Header, Point In Time, Portfolio, Entities, Positions, and Instruments) and further detailed through a subset of attributes within each category. For the full list of attributes, please refer to the SPAN 2 Risk Analysis Framework document available in CME CORE or https://www.cmegroup.com/confluence/display/EPICSANDBOX/SPAN+2+Risk+Analysis+Framework.

Outputs

The Margin Results Message will be organized at various levels (Portfolio, CCP, POD, Product Group) and each level will contain further details for margin requirements, valuations, and sensitivities further broken down by currency when applicable. This structure will support results
for Futures and Options products margined through SPAN and SPAN 2 risk models. For the full
list of attributes and the full margin results data model, please refer to the SPAN 2 Risk Analysis Framework documentation available in CME CORE or }https://www.cmegroup.com/confluence/display/EPICSANDBOX/SPAN+2+Risk+Analysis+Framework+_.

Omnibus Combinations

OmnibusInd indicator defines the relationship between parent and child portfolios, here are possible combinations of account type, NetQty, NakedLong and NakedShort when Omnibus is equal to YES and NO.

AccountType

OmnibusInd

NetQty

NakedLong

NakedShort

SPECULATOR

YES

0/null

≥ 0/null

≥ 0/null

HEDGE

YES

0/null

≥ 0/null

≥ 0/null

SPECULATOR

NO

<>/null

0/null

0/null

HEDGE

NO

<>/null

0/null

0/null

MEMBER

NO

<>/null

0/null

0/null


If OmnibusInd is set to YES, then the final NetQty must either be 0 or null also the Naked Long must be null or non-negative and Naked Short must be null or non-negative. The account type must be either HEDGE or SPECULATOR.
If Omnibus is set to NO, then the final NetQty must not be null and Naked Short must be null or 0 and Naked long must be null or 0.
The following omnibus edge cases will return warning messages:

Errors List

Notes about errors:

Error Type

Error Code

Error Message

Portfolio Type

NO_PAYLOAD

ERR001

"Payload can't be null"

JSON

NO_TRADES_POSITIONS

ERR002

"No trades and/or positions provided"

JSON

INVALID_INPUTTYPE

ERR003

"Unsupported portfolio type supplied in inputType parameter: %s. Must be one of: %s"

CSV

INVALID_CSV_FORMAT

ERR004

"Issue whilst converting from csv format. See logs for more details"

CSV

MARGIN_CALCULATION_ERROR

ERR005

"Unable to process margin request, error during calculations: %s. Check logs for more information"

CSV

MARGIN_AGGREGATION_ERROR

ERR006

"%s"

N/A

NO_RPF_SUPPLIED

ERR007

"Unable to create the Analytics Service Implementation. No risk parameter file provided, or directory does not exist"

N/A

INVALID_RPF

ERR008

"Unable to properly initialize the risk analytics service. %s risk parameter file invalid: %s"

CSV

JSON

INVALID_POINT_IN_TIME

ERR009

Invalid Error

N/A

NO_RPF_FOR_POINT_IN_TIME

ERR010

"Portfolio %s of type %s cannot be margined because the supplied point in time %s does not match any loaded risk parameter file"

CSV

JSON

RPF_INCORRECT_FORMAT

ERR011

"Unable to determine cycle dates from %s – risk parameter file missing or in the wrong format. Check the
README in the rpfs folder in the sdk for information on the format for market data"

N/A

INVALID_PORTFOLIO

ERR012

"Position was ignored: internal SPAN exception while creation position"

CSV

INVALID_POSITION

ERR013

"Invalid position at line $d"

General error used for all semantic issues.

CSV

JSON

INVALID_SPAN_POSITION

ERR014

"Invalid position at line $d"

CSV

NO_MODULE_CONFIG_FOR_RPF

ERR015

"Unable to find configuration for provided risk parameter file: %"

N/A

CANNOT_BE_ENCODED

ERR016

"Unable to encode value"

N/A

INVALID_TRADE

ERR017

"Invalid trade at line $d"

CSV

JSON

NO_POINT_IN_TIME_SUPPLIED

ERR018

"No point in time supplied"

JSON

INVALID_TRANSACTION

ERR019

"Invalid transaction at line $d"

N/A

CANNOT_CONFIGURE_DIFFERENT_DATES

ERR020

"Issue when attempting to load different versions of risk library for different dates"

N/A

CANNOT_FIND_INSTRUMENT

ERR021

"Instrument does not exist"

N/A

UNABLE_TO_LOAD_CACHE

ERR022

"Unable to load cache %s"

N/A

FAILED_CREATE_RISK_DATA_READERS

ERR023

"Failed to create risk data readers for file in %s"

N/A

FAILED_TO_REFRESH_RPF

ERR024

"Failed to refresh/reload risk parameter file"

N/A

ERROR_IN_RL_MARGIN_CALCULATION

ERR025

"Error calculating margin for position/s, please contact CME"

N/A

INVALID_PORTFOLIO_CUSTOMER_ACCOUNT_TYPE

ERR026

"Invalid portfolio customer account type"

CSV

INVALID OMNIBUS

ERR100

"Invalid
netQty/nakedShortQty/nakedLongQty supplied for
parentPortfolio/omnibusIndicator combination

CSV

JSON

N/A

N/A

WARNING: Current configuration in RPF not compatible with deployable version. Overriding for backward compatibility.

N/A

Lower-Level Warnings and INFO Messages

Message Type

Message Code

Message Details

Portfolio Type

DUPLICATE_OMNIBUS_PARENT_ACCOUNT

WRN028

Duplicate omnibus parent account, aggregation may occur to this account

CSV

JSON

OMNIBUS_ACCOUNT_WITH_NO_POSITIONS_AND_NO_CHILDREN

WRN029

Omnibus account has no positions and no child accounts - margin response not returned

CSV

JSON

OMNIBUS_PARENT_ACCOUNT_NOT_FOUND_FOR_CHILD_ACCOUNT

INF030

No omnibus parent account found for child account

CSV

JSON

OMNIBUS_PARENT_ACCOUNT_HAS_NO_CHILDREN

INF031

No child accounts found for omnibus parent account

CSV

JSON

FAILED_TO_RETRIEVE_SPAN2_DATA_FROM_RPF

WRN032

Missing SPAN 2 product data in RPF. Check logs for more information

CSV

JSON

Error codes coming out of the converter:

Error Type

Error Code

Error Message

Portfolio Type

REQUEST_ID

ERR101

Invalid error

N/A

VERSION

ERR102

Invalid error

N/A

SENT_TIME

ERR103

Invalid error

N/A

BUSINESS_DATE

ERR104

"No point in time supplied"

JSON

CYCLE_CODE

ERR105

Invalid error

N/A

RUN_NUMBER

ERR106

Invalid error

N/A

PORTFOLIO_ID

ERR107

Invalid error

N/A

CURRENCY

ERR108

"Invalid value null in column currency: %s"

CSV

CUSTOMER_ACCOUNT_TYPE

ERR109

"Invalid value null in column customerAccountType: %s"

CSV

OMNIBUS_INDICATOR

ERR110

"Invalid netQty/nakedShortQty/nakedLongQty supplied for parentPORTFOLIO/omnibusIndicator combination"

CSV

PARENT_PORTFOLIO_ID

ERR111

Invalid error

N/A

CLEARING_ORGANIZATION_ID

ERR013

"Failed validation: No clearing organization id supplied: %s"

CSV

JSON

FIRM_ID

ERR013

"Failed validation: No firm id supplied: %s"

JSON

ACCOUNT_ID

ERR114

"Failed validation: No account id supplied: %s"

CSV

JSON

ACCOUNT_NAME

ERR013

Invalid error

N/A

ORIGIN_TYPE

ERR116

ERR013

"Invalid value null in column OrginType: %s"

"Failed validation: Orgin type has to be one of CUST, CUSTOMER, HOUS, HOUSE: %s"

CSV

JSON

ACCOUNT_TYPE

ERR117

Invalid error

N/A

SEGREGATION_TYPE

ERR118

Invalid Error

N/A

NET_QUANTITY

ERR013

"Failed validation: Final net quantity must not be 0 for non-omnibus accounts: %s"

CSV

JSON

NAKED_LONG_QUANTITY

ERR100

ERR013

"Invalid netQty/nakedShortQty/nakedLongQty supplied for parentPORTFOLIO/omnibusIndicator combination"

"Failed validation: Final net quantity must not be 0 for non-omnibus accounts: %s"

CSV

JSON

NAKED_SHORT_QUANTITY

ERR100

ERR013

"Invalid netQty/nakedShortQty/nakedLongQty supplied for parentPORTFOLIO/omnibusIndicator combination"

"Failed validation: Final net quantity must not be 0 for non-omnibus accounts: %s"

CSV

JSON

EXCHANGE_ID

ERR013

"Failed validation: No valid exchange id supplied: %s"

CSV

JSON

PRODUCT_CODE

ERR014

"Position was ignored: internal SPAN exception while creating position: %s"

CSV

JSON

PRODUCT_TYPE

ERR013

"Failed validation: No valid product type supplied: %s"

CSV

JSON

PERIOD_CODE

ERR013

"Failed validation: No period code supplied: %s"

CSV

JSON

STRIKE

ERR013

"Failed validation: No strike supplied: %s"

CSV

UNDERLYING_PERIOD_CODE

ERR131

Invalid Error

N/A

MEMO

ERR132

Invalid Error

N/A


Additional error message text which can be found after the ERROR_MESSAGE string:

Release Examples

The below examples are intended to assist with new features and concepts introduced in deployable software, not to provide an exhaustive list of all features. For technical details, please review the "examples" provided in the software download package.

List of Start-up Arguments

Listed in alphabetical order.

Start-up Argument

Data Type

Required?

Description

Default

-DadditionalSpanFiles

string

N

User-supplied risk parameter file directory under suppled root directory.

N/A

-DcacheMode

string

N

If "redis" informs deployable to run with redis data cache; else ignored.

N/A

-DdontIgnoreSpanErrors

boolean

N

true = does not ignore errors from the SPAN library, fails to margin when errors from SPAN library occur.
false = ignores invalid span errors and margins the rest of the portfolio.

false

-DfilterByOrigin

string

N

HOUS = margins only portfolios where OriginType = House
CUST = margins only portfolios where OriginType = Customer
See list of valid origin Types in errors above.

N/A

-DfnoRpfDirectory

string

N

User-supplied risk parameter file directory under suppled root directory (see -Drpf.source.path)

N/A

-DignoreInvalidPositions

boolean

N

true = ignores invalid positions in request and passed only valid positions to margin
false = passes all positions, regardless of validity, to margin. Can result in errors for portfolios with invalid positions.

true

-Dlog4j.configurationFile

string

N

User-supplied log4j configuration file, describing log level.

N/A

-DomnibusPortfolioValidationDisabled

boolean

N

true = omnibus warning messages are not exposed in the margin response.
false = omnibus warning messages are exposed in the margin response, see "Lower-Level Warnings and INFO Messages" above

false

-DriskLibraryDump

boolean

N

true = allows extra logging via arcDlApplication/data folder

false

-Drpf.source.path

string

Y

User-supplied risk parameter file root directory.

./rpfs

-Dserver.port

number

Y

User-supplied server port.

8082

-DspanFilesDirectoryOverride

string

N

User-supplied legacy SPAN file location (see Risk Parameter Files above).

N/A

Initialization of RiskAnalyticsService

RiskAnalyticsServiceFactory.createRiskAnalyticsService(…) takes an object of type RiskConfig.class. This class has a builder internal class. For the purposes of the following examples let's assume a file structure like the below:

-Users

---someUser

-------rpfDirectory

-------20190527_FNO

-------20190528_FNO

-------20190529_FNO

---otherFolder

---someOtherFolder

//If passing just the rpfDirectory, it will try to pick the latest RPF available under that folder. In this case the RPF under 20210119_FNO will be selected.

Example: 

RiskConfig = new Builder()

   .rfpDirectory("/Users/someUser/rfpDirectory")

   .build();
RiskAnalyticsService riskAnalyticsService=
RiskAnalyticsServiceFactory.createRiskAnalyticsService(riskConfig);

//If passing the rpfDirectory plus the fnoRpfDirectory it will select the specific folder inside the rpfDirectory. The folder 20190528_FNO will be selected. Example:

RiskConfig riskConfig=new Builder()

   .rfpDirectory("/Users/someUser/rfpDirectory")

   .fnoRfpDirectory("20190528_FNO")

   .build();
RiskAnalyticsService riskAnalyticsService=
RiskAnalyticsServiceFactory.createRiskAnalyticsService(riskConfig);

//validationDisabled (default: false) à if true completely disables the semantic validation. This flag does not affect the converter syntax validation.

 Example:

RiskConfig riskConfig=new Builder()

  .rfpDirectory("/Users/someUser/rpfDirectory")

  .validationDisabled(true)

  .build();

RiskAnalyticsService riskAnalyticsService=
RiskAnalyticsServiceFactory.createRiskAnalyticsService(riskConfig);

//ignoreInvalidPositions (default:false) à if true ignores invalid trades picked up by semantic validation and margins the good ones. This is the validation before the trades are sent to be margined. Syntactically invalid positions picked up by the converter are handled using the converter API described below in the section 'Using RiskFnoToRiskConverter'.

Example:

RiskConfig riskConfig=new Builder()

  .rfpDirectory("/Users/someUser/rpfDirectory")

  .ignoreInvalidPositions(true)

  .build();

RiskAnalyticsService riskAnalyticsService=
RiskAnalyticsServiceFactory.createRiskAnalyticsService(riskConfig);

//dontIgnoreSpanErrors (default:false) à if true then it will throw exception when errors are returned from the margin calculation. When false the errors will simply be added to the response.

Example:

RiskConfig riskConfig=new Builder()

  .rfpDirectory("/Users/someUser/rpfDirectory")

  .dontIgnoreSpanErrors(true)

  .build();

RiskAnalyticsService riskAnalyticsService=
RiskAnalyticsServiceFactory.createRiskAnalyticsService(riskConfig);

//riskLibraryDump (default:false) à if true it will add extra logging from inside the native calculation.

Example:

RiskConfig riskConfig=new Builder()

  .rfpDirectory("/Users/someUser/rpfDirectory")

  .riskLibraryDump(true)

  .build();

RiskAnalyticsService riskAnalyticsService=
RiskAnalyticsServiceFactory.createRiskAnalyticsService(riskConfig);

//spanFilesDirectoryOverride - will override the marketdata folder span files that are part of the standard SPAN/SPAN 2 rpf file installation. When margining historical SPAN only files, the override folder must be used along with an existing/installed SPAN rpf ( cme.span.yyyymmdd.\[s.c\].zip ). This folder can also be used to add in cross-margin and/or inter-exchange span files (e.g. MGE, OCC).

Example:

RiskConfig riskConfig=new Builder()

  .rfpDirectory("/Users/someUser/rpfDirectory")

  .spanFilesDirectoryO verride/"Some/override/directory")

  .build();

RiskAnalyticsService riskAnalyticsService=
RiskAnalyticsServiceFactory.createRiskAnalyticsService(riskConfig);

Using RiskFnoToRiskConverter

//with errors being returned as a list. It will still return a riskPortfolioRequestMessage.
Example:

 

//with exception being thrown when error is found. Exception of type RiskAnalyticException is thrown with information about the error. Flow is interrupted.
 


Log File Parameter

Deployable uses SLF4j which allows users to plugin desired logging framework. To help users understand logging framework, there is an example log4j xml file supplied in the examples/arcdl-example directory under src/main/resources. This can be changed to use whatever logging level required and packaged into users' tech stack with deployable jar by changing the "Root Level=" field per the below list of log levels.
A second option is to supply a separate log xml file and then this can be loaded into deployable.


Log Levels

Level

Description

Default?

Perf Test Log File Example*

DEBUG

Highest level logging, includes details on calculation engine order or operations.

N

14,700 KB

INFO

Standard logging, some calculation details and all errors

Y

8,400 KB

WARN

Errors only.

N

6,200 KB

ERROR

Very limited logging produced

N

1 KB

OFF

No logging is produced

N

N/A


*Perf test conditions:
Initialize SPAN-only risk parameter file (2/2/22 point in time) + MGE 2/2/22 EOD pa2 file
Load portfolioA – 13,500 positions with errors, no margin expected
Load portfolioB – 12,700 positions, multiple errors, margin expected

Reducing the Size of the Log File

To enable debug mode on the logging levels, you will need to download the following log4j file:

 

In this file find <Root level="INFO">, you can change that to DEBUG (at the bottom of the file).

Performance Metrics

Baseline Test Case Description:

Request TypeTotal Time (mm:ss)Time per portfolioPortfolios per secondMax JVM memory usage (max vm mem)Redis memory usageMax total memory usage
SPAN5:2021.3ms46.812 GBn/a25 GB
SPAN 28:1933.3ms3012.7 GB10.8 GB32 GB


ThreadsSPAN (HH:MM:SS)SPAN 2 (hh:mm:ss)
100:42:0001:09:30
1000:05:2000:08:30