Implement Bermudan swaption in QuantLibXL

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

Implement Bermudan swaption in QuantLibXL

Hyung-Seok Hahm
Hi all,

I'm trying to implement Bermudan swaption in QuantLibXL. 

There is a swaption example, named InterestRateDerivatives.xls as one of the StandaloneExamples in QuantLIbXL. Plus, there is another example for Bermudan swaption named BermudanSwaption.cpp as one of the Quantlib examples.

Basically what I'm trying to do is fill in the gap between these two examples. The problem lies in the fact that ShortRateModel and CalibrationHelper have not been implemented yet. To be more specific, I need to implement the following segment in BermudanSwaption.cpp.

void calibrateModel(
          const boost::shared_ptr<ShortRateModel>& model,
          const std::vector<boost::shared_ptr<CalibrationHelper> >& helpers) {

    LevenbergMarquardt om;
    model->calibrate(helpers, om,
                     EndCriteria(400, 100, 1.0e-8, 1.0e-8, 1.0e-8));

    // Output the implied Black volatilities
    for (Size i=0; i<numRows; i++) {
        Size j = numCols - i -1; // 1x5, 2x4, 3x3, 4x2, 5x1
        Size k = i*numCols + j;
        Real npv = helpers[i]->modelValue();
        Volatility implied = helpers[i]->impliedVolatility(npv, 1e-4,
                                                           100000, 0.05, 0.50);
        Volatility diff = implied - swaptionVols[k];

        std::cout << i+1 << "x" << swapLenghts[j]
                  << std::setprecision(5) << std::noshowpos
                  << ": model " << std::setw(7) << io::volatility(implied)
                  << ", market " << std::setw(7)
                  << io::volatility(swaptionVols[k])
                  << " (" << std::setw(7) << std::showpos
                  << io::volatility(diff) << std::noshowpos << ")\n";
    }
}

I do not have a clue how to expose model->calibrate part in QuantLibXL. 

I've been struggling with this for days, so any suggestion would be appreciatedl.

Thanks.

- Hyung


------------------------------------------------------------------------------
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: Implement Bermudan swaption in QuantLibXL

Eric Ehlers-2
Hi Hyung,

Have you seen the document below?

http://quantlib.org/quantlibaddin/extend_tutorial.html

Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid

Quoting Hyung-Seok Hahm <[hidden email]>:

> Hi all,
>
> I'm trying to implement Bermudan swaption in QuantLibXL.
>
> There is a swaption example, named InterestRateDerivatives.xls as one of
> the StandaloneExamples in QuantLIbXL. Plus, there is another example for
> Bermudan swaption named BermudanSwaption.cpp as one of the Quantlib
> examples.
>
> Basically what I'm trying to do is fill in the gap between these two
> examples. The problem lies in the fact that ShortRateModel and
> CalibrationHelper have not been implemented yet. To be more specific, I
> need to implement the following segment in BermudanSwaption.cpp.
>
> void calibrateModel(
>           const boost::shared_ptr<ShortRateModel>& model,
>           const std::vector<boost::shared_ptr<CalibrationHelper> >&
> helpers) {
>
>     LevenbergMarquardt om;
> *    model->calibrate(helpers, om,*
> *                     EndCriteria(400, 100, 1.0e-8, 1.0e-8, 1.0e-8));*
>
>     // Output the implied Black volatilities
>     for (Size i=0; i<numRows; i++) {
>         Size j = numCols - i -1; // 1x5, 2x4, 3x3, 4x2, 5x1
>         Size k = i*numCols + j;
>         Real npv = helpers[i]->modelValue();
>         Volatility implied = helpers[i]->impliedVolatility(npv, 1e-4,
>                                                            100000, 0.05,
> 0.50);
>         Volatility diff = implied - swaptionVols[k];
>
>         std::cout << i+1 << "x" << swapLenghts[j]
>                   << std::setprecision(5) << std::noshowpos
>                   << ": model " << std::setw(7) << io::volatility(implied)
>                   << ", market " << std::setw(7)
>                   << io::volatility(swaptionVols[k])
>                   << " (" << std::setw(7) << std::showpos
>                   << io::volatility(diff) << std::noshowpos << ")\n";
>     }
> }
>
> I do not have a clue how to expose model->calibrate part in QuantLibXL.
>
> I've been struggling with this for days, so any suggestion would be
> appreciatedl.
>
> Thanks.
>
> - Hyung
>


------------------------------------------------------------------------------
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: Implement Bermudan swaption in QuantLibXL

Hyung-Seok Hahm
Hi Eric,

Yes, I have and I have successfully exposed simple classes such as Stock before. 

However, I believe this case is more complicated. As I understand, in order to run the following segment of the code, three building blocks have been exposed. 

>
    model->calibrate(helpers, om,
                     EndCriteria(400, 100, 1.0e-8, 1.0e-8, 1.0e-8));

>

Here is the breakdown.

(1) model is a ShortRateModel object and has not been exposed in QuantLibXL
(2) helpers is a CalibrationHelper object and has not been exposed
(3) om is a LevenbergMarquart object and HAS BEEN exposed
(4) EndCriteria HAS BEEN exposed

So now the question is how to expose ShortRateModel and CalibrationHelper.

There are 2 kinds of tutorials written by you. 

One for template classes 

and the other for simple classes

I believe ShortRateModel qualifies for simple classes and CalibrationHelper for template classes. Am I on the right track?

Or if you have any better ways, please enlighten me. 

Thanks!

- Hyung



On Wed, Jul 4, 2012 at 4:40 AM, Eric Ehlers <[hidden email]> wrote:
Hi Hyung,

Have you seen the document below?

http://quantlib.org/quantlibaddin/extend_tutorial.html

Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid

Quoting Hyung-Seok Hahm <[hidden email]>:

> Hi all,
>
> I'm trying to implement Bermudan swaption in QuantLibXL.
>
> There is a swaption example, named InterestRateDerivatives.xls as one of
> the StandaloneExamples in QuantLIbXL. Plus, there is another example for
> Bermudan swaption named BermudanSwaption.cpp as one of the Quantlib
> examples.
>
> Basically what I'm trying to do is fill in the gap between these two
> examples. The problem lies in the fact that ShortRateModel and
> CalibrationHelper have not been implemented yet. To be more specific, I
> need to implement the following segment in BermudanSwaption.cpp.
>
> void calibrateModel(
>           const boost::shared_ptr<ShortRateModel>& model,
>           const std::vector<boost::shared_ptr<CalibrationHelper> >&
> helpers) {
>
>     LevenbergMarquardt om;
> *    model->calibrate(helpers, om,*
> *                     EndCriteria(400, 100, 1.0e-8, 1.0e-8, 1.0e-8));*
>
>     // Output the implied Black volatilities
>     for (Size i=0; i<numRows; i++) {
>         Size j = numCols - i -1; // 1x5, 2x4, 3x3, 4x2, 5x1
>         Size k = i*numCols + j;
>         Real npv = helpers[i]->modelValue();
>         Volatility implied = helpers[i]->impliedVolatility(npv, 1e-4,
>                                                            100000, 0.05,
> 0.50);
>         Volatility diff = implied - swaptionVols[k];
>
>         std::cout << i+1 << "x" << swapLenghts[j]
>                   << std::setprecision(5) << std::noshowpos
>                   << ": model " << std::setw(7) << io::volatility(implied)
>                   << ", market " << std::setw(7)
>                   << io::volatility(swaptionVols[k])
>                   << " (" << std::setw(7) << std::showpos
>                   << io::volatility(diff) << std::noshowpos << ")\n";
>     }
> }
>
> I do not have a clue how to expose model->calibrate part in QuantLibXL.
>
> I've been struggling with this for days, so any suggestion would be
> appreciatedl.
>
> Thanks.
>
> - Hyung
>


------------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: Implement Bermudan swaption in QuantLibXL

Hyung-Seok Hahm
After sending the last one, I've found out that HullWhite and Vasicek derived from ShortRateModel have been exposed. 

Then the remaining part I guess is how to expose

