How to serialize an object in Quantlibxl?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to serialize an object in Quantlibxl?

cheng li

Hi All,

 

I am using Quantlibxl to build our own yield curves. Now I am facing one problem. I do succeed in building the curve use qlPiecewiseYieldCurve. Then I want to save that curve to my local driver for future use. I looked into the function categories of Quantlibxl and found that function ohObjectSave may meet my purpose. Unfortunately after I serialized the yield curve to my own folder successfully, I was not able to deserialize that file by ohObjectLoad/ ohObjectLoadString, my sample input is as follows, I am using Quantlibxl 1.1.0 and Office 2010

 

Serialization: ohObjectSave(“CNY_Treasury_Curve_2008-1-2”, “F:\data\Curve\StandaloneCurves\CNY_Treasury_Curve_2008-1-2.xml”, TRUE)

Deserialization: ohObjectLoadString(“F:\data\Curve\StandaloneCurves\CNY_Treasury_Curve_2008-1-2.xml”, TRUE)

 

Besides, another question, the outputted .xml file seems no enough information to reconstruct a curve. It only contains the parameters which are used to construct that object, one sample file are as follows: the file contains the object names of the rate helpers without the detail info on the rate helpers.

 

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<!DOCTYPE boost_serialization>

<boost_serialization signature="serialization::archive" version="8">

<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="140" tracking_level="1" version="0" object_id="_1">

                            <ObjectId>CNY_Treasury_Curve_2008-1-2</ObjectId>

                            <ClassName>qlPiecewiseYieldCurve</ClassName>

                            <NDays>0</NDays>

                            <Calendar>China</Calendar>

                            <RateHelpers class_id="236" tracking_level="0" version="0">

                                     <count>21</count>

                                     <item_version>0</item_version>

                                     <item>060001.IB_.0251_2006-3-8_2013-2-27_7Y_helper</item>

                                     <item>060003.IB_.028_2006-4-5_2016-3-27_10Y_helper</item>

                                     <item>060019.IB_.0327_2006-11-23_2021-11-15_15Y_helper</item>

                                     <item>0700002.IB_.0468_2007-9-27_2022-9-18_15Y_helper</item>

                                     <item>0700004.IB_.0455_2007-10-12_2022-9-29_15Y_helper</item>

                                     <item>0700006.IB_.0469_2007-11-26_2022-11-19_15Y_helper</item>

                                     <item>0700008.IB_.0441_2007-12-24_2017-12-17_10Y_helper</item>

                                     <item>070014.IB_.039_2007-8-31_2014-8-23_7Y_helper</item>

                                     <item>070017.IB_.04_2007-10-29_2012-10-22_5Y_helper</item>

                                     <item>070018.IB_.0435_2007-12-5_2014-11-26_7Y_helper</item>

                                     <item>070002.IB_.021_2007-3-22_2008-3-15_1Y_helper</item>

                                     <item>070016.IB_.0295_2007-9-20_2008-9-13_1Y_helper</item>

                                     <item>070020.IB_.0366_2007-12-19_2008-12-13_1Y_helper</item>

                                     <item>040003.IB_.0442_2004-4-30_2009-4-20_5Y_helper</item>

                                     <item>9902.IB_.0472_1999-5-19_2009-4-29_10Y_helper</item>

                                     <item>030001.IB_.0266_2003-2-26_2010-2-19_7Y_helper</item>

                                     <item>030007.IB_.0266_2003-9-1_2010-8-20_7Y_helper</item>

                                     <item>060018.IB_.0248_2006-11-3_2011-10-25_5Y_helper</item>

                                     <item>070005.IB_.0318_2007-4-30_2012-4-23_5Y_helper</item>

                                     <item>050005.IB_.0337_2005-6-3_2012-5-25_7Y_helper</item>

                                     <item>020009.IB_.027_2002-7-30_2012-7-19_10Y_helper</item>

                            </RateHelpers>

                            <DayCounter>Bond Basis</DayCounter>

                            <Jumps class_id="237" tracking_level="0" version="0">

                                     <count>0</count>

                                     <item_version>0</item_version>

                            </Jumps>

                            <JumpDates>

                                     <count>0</count>

                                     <item_version>0</item_version>

                            </JumpDates>

                            <Accuracy>9.9999999999999998e-013</Accuracy>

                            <TraitsID>ZeroYield</TraitsID>

                            <InterpolatorID>Linear</InterpolatorID>

                            <Permanent>0</Permanent>

                            <UserProperties class_id="238" tracking_level="0" version="0">

                                     <count>0</count>

                                     <item_version>0</item_version>

                            </UserProperties>

                   </px>

         </item>

</object_list>

</boost_serialization>

 

Regards,

Cheng


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

R: How to serialize an object in Quantlibxl?

Ballabio Gerardo-4

