Standard Securities Calculation Methods

APIs, MCP, and SDKs

SDK Code Examples

Use the following samples to load and call the SSCMFI Function Library (SDK) dynamically inside your local applications. Make sure the compiled library (libsscmfi.dll, libsscmfi.so, or libsscmfi.dylib) is placed in your application's executable path.

cpp
💾 Download
#include <iostream>
#include <windows.h>

// Define function pointers matching sscmfi interface
typedef char* (*sscmfi_init_t)(char*);
typedef char* (*sscmfi_calculate_t)(char*);
typedef void (*sscmfi_free_string_t)(char*);

int main() {
    // 1. Dynamic Load of Dynamic Link Library (DLL)
    HINSTANCE hDll = LoadLibrary("libsscmfi.dll");
    if (!hDll) {
        std::cerr << "Failed to load libsscmfi.dll" << std::endl;
        return 1;
    }

    // 2. Resolve Dynamic Function Entry Points
    auto sscmfi_init = (sscmfi_init_t)GetProcAddress(hDll, "sscmfi_init");
    auto sscmfi_calculate = (sscmfi_calculate_t)GetProcAddress(hDll, "sscmfi_calculate");
    auto sscmfi_free_string = (sscmfi_free_string_t)GetProcAddress(hDll, "sscmfi_free_string");

    if (!sscmfi_init || !sscmfi_calculate || !sscmfi_free_string) {
        std::cerr << "Failed to resolve DLL functions" << std::endl;
        FreeLibrary(hDll);
        return 1;
    }

    // 3. Initialize Licensing with API Key (Only needs to be done once per process)
    char* initRes = sscmfi_init("YOUR_API_KEY_HERE");
    std::cout << "SSCMFI Init Status: " << initRes << std::endl;

    // 4. Construct JSON Payload String
    char* jsonPayload = R"({
        "metadata": {
            "calculationID": "SDK-CPP"
        },
        "securityDefinition": {
            "securityID": "SDK-SEC",
            "paymentType": "Periodic",
            "securityType": "Corporate",
            "maturityDate": "3/31/2031",
            "couponRate": 8.75,
            "redemption_value": 100.0,
            "dayCountBasis": "SSCM30/360",
            "eomRule": "Adjust",
            "periodsPerYear": "Monthly"
        },
        "tradeDefinition": {
            "tradeDate": "7/22/2025",
            "settlementDate": "7/23/2025",
            "givenType": "Price",
            "givenValue": 103.5
        },
        "calculationSelection": {
            "calcsToReturn": {
                "calcPY": "Yes",
                "calcPYAnalytics": "Yes",
                "calcCFS": "No",
                "calcCFSAnalytics": "Yes",
                "calcCouponPeriod": "Yes"
            },
            "calculationsFor": "All redemptions"
        },
        "settings": {
            "dateScheme": {
                "dateTwoOrFourYear": "FOUR",
                "dateFormat": "MDY",
                "dateCutoffYear": 2075
            }
        }
    })";

    // 5. Execute In-Process calculation
    char* response = sscmfi_calculate(jsonPayload);
    std::cout << "Calculation Response:\n" << response << std::endl;

    // 6. Free C-string Memory back to the DLL heap
    sscmfi_free_string(response);

    // 7. Cleanup & Unload DLL
    FreeLibrary(hDll);
    return 0;
}
go
💾 Download
package main

import (
	"fmt"
	"syscall"
	"unsafe"
)

