Jump to content

Author Archive

HydraSDO for XML with FpML Example

Thursday, July 3rd, 2008

FpML (Financial products Markup Language) is the industry standard protocol for complex financial products. It was first published in 1999 and is now managed by the ISDA (International Swaps and Derivatives Association). FpML is important because it is the XML specification for OTC (over-the-counter) derivatives and its use has increased substantially over the past few years, especially for interest rate and credit derivatives, according to a recent survey by the ISDA. The complete FpML specifications can be found on the FpML website.

Rogue Wave Software’s HydraSDO for XML product enables XML documents to be read and updated using the SDO (Service Data Objects) API which uses simple XPath notation. SDO is the industry standard for data access in a Service Oriented Architecture. HydraSDO for XML has extremely fast parsing capabilities and very low memory requirements, resulting in performance improvements for most applications. Both C++ and Java are supported, with shared memory access allowing a single copy of data to be accessed by both a C++ and a Java application.

The example below shows how a bond option FpML instance document can be read into memory, and data can be easily retrieved and modified using the Hydra SDO for XML C++ API. The instance document (bond-option.xml) is available from the FpML website.

Example

#include <iostream>
#include <string>

#include <rwsf/sdo/DataFactory.h>
#include <rwsf/sdo/DataGraph.h>
#include <rwsf/sdo/DataObject.h>
#include <rwsf/sdo/DataObjectList.h>
#include <rwsf/sdo/HelperProvider.h>
#include <rwsf/sdo/PropertyList.h>
#include <rwsf/sdo/XMLDataAccessService.h>
#include <rwsf/sdo/XSDHelper.h>

using namespace rwsf;
using namespace sdo;
using namespace std;

const char* SCHEMA_FILE = “../fpml-bond-option-4-4.xsd”;
const char* INSTANCE_DOC = “../bond-option.xml”;

int main()
{
  try
  {
    // Create an XSD Helper instance for working with XML schema
    DataFactoryPtr dataFactory = DataFactory::getDataFactory();
    XSDHelperPtr xsdHelper = HelperProvider::getXSDHelper(dataFactory);

    // Define Types and Properties from the XML Schema
    xsdHelper->defineFile(SCHEMA_FILE);

    // Load the XML instance document
    XMLDataAccessService das(dataFactory);
    DataGraphPtr dataGraph = das.loadFile(INSTANCE_DOC);

    // Create a root data object
    DataObjectPtr root = dataGraph->getRootObject();
    DataObjectPtr fpmlDoc = root->getDataObject(”FpML”);

    // Get bond details
    DataObjectPtr bond = fpmlDoc->getDataObject(”trade[1]/bondOption/bond”);
    std::cout << “Instrument Id = ” << bond->getCString(”instrumentId[1]”);
    std::cout << “Currency = ” << bond->getCString(”currency”);
    std::cout << “Coupon Rate = ” << bond->getCString(”couponRate”);
    std::cout << “Maturity = ” << bond->getCString(”maturity”);
    std::cout << “Par Value = ” << bond->getCString(”parValue”);
    std::cout << “Face Amount = ” << bond->getCString(”faceAmount”);

    // Modify the Coupon Rate from 0.014 to 0.015
    bond->setCString(”couponRate”, “0.015″);

    // Save the changes to a new XML instance document
    das.save(dataGraph, “bond-option.001.xml”);

    return 0;
  }
  catch (SDORuntimeException& e)
  {
    cout << e.why() << endl;
  }
}