Deserialization fails because the serialized object depends on other objects (rate helpers, indexes etc.), ohObjectLoad expects to find them too, and if they aren’t there it bails out. The curve must be serialized together with all the objects it depends on. You might think ohObjectSave would do that automatically but it doesn’t, it only serializes the objects that you explicitly tell it to. Accordingly, the .xml file contains the internal data of the curve and nothing else.

 

As an alternative, after building the curve, you may extract the computed data points with qlPiecewiseYieldCurveDates and qlPiecewiseYieldCurveData, then feed them to qlInterpolatedYieldCurve. This will generate a curve that doesn’t depend on any other objects and can be serialized alone. However in doing so you’ll lose the links to the underlying objects: if you change the value of a rate helper the curve will not be updated. You can’t have it both ways, either it depends on them or it doesn’t.

 

Gerardo

 

 

Da: Cheng Li [mailto:[hidden email]]
Inviato: giovedì 9 agosto 2012 13.04
A: [hidden email]
Oggetto: [Quantlib-users] How to serialize an object in Quantlibxl?

 

Hi All,

 

I am using Quantlibxl to build our own yield curves. Now I am facing one problem. I do succeed in building the curve use qlPiecewiseYieldCurve. Then I want to save that curve to my local driver for future use. I looked into the function categories of Quantlibxl and found that function ohObjectSave may meet my purpose. Unfortunately after I serialized the yield curve to my own folder successfully, I was not able to deserialize that file by ohObjectLoad/ ohObjectLoadString, my sample input is as follows, I am using Quantlibxl 1.1.0 and Office 2010

 

Serialization: ohObjectSave(“CNY_Treasury_Curve_2008-1-2”, “F:\data\Curve\StandaloneCurves\CNY_Treasury_Curve_2008-1-2.xml”, TRUE)

Deserialization: ohObjectLoadString(“F:\data\Curve\StandaloneCurves\CNY_Treasury_Curve_2008-1-2.xml”, TRUE)

 

Besides, another question, the outputted .xml file seems no enough information to reconstruct a curve. It only contains the parameters which are used to construct that object, one sample file are as follows: the file contains the object names of the rate helpers without the detail info on the rate helpers.

 

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<!DOCTYPE boost_serialization>

<boost_serialization signature="serialization::archive" version="8">

<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="140" tracking_level="1" version="0" object_id="_1">

                            <ObjectId>CNY_Treasury_Curve_2008-1-2</ObjectId>

                            <ClassName>qlPiecewiseYieldCurve</ClassName>

                            <NDays>0</NDays>

                            <Calendar>China</Calendar>

                            <RateHelpers class_id="236" tracking_level="0" version="0">

                                     <count>21</count>

                                     <item_version>0</item_version>

                                     <item>060001.IB_.0251_2006-3-8_2013-2-27_7Y_helper</item>

                                     <item>060003.IB_.028_2006-4-5_2016-3-27_10Y_helper</item>

                                     <item>060019.IB_.0327_2006-11-23_2021-11-15_15Y_helper</item>

                                     <item>0700002.IB_.0468_2007-9-27_2022-9-18_15Y_helper</item>

                                     <item>0700004.IB_.0455_2007-10-12_2022-9-29_15Y_helper</item>

                                     <item>0700006.IB_.0469_2007-11-26_2022-11-19_15Y_helper</item>

                                     <item>0700008.IB_.0441_2007-12-24_2017-12-17_10Y_helper</item>

                                     <item>070014.IB_.039_2007-8-31_2014-8-23_7Y_helper</item>

                                     <item>070017.IB_.04_2007-10-29_2012-10-22_5Y_helper</item>

                                     <item>070018.IB_.0435_2007-12-5_2014-11-26_7Y_helper</item>

                                     <item>070002.IB_.021_2007-3-22_2008-3-15_1Y_helper</item>

                                     <item>070016.IB_.0295_2007-9-20_2008-9-13_1Y_helper</item>

                                     <item>070020.IB_.0366_2007-12-19_2008-12-13_1Y_helper</item>

                                     <item>040003.IB_.0442_2004-4-30_2009-4-20_5Y_helper</item>

                                     <item>9902.IB_.0472_1999-5-19_2009-4-29_10Y_helper</item>

                                     <item>030001.IB_.0266_2003-2-26_2010-2-19_7Y_helper</item>

                                     <item>030007.IB_.0266_2003-9-1_2010-8-20_7Y_helper</item>

                                     <item>060018.IB_.0248_2006-11-3_2011-10-25_5Y_helper</item>

                                     <item>070005.IB_.0318_2007-4-30_2012-4-23_5Y_helper</item>

                                     <item>050005.IB_.0337_2005-6-3_2012-5-25_7Y_helper</item>

                                     <item>020009.IB_.027_2002-7-30_2012-7-19_10Y_helper</item>

                            </RateHelpers>

                            <DayCounter>Bond Basis</DayCounter>

                            <Jumps class_id="237" tracking_level="0" version="0">

                                     <count>0</count>

                                     <item_version>0</item_version>

                            </Jumps>

                            <JumpDates>

                                     <count>0</count>

                                     <item_version>0</item_version>

                            </JumpDates>

                            <Accuracy>9.9999999999999998e-013</Accuracy>

                            <TraitsID>ZeroYield</TraitsID>

                            <InterpolatorID>Linear</InterpolatorID>

                            <Permanent>0</Permanent>

                            <UserProperties class_id="238" tracking_level="0" version="0">

                                     <count>0</count>

                                     <item_version>0</item_version>

                            </UserProperties>

                   </px>

         </item>

