Component Interface for Version 4 of PC-SPAN, SPAN Risk Manager, and SPAN Risk Manager Clearing
A real-time component interface is available for PC-SPAN version 4. With this additional software module, licensed separately as SPAN Real-Time Component Interface (SPAN RTCI), you can develop programs which interface to PC-SPAN in real-time.
For example, suppose a customer requests an order. Using the component interface, your program can call PC-SPAN, specify the updated position that will result from the order, request that the performance bond be calculated, and receive back the updated performance bond requirement--all with extremely rapid execution times.
The SPAN Risk Manager Clearing software also has a real-time component interface. With this software module, in addition to everything you can do with the component interface to PC-SPAN, you can develop programs which execute the functions of the SPAN Risk Manager Clearing in real-time.
For example, you could programmatically update market prices for futures and physicals, and then recalculate volatilities, theoretical prices and risk arrays.
This topic provides a technical reference to the real-time component interfaces for PC-SPAN, SPAN Risk Manager, and SPAN Risk Manager Clearing.
- 1 dispinterface ISpanCom
- 1.1 short Load(BSTR fileName, boolean replaceExc, boolean useExtLayout);
- 1.2 short Save(BSTR fileName);
- 1.3 short SelectPIT(BSTR busDate, short isSettle, short isFinal, BSTR busTime, BSTR description);
- 1.4 short SelectPortfolio(BSTR firmCode, BSTR acctCode, BSTR segType);
- 1.5 void ResetPIT();
- 1.6 void ResetPortfolio();
- 1.7 short Calculate();
- 1.8 double GetPortfSpanReq(short pbClass, boolean isInitial);
- 1.9 double GetPortfTotalReq(short pbClass, boolean isInitial);
- 1.10 double GetCurPortfSpanReq(short pbClass, boolean isInitial, BSTR curCode);
- 1.11 double GetCurPortfTotalReq(short pbClass, boolean isInitial, BSTR curCode);
- 1.12 void Delete();
- 1.13 double GetPortfLongFutValue();
- 1.14 double GetPortfShortFutValue();
- 1.15 double GetPortfLongOptValue();
- 1.16 double GetPortfShortOptValue();
- 1.17 void SetLogLevel(short processId, short priorityId);
- 1.18 void LogSave(BSTR fileName);
- 1.19 void LogClear();
- 1.20 short CreatePortfolio(BSTR firmCode, BSTR acctCode, BSTR segType);
- 1.21 short SetPortfAcctType(BSTR acctType, boolean isClearing);
- 1.22 short SetPortfParent(BSTR firmCode, BSTR acctCode, BSTR segType);
- 1.23 short SetPortfCurrency(BSTR currencyCode);
- 1.24 BSTR GetPortfCurrency();
- 1.25 short SetPortfLedgerBalance(double value);
- 1.26 double GetPortfLedgerBalance();
- 1.27 short SavePortfolios(BSTR filename);
- 1.28 short SetPortfOpenTradeEquity(double value);
- 1.29 double GetPortfOpenTradeEquity();
- 1.30 short SetPortfSecurityOnDeposit(double value);
- 1.31 double GetPortfSecurityOnDeposit();
- 1.32 short SetPortfPosition(BSTR exchCmplxAcro, BSTR exchAcro, BSTR pfCode, short pfType, BSTR futPeriod, BSTR optPeriod, boolean isPut, double strike, long totalLong, long totalShort, long intraLong, long intraShort, long interLong, long interShort, long nakedLong, longnakedShort);
- 1.33 short ChangePortfPosition(BSTR exchCmplxAcro, BSTR exchAcro, BSTR pfCode, short pfType, BSTR futPeriod, BSTR optPeriod, boolean isPut, double strike, long totalLong, long totalShort, long intraLong, long intraShort, long interLong, long interShort, long nakedLong, longnakedShort);
- 1.34 short SavePositions(BSTR fileName);
- 1.35 short LoadStream(SAFEARRAY(BYTE) data);
- 2 dispinterface ISpanComRM
- 2.1 short SelectExchangeComplex(BSTR excAcro);
- 2.2 short SelectBFCC(BSTR ccCode);
- 2.3 short SelectProductFamily(BSTR exchCode, BSTR pfCode, short pfType);
- 2.4 void ResetExchangeComplex();
- 2.5 void ResetBFCC();
- 2.6 void ResetProductFamily();
- 2.7 short CalcImpliedVolatility(boolean flatCabVol);
- 2.8 short CalcCallPutAverage(boolean outMoney, boolean acceptZero);
- 2.9 short CalcSeriesVolatility(boolean useZero, double minExpTime, short maxIn, short maxOut, short minAccept);
- 2.10 short CalcPrice(short meth, boolean resetAll);
- 2.11 short CalcRiskArray(short meth, short limitMeth, boolean useTheorPrice);
- 2.12 void UpdatePrice(double value, short meth);
- 2.13 void UpdateVolatility(double value, short meth);
- 2.14 void UpdatePriceScan(double value, short meth);
- 2.15 void UpdateVolScan(double value, short meth);
- 2.16 void UpdateRiskFreeRate(double value, short meth);
- 2.17 void UpdateDividendYield(double value, short meth);
- 2.18 void UpdateTimeToExpiration(double value, short meth);
- 2.19 short UpdateCDSValue(short valueType, double value, short meth);
- 2.20 short SetStartPeriod(BSTR periodCode);
- 2.21 short SetEndPeriod(BSTR periodCode);
- 2.22 void ResetPeriods();
- 2.23 short CopyPIT(BSTR description, BSTR busDate, short isSettle, short isFinal, BSTR busTime);
- 2.24 void DoMarketObservation();
- 2.25 void ResetMarketPrices();
- 2.26 double GetPortfMTMFut();
- 2.27 double GetPortfMTMPrem();
- 2.28 double GetPortfMTMTFut();
- 2.29 double GetPortfMTMTPrem();
- 2.30 double GetPortfUnrealizedPL();
- 2.31 double GetPortfRealizedPLOpen();
- 2.32 double GetPortfRealizedPLLiq();
- 2.33 short SaveRegistryTo(BSTR fileName);
- 2.34 short ApplyWhatIf(BSTR fileName, boolean doCalc);
- 2.35 short CalcValues();
- 2.36 short CalcGreeks(short meth);
- 2.37 short ReplicateBasePrices();
- 2.38 short ApplyVolatilitySkew(short meth);
- 2.39 short PostTrade(BSTR timeStamp, long tradeId, BSTR exchCmplxAcro, BSTR exchAcro, BSTR pfCode, short pfType, BSTR futPeriod, BSTR optPeriod, boolean isPut, double strike, double price, long tradeQty);
- 2.40 short ResetPrices(short prodType);
Below is an example of calling the component interface from Visual C++ code.
#include <stdio.h>
#include <ole2.h>
#import "C:\Span4\Bin\SpanCom.tlb" no_namespace, named_guids
int main(int argc, char* argv[])
{
if(FAILED(::CoInitialize(NULL))) return 1;
ISpanCom* pSpanCom;
if(SUCCEEDED(::CoCreateInstance(CLSID_SpanCom, NULL, CLSCTX_LOCAL_SERVER,
__uuidof(ISpanCom), (LPVOID*) &pSpanCom)))
{
printf( "Success\n");
// pSpanCom->Load("C:\\cme0216s.par",1,0);
pSpanCom->Release();
}
else printf("Fail\n");
::CoUninitialize();
return 0;
}
dispinterface ISpanCom
methods:
short Load(BSTR fileName, boolean replaceExc, boolean useExtLayout);
Description:
Load any SPAN recognized file into PC-SPAN, including SPAN files (*.SPN), classic "flat-files" (*.PA2), position files (*.txt and *.pos), etc. All position files (*.txt and *.pos) require corresponding risk parameter files to be already loaded. Positions are loaded into the currently selected point in time. If this point in time is not present positions are loaded into the first available point in time.
For more details on supported file formats, click here.
Parameters:
fileName - BSTR - The document to be loaded.
replaceExc - bool - Specifies whether PC-SPAN should replace already loaded exchange complexes with the ones from the file (true) or leave them intact (false)
useExtLayout - bool - Specifies whether PC-SPAN should use extended file layout when loading positions. It is only used for loading old format position files (*.txt).
Return Value:
short - Return value can be 0 (success) or non-zero (failure).
short Save(BSTR fileName);
Description:
Saves all the information from PC-SPAN into a file.
Parameters:
fileName - BSTR - The name of document to be saved, in the SPAN XML format.
Return Value:
short - Return value can be 0 (success) or non-zero (failure).
short SelectPIT(BSTR busDate, short isSettle, short isFinal, BSTR busTime, BSTR description);
Description:
Selects a specified point in time as current point in time. Once selected, a point in time remains selected until it is reset, a different point in time is selected, or until the point in time is cleared.
Parameters:
busDate - BSTR - The date of the point in time to select. The point in time must be in a "YYYYMMDD" format. Alternatively, the busDate string parameter may be empty to select the first point in time.
isSettle - short - Search for a point in time where the settlement is: '0' for non-settlement; '1' for settlement; or '-1' for no preference on settlement indication.
isFinal - short - Search for a point in time where the final flag is: '0' for not final; '1' for final; or '-1' for no preference on final indication.
busTime - BSTR - When the isSettle flag is 0, the busTime may be optionally specified. It is formatted as "HHMM". If isSettle flag is not 0, the busTime is ignored.
description - BSTR - When the isSettle flag is not -1, the description may be optionally specified to match the description of available points in time. If passed as an empty string, it is ignored.
Remarks:
If busDate is empty and the isSettle is -1, the rest of the parameters are ignored and first available point in time is selected. If either isSettle or isFinal is set to –1 this parameter and all parameters following it are ignored. If busTime or description is empty it is ignored.
Return Value:
short - Return value can be 0 (success) or non-zero (failure).
short SelectPortfolio(BSTR firmCode, BSTR acctCode, BSTR segType);
Description:
Selects specified portfolio as current. This method searches for the specified portfolio in the currently selected point in time. If point in time is not selected it fails.
Parameters:
firmCode - BSTR - If not empty, it will be used to match the firm code to find the portfolio.
acctCode - BSTR - If not empty, it will be used to match the account code.
segType - BSTR - If not empty, it will be used to match the seg type code.
Remarks:
If all parameters are empty, the first portfolio will be selected. Any combination of parameters may be used.
Return Value:
short - Return value can be 0 (success) or non-zero (failure).
void ResetPIT();
Description:
Sets currently selected point in time to NULL (removes selection). Also resets portfolio selection.
Parameters:
None
Remarks:
When the point in time selection is reset, the point in time is still available. It is merely no longer selected as the active point in time.
Return Value:
None
void ResetPortfolio();
Description:
Sets currently selected portfolio to NULL (removes selection).
Parameters:
None
Remarks:
When this call is made, the portfolio is still available. It is no longer selected as the active portfolio. The point in time selection is not affected by this call.
Return Value:
None
short Calculate();
Description:
Performs SPAN requirements calculations for the currently selected object. If portfolio selection is not NULL it does calculations only for the selected portfolio. If it is NULL and point in time selection is not NULL it does calculations for all portfolios in the selected point in time. If both selected portfolio and selected point in time are NULL it does calculations for all points in time and portfolios loaded into PC-SPAN.
Parameters:
None
Return Value:
short - Return value can be 0 (success) or non-zero (failure).
double GetPortfSpanReq(short pbClass, boolean isInitial);
Description:
Returns SPAN requirement calculated for the selected portfolio. If a portfolio is not selected (NULL) or if Calculate has not been called, the return is 0.
Parameters:
pbClass - short - Specifies the class of the requirement. It can be 1(CORE) or 2(RESERVE).
isInitial - boolean - Indicates maintenance (false) or initial (true) requirement.
Return Value:
double - Returns SPAN requirement calculated for the selected portfolio.
double GetPortfTotalReq(short pbClass, boolean isInitial);
Description:
Returns Total requirement calculated for the selected portfolio. If a portfolio is not selected (NULL) or if Calculate has not been called, the return is 0.
Parameters:
pbClass - short - Specifies the class of the requirement. It can be 1(CORE) or 2(RESERVE).
isInitial - boolean - Indicates maintenance (false) or initial (true) requirement.
Return Value:
double - Returns Total requirement calculated for the selected portfolio.
double GetCurPortfSpanReq(short pbClass, boolean isInitial, BSTR curCode);
Description:
Returns SPAN requirement calculated for the selected portfolio for the specified currency. If a portfolio is not selected (NULL), or if an invalid curCode is passed, or if Calculate has not been called, the return is 0.
Parameters:
pbClass - short - Specifies the class of the requirement. It can be 1(CORE) or 2(RESERVE).
isInitial - boolean - Indicates maintenance (false) or initial (true) requirement.
curCode - BSTR - Specifies the currency code to get the Span requirement in.
Return Value:
double - Returns SPAN requirement calculated for the selected portfolio for the specified currency.
double GetCurPortfTotalReq(short pbClass, boolean isInitial, BSTR curCode);
Description:
Returns Total requirement calculated for the selected portfolio for the specified currency. If a portfolio is not selected (NULL), or if an invalid curCode is passed, or if Calculate has not been called, the return is 0.
Parameters:
pbClass - short - Specifies the class of the requirement. It can be 1(CORE) or 2(RESERVE).
isInitial - boolean - Indicates maintenance (false) or initial (true) requirement.
curCode - BSTR - Specifies the currency code to get the Total requirement in.
curCode - BSTR - Specifies the currency code to get the Total requirement in.
Return Value:
double - Returns Total requirement calculated for the selected portfolio for the specified currency.
void Delete();
Description:
Deletes currently selected object from PC-SPAN. If a portfolio selection has been made, it deletes only the selected portfolio. If it is not selected (NULL) and a point in time selection is selected (NULL) it deletes the selected point in time. If both neither a portfolio or a point in time are selected (both NULL), then the whole contents of the PC-SPAN is deleted.
Parameters:
None
Return Value:
None
double GetPortfLongFutValue();
Description:
Returns long futures value calculated for the selected portfolio. If portfolio is not selected (NULL) it returns 0.
Parameters:
None
Return Value:
double - Returns long futures value for selected portfolio.
double GetPortfShortFutValue();
Description:
Returns short futures value calculated for the selected portfolio. If portfolio is not selected (NULL) it returns 0.
Parameters:
None
Return Value:
double - Returns short futures value for selected portfolio.
double GetPortfLongOptValue();
Description:
Returns long options value calculated for the selected portfolio. If portfolio is not selected (NULL) it returns 0.
Parameters:
None
Return Value:
double - Returns long options value for selected portfolio.
double GetPortfShortOptValue();
Description:
Returns short options value calculated for the selected portfolio. If portfolio is not selected (NULL) it returns 0.
Parameters:
None
Return Value:
double - Returns short options value for selected portfolio.
void SetLogLevel(short processId, short priorityId);
Description:
Use this method to specify logging level for PC-SPAN.
Parameters
processId - short - The upper limit for process id of the log message source. Possible values for processLimits are:
PROC_ID_LOAD_RISK | = 10; |
PROC_ID_LOAD_POS | = 20; |
PROC_ID_LOAD_XML | = 30; |
PROC_ID_OMNIBUS | = 40; |
PROC_ID_CALC_START | = 51; |
PROC_ID_CALC_PBOND | = 60; |
PROC_ID_CALC_SPREAD | = 70; |
PROC_ID_CALC_LIQ_RISK | = 80; |
PROC_ID_CALC_DETAIL_START | = 101; |
PROC_ID_CALC_SPREAD_DETAIL | = 110; |
PROC_ID_CALC_LIQ_RISK_DETAIL | = 120; |
PROC_ID_CALC_POS_DETAIL | = 130; |
PROC_ID_UPPER | = -1; |
priorityId - short - The lower limit for the log message priority. Possible values for the priorityId are:
PRIORITY_ID_LOW | = -1; |
PRIORITY_ID_NORMAL | = 10; |
PRIORITY_ID_WARNING | = 20; |
PRIORITY_ID_ERROR | = 30; |
Remarks:
Default values are 0 (processId) and 30 (priorityId - only errors) are logged.
Return Value:
None
void LogSave(BSTR fileName);
Description:
Saves PC-SPAN log into the file specified by fileName.
Parameters:
fileName - BSTR - The file name to save the log as.
Return Value:
None
void LogClear();
Description:
Clears the PC-SPAN Log.
Parameters:
None
Return Value:
None
short CreatePortfolio(BSTR firmCode, BSTR acctCode, BSTR segType);
Description:
Creates a new portfolio with specified parameters in the selected point in time and selects it as current. The call will fail if a point in time is not selected. If portfolio with given parameters already exist selects the existing portfolio as current (the call does not create a duplicate one).
Parameters:
firmCode - BSTR - The firm code to create a portfolio with.
acctCode - BSTR - The account code to create a portfolio with.
segType - BSTR - The segment type to create a portfolio with. If segType is empty, a “N/A” segment type is assumed.
Return Value:
short - Returns 0 (success) or non-zero (failure).
short SetPortfAcctType(BSTR acctType, boolean isClearing);
Description:
Sets account type for the selected portfolio. If portfolio is not selected the call will fail. If the specified account type is not found in the organization master database the call will fail. The selected portfolio can not have positions already defined otherwise the call will fail.
Parameters:
acctType - BSTR - The account type for the selected portfolio. The following values are currently defined for the acctType:
N | - normal |
M | - member |
H | - hedge |
S | - speculator |
O | - omnibus (speculator) |
Q | - omnibus (hedge). |
isClearing - boolean - specifies whether account is customer(false) or clearing(true).
Return Value:
short - Returns 0 (success) or non-zero (failure).
short SetPortfParent(BSTR firmCode, BSTR acctCode, BSTR segType);
Description:
Sets parent portfolio for the selected portfolio by finding a portfolio using the parameters provided. Used only for omnibus accounts. Only omnibus account can be a parent of another portfolio. Only one level of parents is supported. Fails if portfolio is not selected, parent portfolio can not be found or omnibus rules are violated.
Parameters:
firmCode - BSTR - The portfolio firmCode to search for the selected portfolio.
acctCode - BSTR - The portfolio acctCode to search for the selected portfolio.
segType - BSTR - The portfolio segType to search for the selected portfolio.
Return Value
short - Returns 0 (success) or non-zero (failure).
short SetPortfCurrency(BSTR currencyCode);
Description:
Sets currency for the selected portfolio.
Parameters
currencyCode - BSTR - A three-letter ISO code for the currency (USD, EUR, GBP etc.).
Remarks
The call will fail if a portfolio is not selected or if the currency parameter is not defined in the organization master database.
Return Value
short - Returns 0 (success) or non-zero (failure).
BSTR GetPortfCurrency();
Description:
Returns a three-letter ISO code for the currency of the selected portfolio. If a portfolio is not selected or the currency for it is not specified method returns an empty string.
Parameters:
None
Return Value:
BSTR - Returns an ISO code for the selected portfolio currency.
short SetPortfLedgerBalance(double value);
Description:
Sets ledger balance for the selected portfolio. Fails if portfolio is not selected.
Parameters:
value - double - The portfolio ledger balance to set.
Return Value:
short - Returns 0 (success) or non-zero (failure).
double GetPortfLedgerBalance();
Description:
Returns ledger balance for the selected portfolio. If portfolio is not selected, the call will fail.
Parameters:
None
Return Value:
double - Returns the ledge balance or 0 if no portfolio is selected.
short SavePortfolios(BSTR filename);
Description:
Saves portfolios to a file.
Parameters:
fileName - BSTR - The name of the portfolio file to save.
Remarks:
If a portfolio is selected, only the selected portfolio will be saved. If a portfolio is not selected but a point in time is selected, all of the portfolios belonging to the selected point in time will be saved. A portfolio or a point in time must be selected, otherwise the call will fail.
Return Value:
short - Returns 0 (success) or non-zero (failure).
short SetPortfOpenTradeEquity(double value);
Description:
Sets open trade equity for the selected portfolio. Fails if portfolio is not selected.
Parameters:
value- double - The open trade equity to set.
Return Value:
short - Returns 0 (success) or non-zero (failure).
double GetPortfOpenTradeEquity();
Description:
Returns open trade equity for the selected portfolio. If a portfolio is not selected, the return will be 0.
Parameters:
None
Return Value:
double - Returns open trade equity or 0 if no portfolio is selected.
short SetPortfSecurityOnDeposit(double value);
Description:
Sets security on deposit for the selected portfolio. The call will fail if a portfolio is not selected.
Parameters:
value - double - The security on deposit value to set.
Return Value:
short - Returns 0 (success) or non-zero (failure).
double GetPortfSecurityOnDeposit();
Description:
Returns security on deposit for the selected portfolio. If a portfolio is not selected returns 0.
Parameters:
None
Return Value:
double - Returns the security on deposit or 0 if no portfolio is selected.
short SetPortfPosition(BSTR exchCmplxAcro, BSTR exchAcro, BSTR pfCode, short pfType, BSTR futPeriod, BSTR optPeriod, boolean isPut, double strike, long totalLong, long totalShort, long intraLong, long intraShort, long interLong, long interShort, long nakedLong, longnakedShort);
Description:
Sets positions in the selected portfolio in the specified contract. If portfolio is not selected or contract can not be found the method will fail.
Parameters:
exchCmplxAcro - BSTR - The exchange complex acronym (“CME”, “BOTCC”, etc.)
exchAcro - BSTR - The exchange acronym (“CME”, “CBT”, etc.)
pfCode - BSTR - The product family code (“SP”, “BP”, etc.)
pfType - short - The product family type. Possible values are:
How was your Client Systems Wiki Experience? Submit Feedback
Copyright © 2024 CME Group Inc. All rights reserved.