Exposing GeneralizedHullWhite in QuantLibXL

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

Exposing GeneralizedHullWhite in QuantLibXL

Hyungseok Hahm
Dear all,

I am working on exposing GeneralizedHullWhite in QuantLibXL.

It was not terribly challenging until this step. Here is the .xml part. The problem is in the red. 

    <Constructor name='qlGeneralizedHullWhite'>
      <libraryFunction>GeneralizedHullWhite</libraryFunction>
      <SupportedPlatforms>
        <!--SupportedPlatform name='Excel' calcInWizard='false'/-->
        <SupportedPlatform name='Excel'/>
        <SupportedPlatform name='Cpp'/>
      </SupportedPlatforms>
      <ParameterList>
        <Parameters>
          <Parameter name='YieldCurve'   exampleValue ='EURYC'>
            <type>QuantLib::YieldTermStructure</type>
            <superType>libToHandle</superType>
            <tensorRank>scalar</tensorRank>
            <description>YieldTermStructure object ID.</description>
          </Parameter>
          <Parameter name='SpeedStructure' const='False' default='QuantLib::Date()'>
            <type>QuantLib::Date</type>
            <tensorRank>vector</tensorRank>
            <description>Speed Structure</description>
          </Parameter>
          <Parameter name='VolStructure' const='False' default='QuantLib::Date()'>
            <type>QuantLib::Date</type>
            <tensorRank>vector</tensorRank>
            <description>Vol Structure</description>
          </Parameter>
          <Parameter name='Speed' default='""'>
            <type>QuantLib::Real</type>
            <tensorRank>vector</tensorRank>
            <description>Speed</description>
          </Parameter>
          <Parameter name='Vol' default='""'>
            <type>QuantLib::Real</type>
            <tensorRank>vector</tensorRank>
            <description>Vol</description>
          </Parameter>
        </Parameters>
      </ParameterList>
    </Constructor>

The corresponding part of GeneralizedHullWhite.hpp in QuantLib is

        boost::function<Real (Time)> speed() const;
        boost::function<Real (Time)> vol() const;

As a result, when compiling, the following error message pops up.

error C2440: 'initializing' : cannot convert from 'boost::function<Signature>' to 'std::vector<_Ty>'

At this point, what has caused the error looks obvious. In .xml, the type is defined wrong. 

            <type>QuantLib::Real</type>

Then my question is what is the type definition in QuantLibXL that corresponds to boost::function<Signature> in QuantLib?

If anyone has a clue, please enlighten me. It would be tremendous help!

Thanks!

Hyungseok 

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Exposing GeneralizedHullWhite in QuantLibXL

Peter Caspers-4
> The corresponding part of GeneralizedHullWhite.hpp in QuantLib is
>
>         boost::function<Real (Time)> speed() const;
>         boost::function<Real (Time)> vol() const;

no, it isn't. These are private methods of the class, if I am not
mistaken, not part of the constructor. The
latter reads

        GeneralizedHullWhite(
            const Handle<YieldTermStructure>& yieldtermStructure,
            const std::vector<Date>& speedstructure,
            const std::vector<Date>& volstructure,
            const std::vector<Real>& speed,
            const std::vector<Real>& vol);

so you should check your wrapper code (or post it here for further
clarification).

Depending on what you are planning to do, a look into the sister
folder ql/experimental/models might also
be interesting (well at the moment probably only if you connect to the
current git master, not on a released
version).

Best regards
Peter

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Exposing GeneralizedHullWhite in QuantLibXL

Hyung-Seok Hahm
Hi Peter,

In fact, I moved the methods from private to public. I know it is not the smartest thing to do, but for the sake of practicality. After being sure that the code works, I will make the code prettier. 





On Thu, Jan 9, 2014 at 7:44 PM, Peter Caspers <[hidden email]> wrote:
> The corresponding part of GeneralizedHullWhite.hpp in QuantLib is
>
>         boost::function<Real (Time)> speed() const;
>         boost::function<Real (Time)> vol() const;

no, it isn't. These are private methods of the class, if I am not
mistaken, not part of the constructor. The
latter reads

        GeneralizedHullWhite(
            const Handle<YieldTermStructure>& yieldtermStructure,
            const std::vector<Date>& speedstructure,
            const std::vector<Date>& volstructure,
            const std::vector<Real>& speed,
            const std::vector<Real>& vol);