</object_list>

</boost_serialization>

 

 

Regards,

Cheng




Banca Profilo S.p.A. Corso Italia, 49 - 20122 Milano - Tel. 02 58408.1, Fax 02 5831 6057 Capitale Sociale Euro 136.794.106,00 i.v. Iscrizione al Registro Imprese di Milano, C.F. e P.IVA 09108700155 - [hidden email] Iscritta all’Albo delle Banche e dei Gruppi bancari Aderente al Fondo Interbancario di Tutela dei depositi Aderente al Conciliatore Bancario Finanziario e all’Arbitro Bancario Finanziario Appartenente al Gruppo bancario Banca Profilo e soggetta all’attività di direzione e coordinamento di Arepo BP S.p.A. DISCLAIMER: The information transmitted may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: R: How to serialize an object in Quantlibxl?

Bojan Nikolic

There is a function ohProjectPrecedentIDs() which retrieves the IDs of
dependencies of an object. So it is possible to use this function to
script an automatic complete serialisation of an object.

Best,
Bojan

--
Bojan Nikolic          ||          http://www.bnikolic.co.uk

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

答复: R: How to serialize an object in Quantlibxl?

cheng li
In reply to this post by Ballabio Gerardo-4

Thanks for you detailed explanation. It really solves my problem!

 

发件人: Ballabio Gerardo [mailto:[hidden email]]
发送时间: 201289 20:07
收件人: [hidden email]
主题: [Quantlib-users] R: How to serialize an object in Quantlibxl?

 

Deserialization fails because the serialized object depends on other objects (rate helpers, indexes etc.), ohObjectLoad expects to find them too, and if they aren’t there it bails out. The curve must be serialized together with all the objects it depends on. You might think ohObjectSave would do that automatically but it doesn’t, it only serializes the objects that you explicitly tell it to. Accordingly, the .xml file contains the internal data of the curve and nothing else.

 

As an alternative, after building the curve, you may extract the computed data points with qlPiecewiseYieldCurveDates and qlPiecewiseYieldCurveData, then feed them to qlInterpolatedYieldCurve. This will generate a curve that doesn’t depend on any other objects and can be serialized alone. However in doing so you’ll lose the links to the underlying objects: if you change the value of a rate helper the curve will not be updated. You can’t have it both ways, either it depends on them or it doesn’t.

 

Gerardo

 

 

Da: Cheng Li [mailto:[hidden email]]
Inviato: giovedì 9 agosto 2012 13.04
A: [hidden email]
Oggetto: [Quantlib-users] How to serialize an object in Quantlibxl?

 

Hi All,

 

I am using Quantlibxl to build our own yield curves. Now I am facing one problem. I do succeed in building the curve use qlPiecewiseYieldCurve. Then I want to save that curve to my local driver for future use. I looked into the function categories of Quantlibxl and found that function ohObjectSave may meet my purpose. Unfortunately after I serialized the yield curve to my own folder successfully, I was not able to deserialize that file by ohObjectLoad/ ohObjectLoadString, my sample input is as follows, I am using Quantlibxl 1.1.0 and Office 2010

 

Serialization: ohObjectSave(“CNY_Treasury_Curve_2008-1-2”, “F:\data\Curve\StandaloneCurves\CNY_Treasury_Curve_2008-1-2.xml”, TRUE)

Deserialization: ohObjectLoadString(“F:\data\Curve\StandaloneCurves\CNY_Treasury_Curve_2008-1-2.xml”, TRUE)

 

Besides, another question, the outputted .xml file seems no enough information to reconstruct a curve. It only contains the parameters which are used to construct that object, one sample file are as follows: the file contains the object names of the rate helpers without the detail info on the rate helpers.

 

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<!DOCTYPE boost_serialization>

<boost_serialization signature="serialization::archive" version="8">

