Jump to content

HydraSDO for XML with FpML Example

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;
  }
}

Del.icio.us   |   Technorati   |   Digg   |   Slashdot

3 Responses to “HydraSDO for XML with FpML Example”

  1. Boris Kolpackov Says:

    I wonder what are the advantages of this new SDO approach compared to XML data binding? With data binding you get statically typed object model that does not require manual text to C++ types conversion or string-based flow control. For example, in the above code it is quite easy to make a mistake and misspell an element name:

    cout << “Maturity = ” <getCString(”mturity”);

    This kind of error will only be detected at runtime. With data binding if you misspell a function you will get a compiler error:

    cout << “Maturity = ” <mturity(); // error: mturity: no such function

    Also with data binding you get values automatically converted to C++ types (e.g., int, double, etc.) that can be manipulated directly. For example, if we need to increase couponRate by 0.01 we can simply do:

    bond->couponRate (bond->couponRate () + 0.01);

    With the SDO approach you have to manually convert the string representation of the couponRate element to double, add the increment, and then convert it back to string.

    It looks to me that SDO is nothing more than a DOM with XPath support.

  2. Dean Stewart Says:

    Hi Boris,

    I completely agree with your comments about the benefits of data binding in terms of compile time error checking, and this is what our HydraExpress product provides, an easy to use XML to C++ data binding tool with a high performance C++ parser http://www.roguewave.com/products/hydra/hydraexpress.php

    To answer your question about the advantages of SDO, it provides a single API to access any data source, so allowing access not just to XML files but also relational database data, flat text files, comma separated files, etc. It is also extremely easy to learn and use, as it is based on XPath notation.

    Applications built with SDO can be easily integrated into a SOA architecture, due to the support for disconnected transactions - changes can be stored and applied to the data source at the appropriate time. Also HydraSDO binary objects can be streamed from one machine to another, without the added performance overhead of serializing XML.

    In terms of performance, we found in testing that HydraSDO for XML (C++) uses a considerably smaller memory footprint than other C++ XML parsers (50% of that required by Xerces C++ even with SAX) and has comparable performance for the number of transactions per second (reading an element from an XML file).

    I’m not suggesting that SDO is appropriate in all instances, but where there are multiple data formats, or the application is part of a larger SOA architecture, or where memory resources are limited, it can form part of a solution.

    —-

    Any comments or suggestions much appreciated.

    Regards

    Dean

  3. David Haney Says:

    SDO does provide support for native C/C++ types, it just wasn’t demonstrated in the example above. For the scenario Boris described (increasing the coupon rate by 0.01), you can write code like the following:

    bond->setDouble(”couponRate”, body->getDouble(”couponRate”) + 0.01);

Leave a Reply