Wrapping QuantLib::VanillaSwap class

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

Wrapping QuantLib::VanillaSwap class

Raj Subramani
I have to maintain dimensions such as tradeid, counterpartyname and various other parameters. I have therefore created a class called PlainVanillaSpotSwap with the header file - as follows:

PlainVanillaSpotSwap.h
class PlainVanillaSpotSwap
{
private:
std::string _tradeid;
...
...
public:
...
boost::shared_ptr<VanillaSwap> qlSwap;
}

My problem is I do not know how to lazy instantiate this shared pointer called qlSwap.

At the moment inside the constructor for PlainVanillaSpotSwap - I am doing

boost::shared_ptr<VanillaSwap> _qlSwap(new VanillaSwap(swapType, nominal, ... floatingLegDayCounter));

Obviously - _qlSwap is a local VanillaSwap object created inside the constructor and then I set
qlSwap = _qlSwap;

I would like to avoid this and initialize qlSwap in the constructor itself.

Its been a while since I coded in C++ so please be gentle!
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping QuantLib::VanillaSwap class

Luigi Ballabio
That would be

    qlSwap = boost::shared_ptr<VanillaSwap>(new VanillaSwap(swapType, nominal, ... floatingLegDayCounter));

Luigi


On Fri, Mar 31, 2017 at 10:41 AM Raj Subramani <[hidden email]> wrote:
I have to maintain dimensions such as tradeid, counterpartyname and various
other parameters. I have therefore created a class called
PlainVanillaSpotSwap with the header file - as follows:

PlainVanillaSpotSwap.h
class PlainVanillaSpotSwap
{
private:
std::string _tradeid;
...
...
public:
...
boost::shared_ptr<VanillaSwap> qlSwap;
}

My problem is I do not know how to lazy instantiate this shared pointer
called qlSwap.

At the moment inside the constructor for PlainVanillaSpotSwap - I am doing

boost::shared_ptr<VanillaSwap> _qlSwap(new VanillaSwap(swapType, nominal,
... floatingLegDayCounter));

Obviously - _qlSwap is a local VanillaSwap object created inside the
constructor and then I set
qlSwap = _qlSwap;

I would like to avoid this and initialize qlSwap in the constructor itself.

Its been a while since I coded in C++ so please be gentle!



--
View this message in context: http://quantlib.10058.n7.nabble.com/Wrapping-QuantLib-VanillaSwap-class-tp18163.html
Sent from the quantlib-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping QuantLib::VanillaSwap class

Raj Subramani
Muchas gracias - that worked today (but it did not last night - which was admittedly a long day!)