20#include <ql/exercise.hpp>
21#include <ql/pricingengines/exotic/analyticsimplechooserengine.hpp>
22#include <ql/instruments/payoffs.hpp>
23#include <ql/math/distributions/normaldistribution.hpp>
29 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
30 : process_(
std::move(process)) {
39 QL_REQUIRE(rfdc==divdc,
40 "Risk-free rate and dividend yield must"
41 "have the same day counter");
42 QL_REQUIRE(rfdc==voldc,
43 "Risk-free rate and volatility must"
44 "have the same day counter");
46 auto payoff = ext::dynamic_pointer_cast<StrikedTypePayoff>(
arguments_.
payoff);
47 QL_REQUIRE(payoff,
"non-plain payoff given");
48 Real strike = payoff->strike();
56 process_->dividendYield()->zeroRate(maturity, divdc,
59 process_->riskFreeRate()->zeroRate(maturity, rfdc,
62 QL_REQUIRE(spot > 0.0,
"negative or null spot value");
63 QL_REQUIRE(strike > 0.0,
"negative or null strike value");
64 QL_REQUIRE(volatility > 0.0,
65 "negative or null volatility");
66 QL_REQUIRE(timeToChoosing > 0.0,
67 "choosing date earlier than or equal to evaluation date");
69 Real d = (std::log(spot/strike)
70 + ((riskFreeRate-dividendRate) + volatility*volatility*0.5)*timeToMaturity)
71 /(volatility*std::sqrt(timeToMaturity));
73 Real y = (std::log(spot/strike) + (riskFreeRate-dividendRate)*timeToMaturity
74 + (volatility*volatility*timeToChoosing/2))
75 /(volatility*std::sqrt(timeToChoosing));
79 results_.
value = spot*std::exp(-dividendRate*timeToMaturity)*f(d)
80 - strike*std::exp(-riskFreeRate*timeToMaturity)
81 *f(d-volatility*std::sqrt(timeToMaturity))
82 -spot*std::exp(-dividendRate*timeToMaturity)*f(-y)
83 +strike*std::exp(-riskFreeRate*timeToMaturity)
84 *f(-y+volatility*std::sqrt(timeToChoosing));
void calculate() const override
AnalyticSimpleChooserEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process)
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
Cumulative normal distribution function.
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.
SimpleChooserOption::results results_
SimpleChooserOption::arguments arguments_
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
ext::shared_ptr< Exercise > exercise
ext::shared_ptr< Payoff > payoff
DateProxy & evaluationDate()
the date at which pricing is to be performed.
static Settings & instance()
access to the unique instance
@ NoFrequency
null frequency
Real Volatility
volatility