(1) CalibrationHelper class 
(2) ShortRateModel->calibrate

I will follow the tutorial for template classes for (1). 

And I do not have a clue how to deal with (2), but think the closest function among already exposed is qlCTSMMCapletCalibrationCalibrate (), so I will try to reengineer it.

In the meantime, if you have any tips, please let me know.

Thanks!

- Hyung

On Wed, Jul 4, 2012 at 10:16 AM, Hyung-Seok Hahm <[hidden email]> wrote:
Hi Eric,

Yes, I have and I have successfully exposed simple classes such as Stock before. 

However, I believe this case is more complicated. As I understand, in order to run the following segment of the code, three building blocks have been exposed. 

>
    model->calibrate(helpers, om,
                     EndCriteria(400, 100, 1.0e-8, 1.0e-8, 1.0e-8));

>

Here is the breakdown.

(1) model is a ShortRateModel object and has not been exposed in QuantLibXL
(2) helpers is a CalibrationHelper object and has not been exposed
(3) om is a LevenbergMarquart object and HAS BEEN exposed
(4) EndCriteria HAS BEEN exposed

So now the question is how to expose ShortRateModel and CalibrationHelper.

There are 2 kinds of tutorials written by you. 

One for template classes 

and the other for simple classes

I believe ShortRateModel qualifies for simple classes and CalibrationHelper for template classes. Am I on the right track?

Or if you have any better ways, please enlighten me. 

Thanks!

- Hyung



On Wed, Jul 4, 2012 at 4:40 AM, Eric Ehlers <[hidden email]> wrote:
Hi Hyung,

Have you seen the document below?

http://quantlib.org/quantlibaddin/extend_tutorial.html

Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid

Quoting Hyung-Seok Hahm <[hidden email]>:

> Hi all,
>
> I'm trying to implement Bermudan swaption in QuantLibXL.
>
> There is a swaption example, named InterestRateDerivatives.xls as one of
> the StandaloneExamples in QuantLIbXL. Plus, there is another example for
> Bermudan swaption named BermudanSwaption.cpp as one of the Quantlib
> examples.
>
> Basically what I'm trying to do is fill in the gap between these two
> examples. The problem lies in the fact that ShortRateModel and
> CalibrationHelper have not been implemented yet. To be more specific, I
> need to implement the following segment in BermudanSwaption.cpp.
>
> void calibrateModel(
>           const boost::shared_ptr<ShortRateModel>& model,
>           const std::vector<boost::shared_ptr<CalibrationHelper> >&
> helpers) {
>
>     LevenbergMarquardt om;
> *    model->calibrate(helpers, om,*
> *                     EndCriteria(400, 100, 1.0e-8, 1.0e-8, 1.0e-8));*
>
>     // Output the implied Black volatilities
>     for (Size i=0; i<numRows; i++) {
>         Size j = numCols - i -1; // 1x5, 2x4, 3x3, 4x2, 5x1
>         Size k = i*numCols + j;
>         Real npv = helpers[i]->modelValue();
>         Volatility implied = helpers[i]->impliedVolatility(npv, 1e-4,
>                                                            100000, 0.05,
> 0.50);
>         Volatility diff = implied - swaptionVols[k];
>
>         std::cout << i+1 << "x" << swapLenghts[j]
>                   << std::setprecision(5) << std::noshowpos
>                   << ": model " << std::setw(7) << io::volatility(implied)
>                   << ", market " << std::setw(7)
>                   << io::volatility(swaptionVols[k])
>                   << " (" << std::setw(7) << std::showpos
>                   << io::volatility(diff) << std::noshowpos << ")\n";
>     }
> }
>
> I do not have a clue how to expose model->calibrate part in QuantLibXL.
>
> I've been struggling with this for days, so any suggestion would be
> appreciatedl.
>
> Thanks.
>
> - Hyung
>


------------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: Implement Bermudan swaption in QuantLibXL

Eric Ehlers-2
Hi Hyung,

Quoting Hyung-Seok Hahm <[hidden email]>:

> After sending the last one, I've found out that HullWhite and Vasicek
> derived from ShortRateModel have been exposed.
>
> Then the remaining part I guess is how to expose
>
> (1) CalibrationHelper class
> (2) ShortRateModel->calibrate
>
> I will follow the tutorial for template classes for (1).
>
> And I do not have a clue how to deal with (2), but think the closest
> function among already exposed is qlCTSMMCapletCalibrationCalibrate (), so
> I will try to reengineer it.
>
> In the meantime, if you have any tips, please let me know.

At first glance it looks to me like you are on the right track.  
Please let us know how it goes.

Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid


------------------------------------------------------------------------------
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: Implement Bermudan swaption in QuantLibXL

Hyung-Seok Hahm
Hi Eric,

CalibrationHelper/SwaptionHelper classes have been successfully exposed and I'm playing around them in Excel. 

At the moment, I've push-backed 10 by 7 swaption vols in SwaptionHelper and all but one work well - what I mean is that every swaption swaptionhelper has been created/returned fine in Excel along with relevant inputs such as swaption maturities, lengths, fixed/floating daycounters, termstructure and so on. 

Only one swaption vol has failed in Excel, but I don't think there is anything wrong in Excel exposing because it generates the same error under QuantLib as well. It happened with the very last swaption vol, 10 year by 10 year and it looks like somehow the swaption maturity over-stretches the termstructure and comes back with an error because extrapolate option is turned off. 

All in all, it looks good so far. I'll figure out the above error and move on  (2) ShortRateModel->calibrate.

Thanks.

- Hyung


On Thu, Jul 5, 2012 at 6:57 PM, Eric Ehlers <[hidden email]> wrote:
Hi Hyung,

Quoting Hyung-Seok Hahm <[hidden email]>:

> After sending the last one, I've found out that HullWhite and Vasicek
> derived from ShortRateModel have been exposed.
>
> Then the remaining part I guess is how to expose
>
> (1) CalibrationHelper class
> (2) ShortRateModel->calibrate
>
> I will follow the tutorial for template classes for (1).
>
> And I do not have a clue how to deal with (2), but think the closest
> function among already exposed is qlCTSMMCapletCalibrationCalibrate (), so
> I will try to reengineer it.
>
> In the meantime, if you have any tips, please let me know.

At first glance it looks to me like you are on the right track.
Please let us know how it goes.

Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid


------------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: Implement Bermudan swaption in QuantLibXL

Hyung-Seok Hahm
Eric,

I'm having trouble with adding Quantlib's model.hpp to QuantLibXL. Here is what I have done so far.

(1) Created model.hpp under \QuantLibAddin\qlo

/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
    Added by Hyungseok 37243 on 2012/07/04
*/

#ifndef qla_model_hpp
#define qla_model_hpp

#include <oh/libraryobject.hpp>


#include <ql/types.hpp>

namespace QuantLib {

    class CalibratedModel;
    class Constraint;
    class CalibrationHelper;
    class EndCriteria;
    class OptimizationMethod;

}

namespace QuantLibAddin {

    class CalibrationHelper : public ObjectHandler::LibraryObject<QuantLib::CalibrationHelper> {
      protected:
        OH_LIB_CTOR(CalibrationHelper, QuantLib::CalibrationHelper);
    };

class CalibratedModel : 
public ObjectHandler::LibraryObject<QuantLib::CalibratedModel> {
      public:
        CalibratedModel(
            const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
            const QuantLib::Size nArguments,
            bool permanent);
        void calibrate(                   
const std::vector<boost::shared_ptr<QuantLib::CalibrationHelper> >& instrument,
            QuantLib::OptimizationMethod &method,
            const QuantLib::EndCriteria &endCriteria,
     const QuantLib::Constraint &additionalConstraint,
       const std::vector<QuantLib::Real>& weights);


};

        OH_LIB_CLASS(OptimizationMethod, QuantLib::OptimizationMethod);
OH_LIB_CLASS(EndCriteria, QuantLib::EndCriteria);
OH_LIB_CLASS(Constraint, QuantLib::Constraint);

}

#endif

