# Is there any way to avoid using Handle

I was trying to replicate one example from

http://www.bnikolic.co.uk/blog/ql-fx-option-simple.html

In QuantLib general practice is to use Handle to manage change in the observed variable. I am fine with that.

However for my case, I do not want to use Handle but want to use direct pointer (smart). So I replace below line -

Handle<Quote> underlyingH(boost::shared_ptr<Quote>(new SimpleQuote(in.S)));


with

boost::shared_ptr<SimpleQuote> underlyingH = boost::make_shared<SimpleQuote>(in.S);


With this I am getting error as -

/Users/aa.cpp:60:59: error: no matching constructor for initialization of
'QuantLib::GarmanKohlagenProcess'
boost::shared_ptr<GarmanKohlagenProcess> process(new GarmanKohlagenProcess(underlyingH, fTS, rTS, flatVolTS));
^                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/ql/processes/blackscholesprocess.hpp:196:9: note: candidate constructor not viable: no known conversion from 'boost::shared_ptr<SimpleQuote>' to
'const Handle<QuantLib::Quote>' for 1st argument
GarmanKohlagenProcess(
^
/usr/local/include/ql/processes/blackscholesprocess.hpp:194:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 4 were
provided
class GarmanKohlagenProcess : public GeneralizedBlackScholesProcess {
^
1 error generated.


Is there any way to not use Handle?

Many thanks for your kind help.

The constructor of GarmanKohlagenProcess takes a Handle, so if you really want to avoid it you'll have to modify the constructor (and the type of the corresponding data member it initializes).
• Is there any way to writing the same line as something like underlyingH = ... instead underlyingH(...) – Daniel Sep 18 '20 at 7:47
• Handle<Quote> underlyingH = Handle<Quote>(...), or auto underlyingH = Handle<Quote>(...) if you're using C++11 or later – Luigi Ballabio Sep 18 '20 at 11:55