Re: Expose a QuantLib class method to QuantLibAddin

Posted by g m-10 on
URL: http://quantlib.414.s1.nabble.com/Expose-a-QuantLib-class-method-to-QuantLibAddin-tp319p324.html

Hi,
Luigi, I didn't find the localVol public method (I'm working on the latest release (May 23d 2011))
 
Don said that if the return of a function defined in a xml needs some processing one must write a "equivalent" method in QuantLibAddin,
I checked the example he gave of qlBondDescription but I didnt see the trick.
 
I turned QuantLib::LocalVolSurface::localVolImp to public in order to validate my understanding and it worked fine in Excel (my modifications below) :
 
Conceptually however, I don't see where QuantLib::LocalVolSurface connects to QuantLibAddin::LocalVolSurface?
 
In volatilities.xml:
    <Constructor name='qlLocalVolSurface'>
      <libraryFunction>LocalVolSurfaceImp</libraryFunction>
      <SupportedPlatforms>
        <!--SupportedPlatform name='Excel' calcInWizard='false'/-->
        <SupportedPlatform name='Excel'/>
        <!--SupportedPlatform name='Cpp'/-->
      </SupportedPlatforms>
      <ParameterList>
        <Parameters>
          <Parameter name='BlackVolTermStructure'>
            <type>QuantLib::BlackVolTermStructure</type>
            <superType>libToHandle</superType>
            <tensorRank>scalar</tensorRank>
            <description>BlackVolTS.</description>
          </Parameter>
          <Parameter name='RiskFreeTermStructure'>
            <type>QuantLib::YieldTermStructure</type>
            <superType>libToHandle</superType>
            <tensorRank>scalar</tensorRank>
            <description>RiskFreeTS.</description>
          </Parameter>
          <Parameter name='DividendYieldTermStructure'>
            <type>QuantLib::YieldTermStructure</type>
            <superType>libToHandle</superType>
            <tensorRank>scalar</tensorRank>
            <description>DivYieldTS.</description>
          </Parameter>
          <Parameter name='Underlying'>
            <type>QuantLib::Quote</type>
            <superType>libToHandle</superType>
            <tensorRank>scalar</tensorRank>
            <description>underlying</description>
          </Parameter>
        </Parameters>
      </ParameterList>
    </Constructor>
   
<Member name='qlLocalVolSurfaceValue' type='QuantLib::LocalVolSurface' superType='libraryClass'>
      <description>Returns the local vol surface value at (time,strike).</description>
      <libraryFunction>localVolImpl</libraryFunction>
      <SupportedPlatforms>
        <SupportedPlatform name='Excel' calcInWizard='false' />
      </SupportedPlatforms>
      <ParameterList>
        <Parameters>
          <Parameter name='Time' exampleValue = '0.5'>
            <type>QuantLib::Time</type>
            <tensorRank>scalar</tensorRank>
            <description>time in year fraction</description>
          </Parameter>
          <Parameter name='Strike' exampleValue = '100'>
            <type>QuantLib::Real</type>
            <tensorRank>scalar</tensorRank>
            <description>strike</description>
          </Parameter>
        </Parameters>
      </ParameterList>
      <ReturnValue>
        <type>QuantLib::Real</type>
        <tensorRank>scalar</tensorRank>
      </ReturnValue>
    </Member>
 
In qlo\volatilities.hpp:
 
class LocalVolSurfaceImp : public LocalVolSurface {
      public:
        LocalVolSurfaceImp(const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
      const QuantLib::Handle<QuantLib::BlackVolTermStructure>& blackTS,
      const QuantLib::Handle<QuantLib::YieldTermStructure>& riskFreeTS,
      const QuantLib::Handle<QuantLib::YieldTermStructure>& dividendTS,
      const QuantLib::Handle<QuantLib::Quote> underlying,
      bool permanent);
 };
 
In qlo\termstructures.hpp :
 
OH_OBJ_CLASS(LocalVolSurface, VolatilityTermStructure);
 
In qlo\volatilities.cpp:
 LocalVolSurfaceImp::LocalVolSurfaceImp(
   const boost::shared_ptr<ObjectHandler::ValueObject> &properties,
   const QuantLib::Handle<QuantLib::BlackVolTermStructure>& blackTS,
   const QuantLib::Handle<QuantLib::YieldTermStructure>& riskFreeTS,
   const QuantLib::Handle<QuantLib::YieldTermStructure>& dividendTS,
   const QuantLib::Handle<QuantLib::Quote> underlying,
   bool permanent) : LocalVolSurface(properties, permanent) {
   
   libraryObject_ = boost::shared_ptr<QuantLib::LocalVolSurface>(new
   QuantLib::LocalVolSurface(blackTS, riskFreeTS, dividendTS, underlying));
 }

Thanks!
 
 
> Subject: Re: [Quantlib-users] Expose a QuantLib class method to QuantLibAddin

> From: [hidden email]
> To: [hidden email]
> CC: [hidden email]
> Date: Thu, 30 Jun 2011 12:20:38 +0200
>
>
> On Thu, 2011-06-30 at 11:54 +0200, g m wrote:
> > I'm Actually trying to expose the LocalVolSurface class, I need to use
> > its localVolImpl(Time, Real) method.
> > my understanding is that I have to write Constructor and Method
> > descriptions in a xml file (I chose volatilities.xml file),
> > compile the qlgensrc project, then, write a representation of
> > QuantLib::LocalVolSurface class in the QuantLibObjects project
> > (in volatilities.hpp and volatilities.cpp) to have something like
> > QuantLibAddin::LocalVolSurface. Is that right?
>
> Correct. Also look at termstructures.hpp, which defines the base
> classes.
>
> > The other issue is that the LocalVolSurface::localVolImpl is a
> > protected method and I've got compilation errors because of that.
> > How can I expose such method to Excel?
>
> Export the public LocalVolSurface::localVol(Time, Real, bool) instead.
>
> Luigi
>
>
> --
>
> Vin: It's like this fellow I knew in El Paso. One day, he just took
> all his clothes off and jumped in a mess of cactus. I asked him that
> same question, "Why?"
> Calvera: And?
> Vin: He said, "It seemed like a good idea at the time."
> -- The Magnificent Seven
>
>

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users