(2) Created model.cpp under \QuantLibAddin\qlo 

/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*

  Added by Hyungseok 37243 on 2012/07/04

 */

#if defined(HAVE_CONFIG_H)     // Dynamically created by configure
   #include <qlo/config.hpp>
#endif
#include <qlo/model.hpp>
#include <ql/models/model.hpp>

namespace QuantLibAddin {

        CalibratedModel::CalibratedModel(
            const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
            const QuantLib::Size nArguments,
            bool permanent)
: ObjectHandler::LibraryObject<QuantLib::CalibratedModel>(properties, permanent) {

libraryObject_ = boost::shared_ptr<QuantLib::CalibratedModel>(new
QuantLib::CalibratedModel(nArguments));
}

        void CalibratedModel::calibrate(
  const std::vector<boost::shared_ptr<QuantLib::CalibrationHelper> >& instrument,
                   QuantLib::OptimizationMethod &method,
          const QuantLib::EndCriteria &endCriteria,
    const QuantLib::Constraint &additionalConstraint,
  const std::vector<QuantLib::Real>& weights) {

  libraryObject_->calibrate(instrument, method, endCriteria, additionalConstraint, weights);

}



}

(3) Added in types.xml

    <DataType defaultSuperType='libraryClass'>QuantLib::CalibratedModel</DataType>

(4) Created model.xml under QuantLibAddin\gensrc\metadata\functions

<Category name='model'>
  <description>functions to construct and use model objects.</description>
  <displayName>Model</displayName>
  <xlFunctionWizardCategory>QuantLib - Financial</xlFunctionWizardCategory>
  <serializationIncludes>
    <include>qlo/model.hpp</include>
    <include>ql/models/model.hpp</include>
  </serializationIncludes>
  <addinIncludes>
    <include>qlo/model.hpp</include>
    <include>ql/models/model.hpp</include>
  </addinIncludes>
  <copyright>
    Hyungseok Hahm, 37243
  </copyright>
  
  <Functions>

    <Member name='qlCalibratedModelCalibrate' type='QuantLib::CalibratedModel' superType='libraryClass'>
      <description>calibrate.</description>
      <libraryFunction>calibrate</libraryFunction>
      <SupportedPlatforms>
        <SupportedPlatform name='Excel'/>
        <!--SupportedPlatform name='Cpp'/-->
      </SupportedPlatforms>
      <ParameterList>
        <Parameters>
          <Parameter name='CalibrationHelper' default='""'>
            <type>QuantLib::CalibrationHelper</type>
            <tensorRank>vector</tensorRank>
            <description>Calibration helper ID.</description>
          </Parameter>
          <Parameter name='OptimizationMethod' default='""'>
            <type>QuantLib::OptimizationMethod</type>
            <tensorRank>scalar</tensorRank>
            <description>OptimizationMethod object ID.</description>
          </Parameter>
          <Parameter name='EndCriteria' default='""'>
            <type>QuantLib::EndCriteria</type>
            <tensorRank>scalar</tensorRank>
            <description>EndCriteria object ID.</description>            
          </Parameter>
          <Parameter name='Constraint' default='""'>
            <type>QuantLib::Constraint</type>
            <tensorRank>scalar</tensorRank>
            <description>Leave it blank.</description>
          </Parameter>
          <Parameter name='Weights' default='""'>
            <type>QuantLib::Real</type>
            <tensorRank>vector</tensorRank>
            <description>Leave it blank.</description>
          </Parameter>
        </Parameters>
      </ParameterList>
      <ReturnValue>
        <type>bool</type>
        <tensorRank>scalar</tensorRank>
      </ReturnValue>
    </Member>
  </Functions>
</Category>

Now when I ran it, it auto-generated model.cpp under QuantLibXL\qlxl\functions


