25#ifndef quantlib_forward_engine_hpp
26#define quantlib_forward_engine_hpp
48 template <
class Engine>
50 :
public GenericEngine<ForwardOptionArguments<VanillaOption::arguments>,
51 VanillaOption::results> {
59 ext::shared_ptr<GeneralizedBlackScholesProcess>
process_;
68 template <
class Engine>
70 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
71 : process_(
std::move(process)) {
76 template <
class Engine>
79 ext::shared_ptr<StrikedTypePayoff> argumentsPayoff =
80 ext::dynamic_pointer_cast<StrikedTypePayoff>(
81 this->arguments_.payoff);
82 QL_REQUIRE(argumentsPayoff,
"wrong payoff given");
84 ext::shared_ptr<StrikedTypePayoff>
payoff(
86 this->arguments_.moneyness *
93 QL_REQUIRE(spot->value() > 0.0,
"negative or null underlying given");
95 ext::shared_ptr<YieldTermStructure>(
97 this->arguments_.resetDate)));
99 ext::shared_ptr<YieldTermStructure>(
101 this->arguments_.resetDate)));
108 ext::shared_ptr<BlackVolTermStructure>(
110 this->arguments_.resetDate)));
112 ext::shared_ptr<GeneralizedBlackScholesProcess> fwdProcess(
117 originalEngine_ = ext::shared_ptr<Engine>(
new Engine(fwdProcess));
118 originalEngine_->reset();
122 originalEngine_->getArguments());
123 QL_REQUIRE(originalArguments_,
"wrong engine type");
126 originalEngine_->getResults());
127 QL_REQUIRE(originalResults_,
"wrong engine type");
129 originalArguments_->payoff =
payoff;
130 originalArguments_->exercise = this->arguments_.exercise;
132 originalArguments_->validate();
135 template <
class Engine>
138 originalEngine_->calculate();
139 getOriginalResults();
142 template <
class Engine>
145 DayCounter rfdc = process_->riskFreeRate()->dayCounter();
146 DayCounter divdc = process_->dividendYield()->dayCounter();
148 process_->riskFreeRate()->referenceDate(),
149 this->arguments_.resetDate);
151 this->arguments_.resetDate);
155 if (originalResults_->delta !=
Null<Real>() &&
156 originalResults_->strikeSensitivity !=
Null<Real>()) {
157 this->
results_.delta = discQ * (originalResults_->delta +
158 this->arguments_.moneyness *
159 originalResults_->strikeSensitivity);
162 this->
results_.theta = process_->dividendYield()->
166 this->
results_.vega = discQ * originalResults_->vega;
168 this->
results_.rho = discQ * originalResults_->rho;
169 if (originalResults_->dividendRho !=
Null<Real>()) {
171 + discQ * originalResults_->dividendRho;
const Instrument::results * results_
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Forward engine for vanilla options
ext::shared_ptr< Engine > originalEngine_
void calculate() const override
void getOriginalResults() const
VanillaOption::arguments * originalArguments_
const VanillaOption::results * originalResults_
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
ForwardVanillaEngine(ext::shared_ptr< GeneralizedBlackScholesProcess >)
Generalized Black-Scholes stochastic process.
template base class for option pricing engines
Shared handle to an observable.
Implied term structure at a given date in the future.
Implied vol term structure at a given date in the future.
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Option exercise classes and payoff function.
Forward version of a vanilla option.
@ NoFrequency
null frequency
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
Implied Black Vol Term Structure.
ext::shared_ptr< QuantLib::Payoff > payoff
Payoffs for various options.
Vanilla option on a single asset.