func main() {
	// 1. Load Dynamic Link Library (.dll)
	dll, err := syscall.LoadDLL("libsscmfi.dll")
	if err != nil {
		panic(err)
	}
	defer dll.Release()

	// 2. Resolve Function Names
	sscmfiInit, err := dll.FindProc("sscmfi_init")
	if err != nil {
		panic(err)
	}
	sscmfiCalculate, err := dll.FindProc("sscmfi_calculate")
	if err != nil {
		panic(err)
	}
	sscmfiFreeString, err := dll.FindProc("sscmfi_free_string")
	if err != nil {
		panic(err)
	}

	// Helper to generate a C-compatible null-terminated string pointer
	toCString := func(s string) unsafe.Pointer {
		bytes := append([]byte(s), 0)
		return unsafe.Pointer(&bytes[0])
	}

	// 3. Initialize License (online check-in / fallback local lease)
	apiKey := "YOUR_API_KEY_HERE"
	initRet, _, _ := sscmfiInit.Call(uintptr(toCString(apiKey)))
	
	// Read null-terminated string result
	initResBytes := (*[1 << 20]byte)(unsafe.Pointer(initRet))
	var initLen int
	for initResBytes[initLen] != 0 {
		initLen++
	}
	fmt.Printf("Init Result: %s\n", string(initResBytes[:initLen]))

	// 4. Set up JSON Payload
	payload := `{
        "metadata": {
            "calculationID": "SDK-GO"
        },
        "securityDefinition": {
            "securityID": "SDK-SEC",
            "paymentType": "Periodic",
            "securityType": "Corporate",
            "maturityDate": "3/31/2031",
            "couponRate": 8.75,
            "redemption_value": 100.0,
            "dayCountBasis": "SSCM30/360",
            "eomRule": "Adjust",
            "periodsPerYear": "Monthly"
        },
        "tradeDefinition": {
            "tradeDate": "7/22/2025",
            "settlementDate": "7/23/2025",
            "givenType": "Price",
            "givenValue": 103.5
        },
        "calculationSelection": {
            "calcsToReturn": {
                "calcPY": "Yes",
                "calcPYAnalytics": "Yes",
                "calcCFS": "No",
                "calcCFSAnalytics": "Yes",
                "calcCouponPeriod": "Yes"
            },
            "calculationsFor": "All redemptions"
        },
        "settings": {
            "dateScheme": {
                "dateTwoOrFourYear": "FOUR",
                "dateFormat": "MDY",
                "dateCutoffYear": 2075
            }
        }
    }`

	// 5. Invoke Calculation
	resRet, _, _ := sscmfiCalculate.Call(uintptr(toCString(payload)))
	
	// 6. Read null-terminated Response JSON string
	resBytes := (*[1 << 30]byte)(unsafe.Pointer(resRet))
	var resLen int
	for resBytes[resLen] != 0 {
		resLen++
	}
	fmt.Printf("Calculation Response:\n%s\n", string(resBytes[:resLen]))

	// 7. Free C-string allocation in Go DLL memory space
	sscmfiFreeString.Call(resRet)
}
python
💾 Download
import ctypes
import json

# 1. Load dynamic library (adjust filename for macOS/Linux)
lib = ctypes.CDLL("./libsscmfi.dll")

# 2. Define standard C argument and return types
lib.sscmfi_init.argtypes = [ctypes.c_char_p]
lib.sscmfi_init.restype = ctypes.c_char_p

lib.sscmfi_calculate.argtypes = [ctypes.c_char_p]
lib.sscmfi_calculate.restype = ctypes.c_char_p

lib.sscmfi_free_string.argtypes = [ctypes.c_char_p]
lib.sscmfi_free_string.restype = None

# 3. Initialize SDK license
api_key = b"YOUR_API_KEY_HERE"
init_res = lib.sscmfi_init(api_key)
print(f"Init Status: {init_res.decode('utf-8')}")

# 4. Construct JSON Payload Dictionary
payload = {
    "metadata": {
        "calculationID": "SDK-PYTHON"
    },
    "securityDefinition": {
        "securityID": "SDK-SEC",
        "paymentType": "Periodic",
        "securityType": "Corporate",
        "maturityDate": "3/31/2031",
        "couponRate": 8.75,
        "redemption_value": 100.0,
        "dayCountBasis": "SSCM30/360",
        "eomRule": "Adjust",
        "periodsPerYear": "Monthly"
    },
    "tradeDefinition": {
        "tradeDate": "7/22/2025",
        "settlementDate": "7/23/2025",
        "givenType": "Price",
        "givenValue": 103.5
    },
    "calculationSelection": {
        "calcsToReturn": {
            "calcPY": "Yes",
            "calcPYAnalytics": "Yes",
            "calcCFS": "No",
            "calcCFSAnalytics": "Yes",
            "calcCouponPeriod": "Yes"
        },
        "calculationsFor": "All redemptions"
    },
    "settings": {
        "dateScheme": {
            "dateTwoOrFourYear": "FOUR",
            "dateFormat": "MDY",
            "dateCutoffYear": 2075
        }
    }
}
json_payload = json.dumps(payload).encode('utf-8')

# 5. Perform Calculation
response_ptr = lib.sscmfi_calculate(json_payload)

# 6. Read and Parse JSON C-String Response
response_str = response_ptr.decode('utf-8')
response_data = json.loads(response_str)
print("Calculation Response:")
print(json.dumps(response_data, indent=4))

