Why QuantLib’s Garman-Kohlagen Process Requires a Handle
Summary
This exchange explains why a QuantLib currency option pricing process cannot be initialized with a shared pointer to a quote when its constructor expects a Handle<Quote>. The questioner wants to pass a direct smart pointer instead of a Handle, but the compiler reports that the pointer type does not match the required constructor argument.
The answer is that avoiding Handle requires changing the Garman-Kohlagen process constructor and the corresponding member type it initializes. The exchange gives no alternative implementation or discussion of the consequences, so it does not establish whether such a change is advisable or how it would affect QuantLib’s observer behavior. Its practical lesson is limited to matching the API’s declared types: a smart pointer cannot be substituted where the constructor requires a Handle without modifying that API.
Key ideas
- The process constructor requires a Handle<Quote> for its underlying quote.
- A shared pointer to SimpleQuote does not implicitly satisfy that constructor parameter.
- Avoiding Handle requires changing the constructor and its corresponding stored member type.
- The exchange does not describe the implementation or consequences of such a change.
Tags
Full text
# Is there any way to avoid using Handle
# 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.
## Answer by Luigi Ballabio (score 3, accepted)
https://quant.stackexchange.com/a/58071
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).Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.