so you should check your wrapper code (or post it here for further
clarification).

Depending on what you are planning to do, a look into the sister
folder ql/experimental/models might also
be interesting (well at the moment probably only if you connect to the
current git master, not on a released
version).

Best regards
Peter



--

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


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Fwd: Exposing GeneralizedHullWhite in QuantLibXL

Peter Caspers-4
Hi Hyungseok,

ok, then the question is how to expose methods to excel with
non-native return type, right ? This is not straightforward, I had the
same question some time ago:

http://quantlib.10058.n7.nabble.com/Return-object-in-QLXL-td8942.html

Probably you have to wrap boost::function into a ql object to follow
the path described in the thread, though (not sure about that, it's
been a time since I worked
with the addin).

Peter

On 10 January 2014 00:48, Hyung-Seok Hahm <[hidden email]> wrote:

> Hi Peter,
>
> In fact, I moved the methods from private to public. I know it is not the
> smartest thing to do, but for the sake of practicality. After being sure
> that the code works, I will make the code prettier.
>
> Thanks for the heads up. I'll look into that then.
>
> Cheers,
>
> Hyungseok
>
>
> On Thu, Jan 9, 2014 at 7:44 PM, Peter Caspers <[hidden email]>
> wrote:
>>
>> > The corresponding part of GeneralizedHullWhite.hpp in QuantLib is
>> >
>> >         boost::function<Real (Time)> speed() const;
>> >         boost::function<Real (Time)> vol() const;
>>
>> no, it isn't. These are private methods of the class, if I am not
>> mistaken, not part of the constructor. The
>> latter reads
>>
>>         GeneralizedHullWhite(
>>             const Handle<YieldTermStructure>& yieldtermStructure,
>>             const std::vector<Date>& speedstructure,
>>             const std::vector<Date>& volstructure,
>>             const std::vector<Real>& speed,
>>             const std::vector<Real>& vol);
>>
>> so you should check your wrapper code (or post it here for further
>> clarification).
>>
>> Depending on what you are planning to do, a look into the sister
>> folder ql/experimental/models might also
>> be interesting (well at the moment probably only if you connect to the
>> current git master, not on a released
>> version).
>>
>> Best regards
>> Peter
>
>
>
>
> --
>
> 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 : [hidden email]
>
> LinkedIn: http://kr.linkedin.com/pub/dir/Hyung-seok/Hahm

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Exposing GeneralizedHullWhite in QuantLibXL

Luigi Ballabio
In reply to this post by Hyung-Seok Hahm
Hi Hyungseok,
    it's not that practical if it blocks you :)

If you want to expose the information quickly, you'll be better off
keeping the two methods private and adding something like:

private:
    boost::function<Real (Time)> speed_() const;
    boost::function<Real (Time)> vol_() const;
public:
    Real speed(Time t) const { return speed_()(t); }
    Real vol(Time t) const { return vol_()(t); }

The two public methods above should be straightforward to export.
(They won't be fast, though, as they'll recreate the function every
time. As a further step, you could modify the class so that it caches
the two boost::function instances.)

Luigi

On Fri, Jan 10, 2014 at 12:48 AM, Hyung-Seok Hahm
<[hidden email]> wrote:

> Hi Peter,
>
> In fact, I moved the methods from private to public. I know it is not the
> smartest thing to do, but for the sake of practicality. After being sure
> that the code works, I will make the code prettier.
>
> Thanks for the heads up. I'll look into that then.
>
> Cheers,
>
> Hyungseok
>
>
> On Thu, Jan 9, 2014 at 7:44 PM, Peter Caspers <[hidden email]>
> wrote:
>>
>> > The corresponding part of GeneralizedHullWhite.hpp in QuantLib is
>> >
>> >         boost::function<Real (Time)> speed() const;
>> >         boost::function<Real (Time)> vol() const;
>>
>> no, it isn't. These are private methods of the class, if I am not
>> mistaken, not part of the constructor. The
>> latter reads
>>
>>         GeneralizedHullWhite(
>>             const Handle<YieldTermStructure>& yieldtermStructure,
>>             const std::vector<Date>& speedstructure,
>>             const std::vector<Date>& volstructure,
>>             const std::vector<Real>& speed,
>>             const std::vector<Real>& vol);
>>
>> so you should check your wrapper code (or post it here for further
>> clarification).
>>
>> Depending on what you are planning to do, a look into the sister
>> folder ql/experimental/models might also
>> be interesting (well at the moment probably only if you connect to the
>> current git master, not on a released
>> version).
>>
>> Best regards
>> Peter
>
>
>
>
> --
>
> 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 : [hidden email]
>
> LinkedIn: http://kr.linkedin.com/pub/dir/Hyung-seok/Hahm
>
>
> ------------------------------------------------------------------------------
> CenturyLink Cloud: The Leader in Enterprise Cloud Services.
> Learn Why More Businesses Are Choosing CenturyLink Cloud For
> Critical Workloads, Development Environments & Everything In Between.
> Get a Quote or Start a Free Trial Today.
> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>



--
<https://implementingquantlib.blogspot.com>
<https://twitter.com/lballabio>

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Exposing GeneralizedHullWhite in QuantLibXL

Hyung-Seok Hahm
Luigi and Peter,

I am not totally a stranger to expose user-defined data types in QuantLibXL, so I think I can handle it from here. Adding public methods is also a wonderful idea in the sense that it can keep its integrity.

Thank you very much for the insight that you guys have shared. 

Cheers!

- Hyungseok 



On Fri, Jan 10, 2014 at 5:19 PM, Luigi Ballabio <[hidden email]> wrote:
Hi Hyungseok,
    it's not that practical if it blocks you :)

If you want to expose the information quickly, you'll be better off
keeping the two methods private and adding something like:

private:
    boost::function<Real (Time)> speed_() const;
    boost::function<Real (Time)> vol_() const;
public:
    Real speed(Time t) const { return speed_()(t); }
    Real vol(Time t) const { return vol_()(t); }

The two public methods above should be straightforward to export.
(They won't be fast, though, as they'll recreate the function every
time. As a further step, you could modify the class so that it caches
the two boost::function instances.)

Luigi

On Fri, Jan 10, 2014 at 12:48 AM, Hyung-Seok Hahm
<[hidden email]> wrote:
> Hi Peter,
>
> In fact, I moved the methods from private to public. I know it is not the
> smartest thing to do, but for the sake of practicality. After being sure
> that the code works, I will make the code prettier.
>
> Thanks for the heads up. I'll look into that then.
>
> Cheers,
>
> Hyungseok
>
>
> On Thu, Jan 9, 2014 at 7:44 PM, Peter Caspers <[hidden email]>
> wrote:
>>
>> > The corresponding part of GeneralizedHullWhite.hpp in QuantLib is
>> >
>> >         boost::function<Real (Time)> speed() const;
>> >         boost::function<Real (Time)> vol() const;
>>
>> no, it isn't. These are private methods of the class, if I am not
>> mistaken, not part of the constructor. The
>> latter reads
>>
>>         GeneralizedHullWhite(
>>             const Handle<YieldTermStructure>& yieldtermStructure,
>>             const std::vector<Date>& speedstructure,
>>             const std::vector<Date>& volstructure,
>>             const std::vector<Real>& speed,
>>             const std::vector<Real>& vol);
>>
>> so you should check your wrapper code (or post it here for further
>> clarification).
>>
>> Depending on what you are planning to do, a look into the sister
>> folder ql/experimental/models might also
>> be interesting (well at the moment probably only if you connect to the
>> current git master, not on a released
>> version).
>>
>> Best regards
>> Peter
>
>
>
>
> --
>
> 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 : [hidden email]
>
> LinkedIn: http://kr.linkedin.com/pub/dir/Hyung-seok/Hahm
>
>
> ------------------------------------------------------------------------------
> CenturyLink Cloud: The Leader in Enterprise Cloud Services.
> Learn Why More Businesses Are Choosing CenturyLink Cloud For
> Critical Workloads, Development Environments & Everything In Between.
> Get a Quote or Start a Free Trial Today.
> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>



--
<https://implementingquantlib.blogspot.com>
<https://twitter.com/lballabio>



--

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


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users