# 7. Free Returned C-string back to the DLL heap
lib.sscmfi_free_string(response_ptr)
vb
💾 Download
' === PLACE IN A STANDARD EXCEL VBA MODULE ===

#If VBA7 Then
    Private Declare PtrSafe Function sscmfi_init Lib "libsscmfi.dll" (ByVal apiKey As String) As LongPtr
    Private Declare PtrSafe Function sscmfi_calculate Lib "libsscmfi.dll" (ByVal jsonPayload As String) As LongPtr
    Private Declare PtrSafe Sub sscmfi_free_string Lib "libsscmfi.dll" (ByVal ptr As LongPtr)
    Private Declare PtrSafe Function lstrlenA Lib "kernel32" (ByVal lpString As LongPtr) As Long
    Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal hpvDest As String, ByVal hpvSource As LongPtr, ByVal cbCopy As Long)
#Else
    Private Declare Function sscmfi_init Lib "libsscmfi.dll" (ByVal apiKey As String) As Long
    Private Declare Function sscmfi_calculate Lib "libsscmfi.dll" (ByVal jsonPayload As String) As Long
    Private Declare Sub sscmfi_free_string Lib "libsscmfi.dll" (ByVal ptr As Long)
    Private Declare Function lstrlenA Lib "kernel32" (ByVal lpString As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal hpvDest As String, ByVal hpvSource As Long, ByVal cbCopy As Long)
#End If

' Helper function to read null-terminated C-string from returned LongPtr pointer
#If VBA7 Then
Private Function PointerToString(ByVal ptr As LongPtr) As String
#Else
Private Function PointerToString(ByVal ptr As Long) As String
#End If
    Dim length As Long
    Dim buffer As String
    If ptr = 0 Then
        PointerToString = ""
        Exit Function
    End If
    length = lstrlenA(ptr)
    buffer = Space$(length)
    CopyMemory buffer, ptr, length
    PointerToString = buffer
End Function

' 1. Initialize function library (Call once on Workbook Open)
Public Sub InitSSCMFI(ByVal apiKey As String)
    #If VBA7 Then
        Dim resPtr As LongPtr
    #Else
        Dim resPtr As Long
    #End If
    resPtr = sscmfi_init(apiKey)
    MsgBox "SSCMFI Init Status: " & PointerToString(resPtr)
End Sub

' 2. Custom Excel Function to calculate Bond properties from cell formulas
Public Function SSCM_CALCULATE_BOND(ByVal maturity As String, ByVal coupon As Double, ByVal givenType As String, ByVal givenVal As Double, ByVal settlement As String) As String
    #If VBA7 Then
        Dim resPtr As LongPtr
    #Else
        Dim resPtr As Long
    #End If
    Dim jsonPayload As String
    
    ' Construct JSON payload string
    jsonPayload = "{""metadata"": {""calculationID"": ""SDK-VBA""}," & _
                  """securityDefinition"": {""securityID"": ""Excel"",""paymentType"": ""Periodic"",""securityType"": ""Corporate"",""maturityDate"": """ & maturity & """,""couponRate"": " & coupon & ",""redemption_value"": 100.0,""dayCountBasis"": ""SSCM30/360"",""eomRule"": ""Adjust"",""periodsPerYear"": ""Semi-Annual""}," & _
                  """tradeDefinition"": {""tradeDate"": """ & settlement & """,""settlementDate"": """ & settlement & """,""givenType"": """ & givenType & """,""givenValue"": " & givenVal & "}," & _
                  """calculationSelection"": {""calcsToReturn"": {""calcPY"": ""Yes"",""calcPYAnalytics"": ""Yes"",""calcCFS"": ""No"",""calcCFSAnalytics"": ""Yes"",""calcCouponPeriod"": ""Yes""},""calculationsFor"": ""All redemptions""}," & _
                  """settings"": {""dateScheme"": {""dateTwoOrFourYear"": ""FOUR"",""dateFormat"": ""MDY"",""dateCutoffYear"": 2075}}}"
                  
    ' Call calculation function in DLL
    resPtr = sscmfi_calculate(jsonPayload)
    
    ' Parse returned C-string
    SSCM_CALCULATE_BOND = PointerToString(resPtr)
    
    ' Free the C-string pointer allocated by the DLL heap
    sscmfi_free_string resPtr
End Function