<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="140" tracking_level="1" version="0" object_id="_1">

                            <ObjectId>CNY_Treasury_Curve_2008-1-2</ObjectId>

                            <ClassName>qlPiecewiseYieldCurve</ClassName>

                            <NDays>0</NDays>

                            <Calendar>China</Calendar>

                            <RateHelpers class_id="236" tracking_level="0" version="0">

                                     <count>21</count>

                                     <item_version>0</item_version>

                                     <item>060001.IB_.0251_2006-3-8_2013-2-27_7Y_helper</item>

                                     <item>060003.IB_.028_2006-4-5_2016-3-27_10Y_helper</item>

                                     <item>060019.IB_.0327_2006-11-23_2021-11-15_15Y_helper</item>

                                     <item>0700002.IB_.0468_2007-9-27_2022-9-18_15Y_helper</item>

                                     <item>0700004.IB_.0455_2007-10-12_2022-9-29_15Y_helper</item>

                                     <item>0700006.IB_.0469_2007-11-26_2022-11-19_15Y_helper</item>

                                     <item>0700008.IB_.0441_2007-12-24_2017-12-17_10Y_helper</item>

                                     <item>070014.IB_.039_2007-8-31_2014-8-23_7Y_helper</item>

                                     <item>070017.IB_.04_2007-10-29_2012-10-22_5Y_helper</item>

                                     <item>070018.IB_.0435_2007-12-5_2014-11-26_7Y_helper</item>

                                     <item>070002.IB_.021_2007-3-22_2008-3-15_1Y_helper</item>

                                     <item>070016.IB_.0295_2007-9-20_2008-9-13_1Y_helper</item>

                                     <item>070020.IB_.0366_2007-12-19_2008-12-13_1Y_helper</item>

                                     <item>040003.IB_.0442_2004-4-30_2009-4-20_5Y_helper</item>

                                     <item>9902.IB_.0472_1999-5-19_2009-4-29_10Y_helper</item>

                                     <item>030001.IB_.0266_2003-2-26_2010-2-19_7Y_helper</item>

                                     <item>030007.IB_.0266_2003-9-1_2010-8-20_7Y_helper</item>

                                     <item>060018.IB_.0248_2006-11-3_2011-10-25_5Y_helper</item>

                                     <item>070005.IB_.0318_2007-4-30_2012-4-23_5Y_helper</item>

                                     <item>050005.IB_.0337_2005-6-3_2012-5-25_7Y_helper</item>

                                     <item>020009.IB_.027_2002-7-30_2012-7-19_10Y_helper</item>

                            </RateHelpers>

                            <DayCounter>Bond Basis</DayCounter>

                            <Jumps class_id="237" tracking_level="0" version="0">

                                     <count>0</count>

                                     <item_version>0</item_version>

                            </Jumps>

                            <JumpDates>

                                     <count>0</count>

                                     <item_version>0</item_version>

                            </JumpDates>

                            <Accuracy>9.9999999999999998e-013</Accuracy>

                            <TraitsID>ZeroYield</TraitsID>

                            <InterpolatorID>Linear</InterpolatorID>

                            <Permanent>0</Permanent>

                            <UserProperties class_id="238" tracking_level="0" version="0">

                                     <count>0</count>

                                     <item_version>0</item_version>

                            </UserProperties>

                   </px>

         </item>

</object_list>

</boost_serialization>

 

 

Regards,

Cheng

 
 
 
 
 
Banca Profilo S.p.A.
Corso Italia, 49 - 20122 Milano - Tel. 02 58408.1, Fax 02 5831 6057
Capitale Sociale Euro 136.794.106,00 i.v.
Iscrizione al Registro Imprese di Milano, C.F. e P.IVA 09108700155 - [hidden email]
Iscritta all’Albo delle Banche e dei Gruppi bancari
Aderente al Fondo Interbancario di Tutela dei depositi
Aderente al Conciliatore Bancario Finanziario e all’Arbitro Bancario Finanziario
Appartenente al Gruppo bancario Banca Profilo e soggetta all’attività di direzione e coordinamento di Arepo BP S.p.A.
 
 
DISCLAIMER:
The information transmitted may contain confidential and/or privileged material.
Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, 
this information by persons or entities other than the intended recipient is prohibited. 
If you received this in error, please contact the sender and delete the material from any computer.
 
 
 

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

答复: R: How to serialize an object in Quantlibxl?

cheng li
In reply to this post by Bojan Nikolic
I'll try this way. Thank you.

-----邮件原件-----
发件人: Bojan Nikolic [mailto:[hidden email]]
发送时间: 2012年8月9日 20:38
收件人: Ballabio Gerardo
抄送: [hidden email]
主题: Re: [Quantlib-users] R: How to serialize an object in Quantlibxl?


There is a function ohProjectPrecedentIDs() which retrieves the IDs of
dependencies of an object. So it is possible to use this function to script
an automatic complete serialisation of an object.

Best,
Bojan

--
Bojan Nikolic          ||          http://www.bnikolic.co.uk

----------------------------------------------------------------------------
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat
landscape has changed and how IT managers can respond. Discussions will
include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users