25#ifndef quantlib_quanto_engine_hpp
26#define quantlib_quanto_engine_hpp
28#include <ql/instruments/payoffs.hpp>
29#include <ql/instruments/quantovanillaoption.hpp>
30#include <ql/processes/blackscholesprocess.hpp>
31#include <ql/termstructures/yield/quantotermstructure.hpp>
48 template <
class Instr,
class Engine>
51 QuantoOptionResults<typename Instr::results> > {
53 QuantoEngine(ext::shared_ptr<GeneralizedBlackScholesProcess>,
60 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
69 template <
class Instr,
class Engine>
71 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
75 : process_(
std::move(process)), foreignRiskFreeRate_(
std::move(foreignRiskFreeRate)),
76 exchangeRateVolatility_(
std::move(exchangeRateVolatility)),
77 correlation_(
std::move(correlation)) {
84 template <
class Instr,
class Engine>
88 Real exchangeRateATMlevel = 1.0;
91 ext::shared_ptr<StrikedTypePayoff> payoff =
92 ext::dynamic_pointer_cast<StrikedTypePayoff>(
93 this->arguments_.payoff);
94 QL_REQUIRE(payoff,
"non-striked payoff given");
95 Real strike = payoff->strike();
98 QL_REQUIRE(spot->value() > 0.0,
"negative or null underlying");
102 ext::shared_ptr<YieldTermStructure>(
104 process_->riskFreeRate(),
105 foreignRiskFreeRate_,
106 process_->blackVolatility(),
108 exchangeRateVolatility_,
109 exchangeRateATMlevel,
110 correlation_->value())));
113 ext::shared_ptr<GeneralizedBlackScholesProcess> quantoProcess(
115 riskFreeRate, blackVol));
117 ext::shared_ptr<Engine> originalEngine(
new Engine(quantoProcess));
118 originalEngine->reset();
119 auto* originalArguments =
120 dynamic_cast<typename Instr::arguments*
>(originalEngine->getArguments());
121 QL_REQUIRE(originalArguments,
"wrong engine type");
123 *originalArguments = this->arguments_;
125 originalArguments->validate();
126 originalEngine->calculate();
128 const auto* originalResults =
129 dynamic_cast<const typename Instr::results*
>(originalEngine->getResults());
130 QL_REQUIRE(originalResults,
"wrong engine type");
132 this->results_.
value = originalResults->value;
133 this->results_.delta = originalResults->delta;
134 this->results_.gamma = originalResults->gamma;
135 this->results_.theta = originalResults->theta;
137 originalResults->dividendRho !=
Null<Real>()) {
138 this->results_.rho = originalResults->rho +
139 originalResults->dividendRho;
140 this->results_.dividendRho = originalResults->dividendRho;
142 this->results_.rho = this->results_.dividendRho =
Null<Real>();
145 exchangeRateVolatility_->blackVol(
146 this->arguments_.exercise->lastDate(),
147 exchangeRateATMlevel);
149 && originalResults->dividendRho !=
Null<Real>()) {
150 this->results_.vega = originalResults->vega +
151 correlation_->value() * exchangeRateFlatVol *
152 originalResults->dividendRho;
157 if (originalResults->dividendRho !=
Null<Real>()) {
158 Volatility volatility = process_->blackVolatility()->blackVol(
159 this->arguments_.exercise->lastDate(),
160 process_->stateVariable()->value());
161 this->results_.qvega = correlation_->value() *
162 process_->blackVolatility()->blackVol(
163 this->arguments_.exercise->lastDate(),
164 process_->stateVariable()->value()) *
165 originalResults->dividendRho;
166 this->results_.qrho = - originalResults->dividendRho;
167 this->results_.qlambda = exchangeRateFlatVol *
168 volatility * originalResults->dividendRho;
170 this->results_.qvega = this->results_.qrho =
Generalized Black-Scholes stochastic process.
template base class for option pricing engines
Shared handle to an observable.
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Handle< Quote > correlation_
Handle< YieldTermStructure > foreignRiskFreeRate_
QuantoEngine(ext::shared_ptr< GeneralizedBlackScholesProcess >, Handle< YieldTermStructure > foreignRiskFreeRate, Handle< BlackVolTermStructure > exchangeRateVolatility, Handle< Quote > correlation)
void calculate() const override
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
Handle< BlackVolTermStructure > exchangeRateVolatility_
Real Volatility
volatility