Serialization Demo

This document explains how to build an environment supporting export/import from/to Excel/C++ on Windows/Linux.

For the Excel portions of this tutorial you can use either the QuantLibXL Addin that was delivered by the binary installer, or one that you compile yourself using the tutorial Build QuantLibXL From Source Code.

For the C++ portions of this tutorial you must compile the QuantLibAddin C++ environment as described in tutorial Build A QuantLibAddin C++ Environment on Windows and/or Linux.

Different versions of Boost create serialization files in different formats. If the application that imports the XML is compiled against a different version of Boost than the application that exported the XML, then the import fails with stream error. The export files created for this demo were generated from binaries that were compiled against Boost 1.35.0. The binary release of QuantLibXL was compiled against Boost 1.35.0. If you're using a different version of Boost then you need to re-export the demo files before attempting the import.

1 Windows
1.1 Excel
1.1.1 Export
1.1.2 Import
1.2 C++
1.2.1 Export
1.2.2 Import
2 Linux
2.1 C++
2.1.1 Export
2.1.2 Import

1 Windows

1.1 Excel

1.1.1 Export

  • Start Excel
  • Load VBA addin QuantLibXL\framework2\QuantLibXL.xla. The addin contains some startup code which should automatically load the following:
    QuantLibXL\xll\QuantLibXL-vc90-mt-1_22_0.xll
    QuantLibXL\framework2\addin\*.xla
    
  • Invoke menu item QuantLibXL | Load | Serialization Demo. This loads the following:
    QuantLibXL\framework2\workbooks\SerializationDemo.xls
    
  • Hit Ctrl-Alt-F9
  • Confirm that a PV (on my machine, -39,396.95) is showing in cell [SerializationDemo.xls]Swap!$F$14
  • Activate sheet Serialization and invoke menu item QuantLibXL | Serialization Demo | Export
  • The following 2 files are produced:
    QuantLibXL\framework2\xml\MarketData.xml
    QuantLibXL\framework2\xml\Swap.xml
    

1.1.2 Import

  • Start Excel
  • Load VBA addin QuantLibXL\framework2\QuantLibXL.xla. The addin contains some startup code which should automatically load the following:
    QuantLibXL\xll\QuantLibXL-vc90-mt-1_22_0.xll
    QuantLibXL\framework2\addin\*.xla
    
  • Invoke menu item QuantLibXL | Load | Serialization Demo. This loads the following:
    QuantLibXL\framework2\workbooks\SerializationDemo.xls
    
  • Set range [SerializationDemo.xls]Settings!$H$15 to Import
  • Activate sheet Serialization and invoke menu item QuantLibXL | Serialization Demo | Import
  • The following 2 files are loaded:
    QuantLibXL\framework2\xml\MarketData.xml
    QuantLibXL\framework2\xml\Swap.xml
    
  • Hit Ctrl-Alt-F9
  • Confirm that a PV (on my machine, -39,396.95) is showing in cell [SerializationDemo.xls]Swap!$F$14

If switching back and forth between import and export during a single Excel session you can use the command QuantLibXL | ObjectHandler | Delete All Objects to ensure that the ObjectHandler repository is empty. You can confirm this by ensuring that command QuantLibXL | ObjectHandler | Object Count returns zero.

1.2 C++

1.2.1 Export

Open a DOS prompt in directory QuantLibAddin\Clients\CppSwapOut. Invoke the executable. The output from the program should appear as follows:

Begin example program.
QuantLibAddin version = 1.22.0
ObjectHandler version = 1.22.0
SWAP PV = -39396.9
Example of serializing to/from a buffer:
XML =
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="5">
<object_list class_id="1" tracking_level="1" version="0" object_id="_0">
        <count>1</count>
        <item_version>1</item_version>
        <item class_id="0" tracking_level="0" version="1">
                <px class_id="166" tracking_level="1" version="0" object_id="_1">
                        <ObjectId>quote1</ObjectId>
                        <ClassName>qlSimpleQuote</ClassName>
                        <Value>1.23</Value>
                        <TickValue>0</TickValue>
                        <Permanent>0</Permanent>
                        <UserProperties class_id="234" tracking_level="0"
                            version="0">
                                <count>0</count>
                                <item_version>0</item_version>
                        </UserProperties>
                </px>
        </item>
</object_list>
</boost_serialization>


INFO - log dump of object with ID = quote1

property = Permanent            value = 0
property = TickValue            value = 0
property = Value                value = 1.23
Permanent = false


End example program.

The program generates the XML export files Swap.xml and MarketData.xml in the current directory.

1.2.2 Import

Open a DOS prompt in directory QuantLibAddin\Clients\CppInstrumentIn. Invoke batch file price_Swap.bat. The program loads the following 2 files:

QuantLibAddin\Clients\CppInstrumentIn\MarketData\MarketData.xml
QuantLibAddin\Clients\CppInstrumentIn\Models\Swap.xml

The output from the program should appear as follows:

QuantLibAddin\Clients\CppInstrumentIn>InstrumentIn-vc90-mt.exe
    40546 Swap Swap.xml MarketData.xml
Begin example program.
QuantLibAddin version = 1.22.0
ObjectHandler version = 1.22.0
Instrument PV = -39396.9
End example program.

2 Linux

2.1 C++

2.1.1 Export

cd to directory QuantLibAddin/Clients/CppSwapOut and execute program swap_out. The output from the program should appear as follows:

Begin example program.
QuantLibAddin version = 1.22.0
ObjectHandler version = 1.22.0
SWAP PV = -39396.9
Example of serializing to/from a buffer:
XML =
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="5">
<object_list class_id="1" tracking_level="1" version="0" object_id="_0">
        <count>1</count>
        <item_version>1</item_version>
        <item class_id="0" tracking_level="0" version="1">
                <px class_id="166" tracking_level="1" version="0" object_id="_1">
                        <ObjectId>quote1</ObjectId>
                        <ClassName>qlSimpleQuote</ClassName>
                        <Value>1.23</Value>
                        <TickValue>0</TickValue>
                        <Permanent>0</Permanent>
                        <UserProperties class_id="234" tracking_level="0"
                            version="0">
                                <count>0</count>
                                <item_version>0</item_version>
                        </UserProperties>
                </px>
        </item>
</object_list>
</boost_serialization>


INFO - log dump of object with ID = quote1

property = Permanent            value = 0
property = TickValue            value = 0
property = Value                value = 1.23
Permanent = false


End example program.

The program generates the XML export files Swap.xml and MarketData.xml in the current directory.

2.1.2 Import

cd to directory QuantLibAddin/Clients/CppInstrumentIn. Invoke shell script price_Swap.sh. The program loads the following 2 files:

QuantLibAddin/Clients/CppInstrumentIn/MarketData/MarketData.xml
QuantLibAddin/Clients/CppInstrumentIn/Models/Swap.xml

The output from the program should appear as follows:

QuantLibAddin\Clients\CppInstrumentIn>./instrument_in
    40546 Swap Swap.xml MarketData.xml
Begin example program.
QuantLibAddin version = 1.22.0
ObjectHandler version = 1.22.0
Instrument PV = -39396.9
End example program.