/*  
 Hyungseok Hahm, 37243
 
 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <[hidden email]>. The license is also available online at

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

// This file was generated automatically by gensrc.py.  If you edit this file
// manually then your changes will be lost the next time gensrc runs.

// This source code file was generated from the following stub:
//      d:/build_ql_1_1_0/QuantLibAddin/gensrc/stubs/stub.excel.includes

#include <qlo/qladdindefines.hpp>
#include <qlo/model.hpp>
#include <ql/models/model.hpp>

#include <ohxl/objecthandlerxl.hpp>
#include <ohxl/callingrange.hpp>
#include <qlxl/session.hpp>
#include <qlxl/conversions/all.hpp>

#define XLL_DEC DLLEXPORT

XLL_DEC short int *qlCalibratedModelCalibrate(
        char *ObjectId,
        OPER *CalibrationHelper,
        OPER *OptimizationMethod,
        OPER *EndCriteria,
        OPER *Constraint,
        OPER *Weights,
        OPER *Trigger) {

    // declare a shared pointer to the Function Call object

    boost::shared_ptr<ObjectHandler::FunctionCall> functionCall;

    try {

        // instantiate the Function Call object

        functionCall = boost::shared_ptr<ObjectHandler::FunctionCall>(
            new ObjectHandler::FunctionCall("qlCalibratedModelCalibrate"));

        ObjectHandler::validateRange(Trigger, "Trigger");

        // initialize the session ID (if enabled)

        SET_SESSION_ID

        // convert input datatypes to C++ datatypes

        std::vector<std::string> CalibrationHelperCpp =
            ObjectHandler::operToVector<std::string>(*CalibrationHelper, "CalibrationHelper");

        std::string OptimizationMethodCpp = ObjectHandler::convert2<std::string>(
            ObjectHandler::ConvertOper(*OptimizationMethod), "OptimizationMethod", "");

        std::string EndCriteriaCpp = ObjectHandler::convert2<std::string>(
            ObjectHandler::ConvertOper(*EndCriteria), "EndCriteria", "");

        std::string ConstraintCpp = ObjectHandler::convert2<std::string>(
            ObjectHandler::ConvertOper(*Constraint), "Constraint", "");

        std::vector<double> WeightsCpp =
            ObjectHandler::operToVector<double>(*Weights, "Weights");

        // convert input datatypes to QuantLib datatypes

        std::vector<QuantLib::Real> WeightsLib =
            ObjectHandler::operToVector<QuantLib::Real>(*Weights, "Weights");

        // convert object IDs into library objects

        OH_GET_REFERENCE(ObjectIdLibObjPtr, ObjectId,
            QuantLibAddin::CalibratedModel, QuantLib::CalibratedModel)

        std::vector<boost::shared_ptr<QuantLib::CalibrationHelper> > CalibrationHelperLibObjPtr =
            ObjectHandler::getLibraryObjectVector<QuantLibAddin::CalibrationHelper, QuantLib::CalibrationHelper>(CalibrationHelperCpp);

        OH_GET_REFERENCE_DEFAULT(OptimizationMethodLibObjPtr, OptimizationMethodCpp,
            QuantLibAddin::OptimizationMethod, QuantLib::OptimizationMethod)

        OH_GET_REFERENCE_DEFAULT(EndCriteriaLibObjPtr, EndCriteriaCpp,
            QuantLibAddin::EndCriteria, QuantLib::EndCriteria)

        OH_GET_REFERENCE_DEFAULT(ConstraintLibObjPtr, ConstraintCpp,
            QuantLibAddin::Constraint, QuantLib::Constraint)

        // invoke the member function

        static short int returnValue;
        returnValue = ObjectIdLibObjPtr->calibrate(
                CalibrationHelperLibObjPtr,
                OptimizationMethodLibObjPtr,
                EndCriteriaLibObjPtr,
                ConstraintLibObjPtr,
                WeightsLib);

        // convert and return the return value

        return &returnValue;

    } catch (const std::exception &e) {
        ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall);
        return 0;
    } catch (...) {
        ObjectHandler::RepositoryXL::instance().logError("unkown error type", functionCall);
        return 0;
    }

}

and came back with the error

4>d:\build_ql_1_1_0\quantlibxl\qlxl\functions\model.cpp(109) : error C2664: 'QuantLib::CalibratedModel::calibrate' : can't convert 'boost::shared_ptr<T>' to 'QuantLib::OptimizationMethod &'
4>        with
4>        [
4>            T=QuantLib::OptimizationMethod
4>        ]

Obviously, the problem is in model.cpp at QuantLibXL\qlxl\functions, there is a function call

        OH_GET_REFERENCE_DEFAULT(OptimizationMethodLibObjPtr, OptimizationMethodCpp,
            QuantLibAddin::OptimizationMethod, QuantLib::OptimizationMethod)

        OH_GET_REFERENCE_DEFAULT(EndCriteriaLibObjPtr, EndCriteriaCpp,
            QuantLibAddin::EndCriteria, QuantLib::EndCriteria)

        OH_GET_REFERENCE_DEFAULT(ConstraintLibObjPtr, ConstraintCpp,
            QuantLibAddin::Constraint, QuantLib::Constraint)

        returnValue = ObjectIdLibObjPtr->calibrate(
                CalibrationHelperLibObjPtr,
                OptimizationMethodLibObjPtr,
                EndCriteriaLibObjPtr,
                ConstraintLibObjPtr,
                WeightsLib);

But in fact, void CalibratedModel::calibrate is

    void CalibratedModel::calibrate(
        const std::vector<boost::shared_ptr<CalibrationHelper> >& instruments,
        OptimizationMethod& method,
        const EndCriteria& endCriteria,
        const Constraint& additionalConstraint,
        const std::vector<Real>& weights)

And there is mismatch in types between two functions. 

So I need to create in model.cpp at QuantLibXL\qlxl\functions

OptimizationMethodLibObjPtr, EndCriteriaLibObjPtr, ConstraintLibObjPtr,

not in the type of boost::shared_ptr<T>, but as in QuantLib::OptimizationMethod&, EndCriteria&, Contraint&. The problem is that the following segment, 

        OH_GET_REFERENCE_DEFAULT(OptimizationMethodLibObjPtr, OptimizationMethodCpp,
            QuantLibAddin::OptimizationMethod, QuantLib::OptimizationMethod)

        OH_GET_REFERENCE_DEFAULT(EndCriteriaLibObjPtr, EndCriteriaCpp,
            QuantLibAddin::EndCriteria, QuantLib::EndCriteria)

        OH_GET_REFERENCE_DEFAULT(ConstraintLibObjPtr, ConstraintCpp,
            QuantLibAddin::Constraint, QuantLib::Constraint)

is automatically generated, so I do not know how to control it. Any good ideas?

- Hyung


On Thu, Jul 5, 2012 at 10:27 PM, Hyung-Seok Hahm <[hidden email]> wrote:
Hi Eric,

CalibrationHelper/SwaptionHelper classes have been successfully exposed and I'm playing around them in Excel. 

At the moment, I've push-backed 10 by 7 swaption vols in SwaptionHelper and all but one work well - what I mean is that every swaption swaptionhelper has been created/returned fine in Excel along with relevant inputs such as swaption maturities, lengths, fixed/floating daycounters, termstructure and so on. 

Only one swaption vol has failed in Excel, but I don't think there is anything wrong in Excel exposing because it generates the same error under QuantLib as well. It happened with the very last swaption vol, 10 year by 10 year and it looks like somehow the swaption maturity over-stretches the termstructure and comes back with an error because extrapolate option is turned off. 

All in all, it looks good so far. I'll figure out the above error and move on  (2) ShortRateModel->calibrate.

Thanks.

- Hyung



------------------------------------------------------------------------------
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: Implement Bermudan swaption in QuantLibXL

Eric Ehlers-2
Hi Hyung,

Apologies for the delay in my response, I was away.

> is automatically generated, so I do not know how to control it. Any good
> ideas?

You need to change the types in QuantLibAddin/qlo/model.?pp.

For example, your parameter OptimizationMethod should be declared in  
the above files with type  
boost::shared_ptr<QuantLib::OptimizationMethod>.

Search the source code for existing examples.  For example function  
qlAbcdInterpolation has a parameter of type  
QuantLib::OptimizationMethod, you can copy that.

I think you might also need to change the name of the variable because  
your current variable name "OptimizationMethod" is the same as the type.

Kind Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid


------------------------------------------------------------------------------
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: Implement Bermudan swaption in QuantLibXL

Hyung-Seok Hahm
Hi Eric,

Welcome back. I know you're doing a favor to the whole community, so please don't be sorry. ;-)

I've looked into qlAbcdInterpolation, but there is a discrepancy in that and my case. 

For instance,   qlAbcdInterpolation eventually gets to class AbcdInterpolation in QuantLib which has a parameter of type,

const boost::shared_ptr<OptimizationMethod>& opMethod

Therefore setting boost::shared_ptr<QuantLib::OptimizationMethod> in QuantLibAddin/qlo/model.?pp will do the job.

However, in my case, the ql-interface function eventually reaches void CalibrateModel::calibrate in model.cpp in QuantLib which has a parameter of type,

OptimizationMethod& method,

Therefore somehow it has to be declared as such in QuantLibAddin/qlo/model.?pp. What I have tried is

1. Create QuantLibAddin/qlo/model.hpp

#ifndef qla_model_hpp
#define qla_model_hpp

#include <oh/libraryobject.hpp>

#include <ql/types.hpp>

namespace QuantLib {

   class CalibratedModel;
    class Constraint;
    class CalibrationHelper;
    class EndCriteria;
    class OptimizationMethod;

}

namespace QuantLibAddin {

        OH_LIB_CLASS(OptimizationMethod, QuantLib::OptimizationMethod);
OH_LIB_CLASS(EndCriteria, QuantLib::EndCriteria);
OH_LIB_CLASS(Constraint, QuantLib::Constraint);



    class CalibrationHelper : public ObjectHandler::LibraryObject<QuantLib::CalibrationHelper> {
      protected:
        OH_LIB_CTOR(CalibrationHelper, QuantLib::CalibrationHelper);
    };

class CalibratedModel : 
public ObjectHandler::LibraryObject<QuantLib::CalibratedModel> {
      public:
        CalibratedModel(
            const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
            const QuantLib::Size nArguments,
            bool permanent);
        void calibrate(                   
const std::vector<boost::shared_ptr<QuantLib::CalibrationHelper> >& instrument,
            QuantLib::OptimizationMethod& om,
            const QuantLib::EndCriteria &endCriteria,
     const QuantLib::Constraint &additionalConstraint,
       const std::vector<QuantLib::Real>& weights);


};

}

#endif

2. Create QuantLibAddin/qlo/model.cpp

#if defined(HAVE_CONFIG_H)     // Dynamically created by configure
  #include <qlo/config.hpp>
#endif
#include <qlo/model.hpp>
#include <ql/models/model.hpp>

namespace QuantLibAddin {

        CalibratedModel::CalibratedModel(
            const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
            const QuantLib::Size nArguments,
            bool permanent)
: ObjectHandler::LibraryObject<QuantLib::CalibratedModel>(properties, permanent) {

libraryObject_ = boost::shared_ptr<QuantLib::CalibratedModel>(new
QuantLib::CalibratedModel(nArguments));
}

        void CalibratedModel::calibrate(
  const std::vector<boost::shared_ptr<QuantLib::CalibrationHelper> >& instrument,
                                   QuantLib::OptimizationMethod& om,
                   const QuantLib::EndCriteria &endCriteria,
    const QuantLib::Constraint &additionalConstraint,
  const std::vector<QuantLib::Real>& weights) {

  libraryObject_->calibrate(instrument, om, endCriteria, additionalConstraint, weights);

}



}

3. model.xml

<Category name='model'>
  <description>functions to construct and use model objects.</description>
  <displayName>Model</displayName>
  <xlFunctionWizardCategory>QuantLib - Financial</xlFunctionWizardCategory>
  <serializationIncludes>
    <include>qlo/model.hpp</include>
    <include>ql/models/model.hpp</include>
  </serializationIncludes>
  <addinIncludes>
    <include>qlo/model.hpp</include>
    <include>ql/models/model.hpp</include>
  </addinIncludes>
  <copyright>
    Hyungseok Hahm, 37243
  </copyright>
  
  <Functions>

    <Member name='qlCalibratedModelCalibrate' type='QuantLib::CalibratedModel' superType='libraryClass'>
      <description>calibrate.</description>
      <libraryFunction>calibrate</libraryFunction>
      <SupportedPlatforms>
        <SupportedPlatform name='Excel'/>
        <!--SupportedPlatform name='Cpp'/-->
      </SupportedPlatforms>
      <ParameterList>
        <Parameters>
          <Parameter name='CalibrationHelper' default='""'>
            <type>QuantLib::CalibrationHelper</type>
            <tensorRank>vector</tensorRank>
            <description>Calibration helper ID.</description>
          </Parameter>
          <Parameter name='OptimizationMethod' default='""'>
            <type>QuantLib::OptimizationMethod</type>
            <supertype> underlyingClass </supertype>
            <tensorRank>scalar</tensorRank>
            <description>OptimizationMethod object ID.</description>
          </Parameter>
          <Parameter name='EndCriteria' default='""'>
            <type>QuantLib::EndCriteria</type>
            <supertype> underlyingClass </supertype>
            <tensorRank>scalar</tensorRank>
            <description>EndCriteria object ID.</description>            
          </Parameter>
          <Parameter name='Constraint' default='""'>
            <type>QuantLib::Constraint</type>
            <supertype> underlyingClass </supertype>
            <tensorRank>scalar</tensorRank>
            <description>Leave it blank.</description>
          </Parameter>
          <Parameter name='Weights' default='""'>
            <type>QuantLib::Real</type>
            <tensorRank>vector</tensorRank>
            <description>Leave it blank.</description>
          </Parameter>
        </Parameters>
      </ParameterList>
      <ReturnValue>
        <type>bool</type>
        <tensorRank>scalar</tensorRank>
      </ReturnValue>
    </Member>
  </Functions>
</Category>

And yet I'm still getting an error, "error C2664: Can't convert QuantLib::CalibrateModel::calibrate : boost::shared_ptr<T> to QuantLib::OptimizationMethod &".

I believe this is due to the fact that in QuantLibAddin, OptimizationMethod is created as in boost::shared_ptr<QuantLib::OptimizationMethod>, not in QuantLib::OptimizationMethod &, which is what I want to do.

When I set superType to underlyingClass in Optimization in model.xml, I wanted it to be create in QuantLib::OptimizationMethod &, which obviously failed. 

Please let me know if you have any ideas.

Thanks.

- Hyung

On Wed, Jul 25, 2012 at 1:14 AM, Eric Ehlers <[hidden email]> wrote:
Hi Hyung,

Apologies for the delay in my response, I was away.

> is automatically generated, so I do not know how to control it. Any good
> ideas?

You need to change the types in QuantLibAddin/qlo/model.?pp.

For example, your parameter OptimizationMethod should be declared in
the above files with type
boost::shared_ptr<QuantLib::OptimizationMethod>.

Search the source code for existing examples.  For example function
qlAbcdInterpolation has a parameter of type
QuantLib::OptimizationMethod, you can copy that.

I think you might also need to change the name of the variable because
your current variable name "OptimizationMethod" is the same as the type.

Kind Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid


------------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: Implement Bermudan swaption in QuantLibXL

Eric Ehlers-2
Hi Hyung,

Thanks for your understanding :)

Here is the fix:

1) model.xml

For the three parameters OptimizationMethod, EndCriteria, and
Constraint -

Replace this:

     <supertype> underlyingClass </supertype>

With this:

     <superType>underlyingClass</superType>

And delete this:  default='""'

Which should give you:

           <Parameter name='OptimizationMethod'>
             <type>QuantLib::OptimizationMethod</type>
             <superType>underlyingClass</superType>
             <tensorRank>scalar</tensorRank>
             <description>OptimizationMethod object ID.</description>
           </Parameter>
           <Parameter name='EndCriteria'>
             <type>QuantLib::EndCriteria</type>
             <superType>underlyingClass</superType>
             <tensorRank>scalar</tensorRank>
             <description>EndCriteria object ID.</description>
           </Parameter>
           <Parameter name='Constraint'>
             <type>QuantLib::Constraint</type>
             <superType>underlyingClass</superType>
             <tensorRank>scalar</tensorRank>
             <description>Leave it blank.</description>
           </Parameter>

2) QuantLibAddin\gensrc\metadata\rules\excel.xml

In the RuleGroup called referenceConversions, add this line:

     <Rule tensorRank='scalar' superType='underlyingClass'
type='QuantLib::OptimizationMethod' codeID='code49'/>

That should do the trick, it compiles for me.  Please let me know how
it goes.

Kind Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid

------------------------------------------------------------------------------
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: Implement Bermudan swaption in QuantLibXL

Eric Ehlers-2
P.S. Also in model.xml you need to change the return type of the
function to void.

On 2012-07-25 12:52, Eric Ehlers wrote:

> Hi Hyung,
>
> Thanks for your understanding :)
>
> Here is the fix:
>
> 1) model.xml
>
> For the three parameters OptimizationMethod, EndCriteria, and
> Constraint -
>
> Replace this:
>
>      <supertype> underlyingClass </supertype>
>
> With this:
>
>      <superType>underlyingClass</superType>
>
> And delete this:  default='""'
>
> Which should give you:
>
>            <Parameter name='OptimizationMethod'>
>              <type>QuantLib::OptimizationMethod</type>
>              <superType>underlyingClass</superType>
>              <tensorRank>scalar</tensorRank>
>              <description>OptimizationMethod object ID.</description>
>            </Parameter>
>            <Parameter name='EndCriteria'>
>              <type>QuantLib::EndCriteria</type>
>              <superType>underlyingClass</superType>
>              <tensorRank>scalar</tensorRank>
>              <description>EndCriteria object ID.</description>
>            </Parameter>
>            <Parameter name='Constraint'>
>              <type>QuantLib::Constraint</type>
>              <superType>underlyingClass</superType>
>              <tensorRank>scalar</tensorRank>
>              <description>Leave it blank.</description>
>            </Parameter>
>
> 2) QuantLibAddin\gensrc\metadata\rules\excel.xml
>
> In the RuleGroup called referenceConversions, add this line:
>
>      <Rule tensorRank='scalar' superType='underlyingClass'
> type='QuantLib::OptimizationMethod' codeID='code49'/>
>
> That should do the trick, it compiles for me.  Please let me know how
> it goes.
>
> Kind Regards,
> Eric
>
> ===================================================
> Eric Ehlers
> nazcatech sprl | Brussels | http://www.nazcatech.be
> * Distributed computing for pricing analytics
> * Use Microsoft Excel as a client to the Grid
>
>
> ------------------------------------------------------------------------------
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Implement Bermudan swaption in QuantLibXL

Hyung-Seok Hahm
Eric,

I'm still getting  "error C2664: Can't convert QuantLib::CalibrateModel::calibrate : 'const QuantLib::OptimizationMethod' to 'QuantLib::OptimizationMethod &'".

It kinda makes sense in that the superType of QuantLib::OptimizationMethod is set to underlyingClass in model.xml and according to supertypes.xml, 

    <!-- from ObjectHandler::Object to const QuantLib::xx & -->
    <SuperType name='underlyingClass' nativeType='string' conversionSuffix='LibObj' memberAccess='.'/>

underlyingClass is supposed to convert to the type of const QuantLib::xx &. If I'm right, can you suggest any other superType that converts to QuantLib::xx &

If not, please let me know what I'm missing.

Thanks for your help!

- Hyung

On Wed, Jul 25, 2012 at 7:56 PM, Eric Ehlers <[hidden email]> wrote:
P.S. Also in model.xml you need to change the return type of the
function to void.

On 2012-07-25 12:52, Eric Ehlers wrote:
> Hi Hyung,
>
> Thanks for your understanding :)
>
> Here is the fix:
>
> 1) model.xml
>
> For the three parameters OptimizationMethod, EndCriteria, and
> Constraint -
>
> Replace this:
>
>      <supertype> underlyingClass </supertype>
>
> With this:
>
>      <superType>underlyingClass</superType>
>
> And delete this:  default='""'
>
> Which should give you:
>
>            <Parameter name='OptimizationMethod'>
>              <type>QuantLib::OptimizationMethod</type>
>              <superType>underlyingClass</superType>
>              <tensorRank>scalar</tensorRank>
>              <description>OptimizationMethod object ID.</description>
>            </Parameter>
>            <Parameter name='EndCriteria'>
>              <type>QuantLib::EndCriteria</type>
>              <superType>underlyingClass</superType>
>              <tensorRank>scalar</tensorRank>
>              <description>EndCriteria object ID.</description>
>            </Parameter>
>            <Parameter name='Constraint'>
>              <type>QuantLib::Constraint</type>
>              <superType>underlyingClass</superType>
>              <tensorRank>scalar</tensorRank>
>              <description>Leave it blank.</description>
>            </Parameter>
>
> 2) QuantLibAddin\gensrc\metadata\rules\excel.xml
>
> In the RuleGroup called referenceConversions, add this line:
>
>      <Rule tensorRank='scalar' superType='underlyingClass'
> type='QuantLib::OptimizationMethod' codeID='code49'/>
>
> That should do the trick, it compiles for me.  Please let me know how
> it goes.
>
> Kind Regards,
> Eric
>
> ===================================================
> Eric Ehlers
> nazcatech sprl | Brussels | http://www.nazcatech.be
> * Distributed computing for pricing analytics
> * Use Microsoft Excel as a client to the Grid
>
>
> ------------------------------------------------------------------------------
> 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



------------------------------------------------------------------------------
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: Implement Bermudan swaption in QuantLibXL

Eric Ehlers-2
Hi Hyung,

On 2012-07-26 03:07, Hyung-Seok Hahm wrote:

> Eric,
>
> I'm still getting  "error C2664: Can't convert
> QuantLib::CalibrateModel::calibrate : 'const
> QuantLib::OptimizationMethod' to 'QuantLib::OptimizationMethod &'".
>
> It kinda makes sense in that the superType of
> QuantLib::OptimizationMethod is set to underlyingClass in model.xml
> and according to supertypes.xml, 
>
>     <!-- from ObjectHandler::Object to const QuantLib::xx & -->
>     <SuperType name='underlyingClass' nativeType='string'
> conversionSuffix='LibObj' memberAccess='.'/>
>
> underlyingClass is supposed to convert to the type of CONST
> QUANTLIB::XX &. If I'm right, can you suggest any other superType
> that
> converts to QUANTLIB::XX &? 
There isn't one, because the cases where we need a non-const reference
are so rare that we didn't get around to defining the relevant
supertype.

Instead we use supertype underlyingClass, then implement a little
override as I described in my previous message:

> 2) QuantLibAddin\gensrc\metadata\rules\excel.xml
>
> In the RuleGroup called referenceConversions, add this line:
>
>      <Rule tensorRank='scalar' superType='underlyingClass'
> type='QuantLib::OptimizationMethod' codeID='code49'/>

This works already for QuantLib::SequenceStatistics and you could refer
to that example.

I implemented the fix for your code and it seems to work.  Attached are
the files that I changed as explained in my previous message.  To try
this out, please:

- Do a clean install of 1.1 (full build) as explained here:  
http://quantlib.org/quantlibaddin/build_qlxl.html
- Detach the attached file to C:/build_ql_1_1_0/patch.zip and
uncompress it there.
- Build C:/build_ql_1_1_0/QuantLibXL/QuantLibXL_full_vc9.sln

That should do it, any problems please let me know.

Kind Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid
------------------------------------------------------------------------------
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

patch.zip (21K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Implement Bermudan swaption in QuantLibXL

Hyung-Seok Hahm
Hi Eric,

Works like a charm. ;-) I'll probably need to overcome a couple of more things to get Bermudan swaptions working in QuantLibXL, but this is a breakthrough. 

Appreciate your help!!

- Hyung

On Thu, Jul 26, 2012 at 9:17 PM, Eric Ehlers <[hidden email]> wrote:
Hi Hyung,


On 2012-07-26 03:07, Hyung-Seok Hahm wrote:
Eric,

I'm still getting  "error C2664: Can't convert
QuantLib::CalibrateModel::calibrate : 'const
QuantLib::OptimizationMethod' to 'QuantLib::OptimizationMethod &'".

It kinda makes sense in that the superType of
QuantLib::OptimizationMethod is set to underlyingClass in model.xml
and according to supertypes.xml, 

    <!-- from ObjectHandler::Object to const QuantLib::xx & -->
    <SuperType name='underlyingClass' nativeType='string'
conversionSuffix='LibObj' memberAccess='.'/>

underlyingClass is supposed to convert to the type of CONST
QUANTLIB::XX &. If I'm right, can you suggest any other superType that
converts to QUANTLIB::XX &? 

There isn't one, because the cases where we need a non-const reference are so rare that we didn't get around to defining the relevant supertype.

Instead we use supertype underlyingClass, then implement a little override as I described in my previous message:


2) QuantLibAddin\gensrc\metadata\rules\excel.xml

In the RuleGroup called referenceConversions, add this line:

     <Rule tensorRank='scalar' superType='underlyingClass'
type='QuantLib::OptimizationMethod' codeID='code49'/>

This works already for QuantLib::SequenceStatistics and you could refer to that example.

I implemented the fix for your code and it seems to work.  Attached are the files that I changed as explained in my previous message.  To try this out, please:

- Do a clean install of 1.1 (full build) as explained here:  http://quantlib.org/quantlibaddin/build_qlxl.html
- Detach the attached file to C:/build_ql_1_1_0/patch.zip and uncompress it there.
- Build C:/build_ql_1_1_0/QuantLibXL/QuantLibXL_full_vc9.sln

That should do it, any problems please let me know.


Kind Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid

------------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: Implement Bermudan swaption in QuantLibXL

Hyung-Seok Hahm
Hi Eric,

One piece of a puzzle is missing. 

QuantLibAddin/qlo/valueobjects/vo_model.*pp
QuantLibAddin/qlo/serialization/create/create_model.*pp 
QuantLibAddin/qlo/serialization/register/serialization_model.*pp
 
have not been created. Where should I modify to create them?

- Hyung

On Fri, Jul 27, 2012 at 1:17 PM, Hyung-Seok Hahm <[hidden email]> wrote:
Hi Eric,

Works like a charm. ;-) I'll probably need to overcome a couple of more things to get Bermudan swaptions working in QuantLibXL, but this is a breakthrough. 

Appreciate your help!!

- Hyung

On Thu, Jul 26, 2012 at 9:17 PM, Eric Ehlers <[hidden email]> wrote:
Hi Hyung,


On 2012-07-26 03:07, Hyung-Seok Hahm wrote:
Eric,

I'm still getting  "error C2664: Can't convert
QuantLib::CalibrateModel::calibrate : 'const
QuantLib::OptimizationMethod' to 'QuantLib::OptimizationMethod &'".

It kinda makes sense in that the superType of
QuantLib::OptimizationMethod is set to underlyingClass in model.xml
and according to supertypes.xml, 

    <!-- from ObjectHandler::Object to const QuantLib::xx & -->
    <SuperType name='underlyingClass' nativeType='string'
conversionSuffix='LibObj' memberAccess='.'/>

underlyingClass is supposed to convert to the type of CONST
QUANTLIB::XX &. If I'm right, can you suggest any other superType that
converts to QUANTLIB::XX &? 

There isn't one, because the cases where we need a non-const reference are so rare that we didn't get around to defining the relevant supertype.

Instead we use supertype underlyingClass, then implement a little override as I described in my previous message:


2) QuantLibAddin\gensrc\metadata\rules\excel.xml

In the RuleGroup called referenceConversions, add this line:

     <Rule tensorRank='scalar' superType='underlyingClass'
type='QuantLib::OptimizationMethod' codeID='code49'/>

This works already for QuantLib::SequenceStatistics and you could refer to that example.

I implemented the fix for your code and it seems to work.  Attached are the files that I changed as explained in my previous message.  To try this out, please:

- Do a clean install of 1.1 (full build) as explained here:  http://quantlib.org/quantlibaddin/build_qlxl.html
- Detach the attached file to C:/build_ql_1_1_0/patch.zip and uncompress it there.
- Build C:/build_ql_1_1_0/QuantLibXL/QuantLibXL_full_vc9.sln

That should do it, any problems please let me know.


Kind Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid

------------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: Implement Bermudan swaption in QuantLibXL

Hyung-Seok Hahm
Another follow-up question. 

I'm getting the following error. 

"qlCalibratedModelCalibrate - ObjectHandler error: attempt to retrieve object with unknown ID..."

Digging into it a little more, it comes from the auto-generated QuantLibXL\qlxl\functions\model.cpp

  OH_GET_REFERENCE(ObjectIdLibObjPtr, ObjectId,
     QuantLibAddin::CalibratedModel, QuantLib::CalibratedModel)

I had an impression that an object of QuantLibAddin::CalibratedModel was not registered, so what I did was

add the following line in types.xml

<DataType defaultSuperType='objectClass'>QuantLibAddin::CalibratedModel</DataType>

Didn't work out though. Any suggestions?

- Hyung


On Mon, Jul 30, 2012 at 1:21 PM, Hyung-Seok Hahm <[hidden email]> wrote:
Hi Eric,

One piece of a puzzle is missing. 

QuantLibAddin/qlo/valueobjects/vo_model.*pp
QuantLibAddin/qlo/serialization/create/create_model.*pp 
QuantLibAddin/qlo/serialization/register/serialization_model.*pp
 
have not been created. Where should I modify to create them?

- Hyung

On Fri, Jul 27, 2012 at 1:17 PM, Hyung-Seok Hahm <[hidden email]> wrote:
Hi Eric,

Works like a charm. ;-) I'll probably need to overcome a couple of more things to get Bermudan swaptions working in QuantLibXL, but this is a breakthrough. 

Appreciate your help!!

- Hyung

On Thu, Jul 26, 2012 at 9:17 PM, Eric Ehlers <[hidden email]> wrote:
Hi Hyung,


On 2012-07-26 03:07, Hyung-Seok Hahm wrote:
Eric,

I'm still getting  "error C2664: Can't convert
QuantLib::CalibrateModel::calibrate : 'const
QuantLib::OptimizationMethod' to 'QuantLib::OptimizationMethod &'".

It kinda makes sense in that the superType of
QuantLib::OptimizationMethod is set to underlyingClass in model.xml
and according to supertypes.xml, 

    <!-- from ObjectHandler::Object to const QuantLib::xx & -->
    <SuperType name='underlyingClass' nativeType='string'
conversionSuffix='LibObj' memberAccess='.'/>

underlyingClass is supposed to convert to the type of CONST
QUANTLIB::XX &. If I'm right, can you suggest any other superType that
converts to QUANTLIB::XX &? 

There isn't one, because the cases where we need a non-const reference are so rare that we didn't get around to defining the relevant supertype.

Instead we use supertype underlyingClass, then implement a little override as I described in my previous message:


2) QuantLibAddin\gensrc\metadata\rules\excel.xml

In the RuleGroup called referenceConversions, add this line:

     <Rule tensorRank='scalar' superType='underlyingClass'
type='QuantLib::OptimizationMethod' codeID='code49'/>

This works already for QuantLib::SequenceStatistics and you could refer to that example.

I implemented the fix for your code and it seems to work.  Attached are the files that I changed as explained in my previous message.  To try this out, please:

- Do a clean install of 1.1 (full build) as explained here:  http://quantlib.org/quantlibaddin/build_qlxl.html
- Detach the attached file to C:/build_ql_1_1_0/patch.zip and uncompress it there.
- Build C:/build_ql_1_1_0/QuantLibXL/QuantLibXL_full_vc9.sln

That should do it, any problems please let me know.


Kind Regards,
Eric

===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid

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








--

Hyungseok Hahm, PhD, FRM   

Quantitative Analyst 

Industrial Bank of Korea

Trading Department

Tel      : 82-2-729-7081

Fax       : 82-2-729-6084

E-mail  : [hidden email]

Yahoo Msn : hyungseok.hahm

Google Talk : hs.hahm.ibk[hidden email]

LinkedIn: http://kr.linkedin.com/pub/dir/Hyung-seok/Hahm



------------------------------------------------------------------------------
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: Implement Bermudan swaption in QuantLibXL

Eric Ehlers-2
In reply to this post by Hyung-Seok Hahm
Hi Hyung,

On 2012-07-30 06:21, Hyung-Seok Hahm wrote:
> Hi Eric,
>
> One piece of a puzzle is missing. 
>
> QuantLibAddin/qlo/valueobjects/vo_model.*pp
> QuantLibAddin/qlo/serialization/create/create_model.*pp 
> QuantLibAddin/qlo/serialization/register/serialization_model.*pp
>  
> have not been created. Where should I modify to create them?

Those files are not created, and not required, because you have not
implemented any constructors in model.xml.

Regards,
Eric

--
===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid

------------------------------------------------------------------------------
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: Implement Bermudan swaption in QuantLibXL

Eric Ehlers-2
In reply to this post by Hyung-Seok Hahm
Hi Hyung,

On 2012-07-30 07:15, Hyung-Seok Hahm wrote:
> Another follow-up question. 
>
> I'm getting the following error. 
>
> "qlCalibratedModelCalibrate - ObjectHandler error: attempt to
> retrieve object with unknown ID..."

That run time error tells you that you are trying to retrieve an object
that does not exist.

Can you check whether the object that you are trying to retrieve has in
fact been created previously?

Regards,
Eric

--
===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid

------------------------------------------------------------------------------
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: Implement Bermudan swaption in QuantLibXL

Hyung-Seok Hahm
Eric,

Yeop. Thanks to your advice, I've passed the obstacle and still moving forward. 

Now I'm stuck at implementing the following segment in BermudanSwaption.cpp

        boost::shared_ptr<HullWhite> modelHW(new HullWhite(rhTermStructure));
......
        calibrateModel(modelHW, swaptions);

And the function, calibrateModel is declared as 

void calibrateModel(
          const boost::shared_ptr<CalibratedModel>& model,
          const std::vector<boost::shared_ptr<CalibrationHelper> >& helpers)

Given the fact that the above example perfectly works, I know that HullWhite can be dynamically cast to CalibratedModel in QuantLib.

Now back to QuantLibXL, I've exposed HullWhite and CalibratedModel. However, when HullWhite is throwed into CalibratedModel, it generates 

qlCalibratedModelCalibrate - Error retrieving object with id 'obj_0000e#0000' - unable to convert reference to type 'class QuantLibAddin::CalibratedModel' found instead 'class QuantLibAddin::HullWhite'

Debugging indicates that the error originates in

\ObjectHandler\oh\repository.hpp

        //! Template member function to retrieve the Object with given ID.
        /*! Retrieve the object with the given ID and downcast it to the desired type.
            Throw an exception if no Object exists with that ID.
            This template passes the work off to function retrieveObjectImpl which
            may be overridden in derived classes.
        */
        template <class T>
        void retrieveObject(boost::shared_ptr<T> &ret,
                            const std::string &id) {
            boost::shared_ptr<Object> object = retrieveObjectImpl(id);
            ret = boost::dynamic_pointer_cast<T>(object);
            OH_REQUIRE(ret, "Error retrieving object with id '"
                << id << "' - unable to convert reference to type '"
                << typeid(T).name() << "' found instead '"
                << typeid(*object).name() << "'");
        }

So my guess is that in QuantLib, QuantLib::HullWhite is dynamically castable to QuantLib::CalibratedModel while in QuantLibAddin, QuantLibAddin::Hullwhite is yet to do so to QuantLibAddin::CalibratedModel.

Please let me know where and how I can set this. 

Thanks!

- Hyung



On Tue, Jul 31, 2012 at 2:23 AM, Eric Ehlers <[hidden email]> wrote:
Hi Hyung,

On 2012-07-30 07:15, Hyung-Seok Hahm wrote:
> Another follow-up question. 
>
> I'm getting the following error. 
>
> "qlCalibratedModelCalibrate - ObjectHandler error: attempt to
> retrieve object with unknown ID..."

That run time error tells you that you are trying to retrieve an object
that does not exist.

Can you check whether the object that you are trying to retrieve has in
fact been created previously?

Regards,
Eric

--
===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid

------------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: Implement Bermudan swaption in QuantLibXL

Hyung-Seok Hahm
Eric or anybody who can help,

I was able to fix the previous problems and yet another comes up.

Now I'm implementing the following line in QuantLibXL

>>

boost::shared_ptr<HullWhite> modelHW(new HullWhite(rhTermStructure);
....
std::vector<boost::shared_ptr<CalibrationHelper>> swaptions;
.....
swaptions[i]->setPricingEngine(boost::shared_ptr<PricingEngine>(
    new JamshidianSwaptionEngine(modelHW)));

>>

I believe the key to this is to expose setPricingEngine function in CalibrationHelper class, which is not placed in the current version of QuantLibXL.

I've noticed that there is already a similar implementation in baseinstrument.*pp

//baseinstruments.hpp

#ifndef qla_baseinstruments_hpp
#define qla_baseinstruments_hpp

#include <oh/libraryobject.hpp>

namespace QuantLib {
    class Instrument;
}

namespace QuantLibAddin {
    
    class PricingEngine;
    
    //OH_LIB_CLASS(Instrument, QuantLib::Instrument);
    class Instrument : public ObjectHandler::LibraryObject<QuantLib::Instrument> {
      public:
        void setPricingEngine(boost::shared_ptr<PricingEngine>& e) const;
      protected:
        OH_LIB_CTOR(Instrument, QuantLib::Instrument)
    };

    OH_OBJ_CLASS(OneAssetOption, Instrument);

}

#endif

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

//baseinstruments.cpp

#include <qlo/baseinstruments.hpp>
#include <qlo/pricingengines.hpp>
#include <ql/instrument.hpp>

namespace QuantLibAddin {

    void Instrument::setPricingEngine(boost::shared_ptr<PricingEngine>& engine) const {
        boost::shared_ptr<QuantLib::PricingEngine> ql_engine;
        engine->getLibraryObject(ql_engine);

        libraryObject_->setPricingEngine(ql_engine);
        
        boost::shared_ptr<ObjectHandler::ValueObject> inst_properties = properties();
        boost::shared_ptr<ObjectHandler::ValueObject> eng_properties = engine->properties();
        
        std::string engineId = eng_properties->objectId();
        inst_properties->setProperty("EngineID", engineId);
    }
}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Inspired by them, I've done the similar settings in calibrationhelpers.*pp

// calibrationhelpers.hpp

....
   class CalibrationHelper : public ObjectHandler::LibraryObject<QuantLib::CalibrationHelper> {
      public:
 // Imitate baseinstruments.hpp
void setPricingEngine(boost::shared_ptr<PricingEngine>& engine) const;
      protected:
// boost::shared_ptr<PricingEngine> engine_;
        OH_LIB_CTOR(CalibrationHelper, QuantLib::CalibrationHelper);
    };
...

// calibrationhelpers.cpp

,,,,

void CalibrationHelper::setPricingEngine(boost::shared_ptr<PricingEngine>& engine) const {
        boost::shared_ptr<QuantLib::PricingEngine> ql_engine;
        engine->getLibraryObject(ql_engine);

        libraryObject_->setPricingEngine(ql_engine);
        
        boost::shared_ptr<ObjectHandler::ValueObject> inst_properties = properties();
        boost::shared_ptr<ObjectHandler::ValueObject> eng_properties = engine->properties();
        
        std::string engineId = eng_properties->objectId();
        inst_properties->setProperty("EngineID", engineId);

}
...

which gives the following error

10>c:\boost\boost_1_44\boost\smart_ptr\shared_ptr.hpp(259) : error C2680: 'QuantLibAddin::PricingEngine *' : the corresponding type of dynamic_cast is wrong
10>        'QuantLibAddin::PricingEngine' : In order to use dynamic_cast, the class should be defined first
10>        c:\boost\boost_1_44\boost\smart_ptr\shared_ptr.hpp(522) : check the reference to  'boost::shared_ptr<T>::shared_ptr<ObjectHandler::Object>(const boost::shared_ptr<ObjectHandler::Object> &,boost::detail::dynamic_cast_tag)'
10>        with
10>        [
10>            T=QuantLibAddin::PricingEngine
10>        ]
10>        d:\build_ql_1_1_0\objecthandler\oh\repository.hpp(91) :  check the reference to'boost::shared_ptr<T> boost::dynamic_pointer_cast<T,ObjectHandler::Object>(const boost::shared_ptr<ObjectHandler::Object> &)'
10>        with
10>        [
10>            T=QuantLibAddin::PricingEngine
10>        ]
10>        d:\build_ql_1_1_0\quantlibxl\qlxl\functions\calibrationhelpers.cpp(72) :  check the reference to  'void ObjectHandler::Repository::retrieveObject<QuantLibAddin::PricingEngine>(boost::shared_ptr<T> &,const std::string &)'
10>        with
10>        [
10>            T=QuantLibAddin::PricingEngine
10>        ]
10>c:\boost\boost_1_44\boost\smart_ptr\shared_ptr.hpp(260) : fatal error C1903:

I guess that the range of dynamic_castable types should be declared somewhere in qlgensrc. Please let me know if you know how.

Thanks!

- Hyung


On Thu, Aug 2, 2012 at 9:53 AM, Hyung-Seok Hahm <[hidden email]> wrote:
Eric,

Yeop. Thanks to your advice, I've passed the obstacle and still moving forward. 

Now I'm stuck at implementing the following segment in BermudanSwaption.cpp

        boost::shared_ptr<HullWhite> modelHW(new HullWhite(rhTermStructure));
......
        calibrateModel(modelHW, swaptions);

And the function, calibrateModel is declared as 

void calibrateModel(
          const boost::shared_ptr<CalibratedModel>& model,
          const std::vector<boost::shared_ptr<CalibrationHelper> >& helpers)

Given the fact that the above example perfectly works, I know that HullWhite can be dynamically cast to CalibratedModel in QuantLib.

Now back to QuantLibXL, I've exposed HullWhite and CalibratedModel. However, when HullWhite is throwed into CalibratedModel, it generates 

qlCalibratedModelCalibrate - Error retrieving object with id 'obj_0000e#0000' - unable to convert reference to type 'class QuantLibAddin::CalibratedModel' found instead 'class QuantLibAddin::HullWhite'

Debugging indicates that the error originates in

\ObjectHandler\oh\repository.hpp

        //! Template member function to retrieve the Object with given ID.
        /*! Retrieve the object with the given ID and downcast it to the desired type.
            Throw an exception if no Object exists with that ID.
            This template passes the work off to function retrieveObjectImpl which
            may be overridden in derived classes.
        */
        template <class T>
        void retrieveObject(boost::shared_ptr<T> &ret,
                            const std::string &id) {
            boost::shared_ptr<Object> object = retrieveObjectImpl(id);
            ret = boost::dynamic_pointer_cast<T>(object);
            OH_REQUIRE(ret, "Error retrieving object with id '"
                << id << "' - unable to convert reference to type '"
                << typeid(T).name() << "' found instead '"
                << typeid(*object).name() << "'");
        }

So my guess is that in QuantLib, QuantLib::HullWhite is dynamically castable to QuantLib::CalibratedModel while in QuantLibAddin, QuantLibAddin::Hullwhite is yet to do so to QuantLibAddin::CalibratedModel.

Please let me know where and how I can set this. 

Thanks!

- Hyung



------------------------------------------------------------------------------
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
12