32 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
34 Size maxNrIntegrationSteps)
35 : process_(
std::move(process)),
37 maxNrIntegrationSteps_(maxNrIntegrationSteps) {
43 "must be Average::Type Arithmetic ");
46 "not a European Option");
48 const ext::shared_ptr<PlainVanillaPayoff>
payoff =
49 ext::dynamic_pointer_cast<PlainVanillaPayoff>(
arguments_.payoff);
53 std::sort(fixingDates.begin(), fixingDates.end());
55 Size futureFixings = fixingDates.size();
62 if ( futureFixings > 0
65 fixingDates.erase(fixingDates.begin());
68 runningAccumulator +=
process_->x0();
71 if (futureFixings == 0) {
72 QL_REQUIRE(pastFixings > 0,
"no past fixings given");
74 * rTS->discount(exerciseDate);
80 "last fixing date must be before exercise date");
82 "first fixing date is in the past");
84 QL_REQUIRE(std::adjacent_find(fixingDates.begin(), fixingDates.end())
85 == fixingDates.end(),
"two fixing dates are the same");
87 const Real accruedAverage = (pastFixings != 0)
88 ?
Real(runningAccumulator / (pastFixings + futureFixings))
91 const Real strike =
payoff->strike() - accruedAverage;
92 QL_REQUIRE(strike >= 0.0,
"effective strike should to be positive");
96 const Date volRefDate = volTS->referenceDate();
99 if (futureFixings > 1) {
100 std::vector<Time> fixingTimes(futureFixings), variances(futureFixings);
101 for (
Size i=0; i < futureFixings; ++i) {
102 const Date& fixingDate = fixingDates[i];
103 fixingTimes[i] = volDc.
yearFraction(volRefDate, fixingDate);
104 variances[i] =
process_->blackVolatility()->blackVariance(fixingDate, strike);
107 Matrix rho(futureFixings, futureFixings);
108 for (
Size i=0; i <
rho.rows(); ++i)
109 for (
Size j=i; j <
rho.columns(); ++j)
111 variances[std::min(i,j)] / std::sqrt(variances[i]*variances[j]);
114 ext::make_shared<FlatForward>(rTS->referenceDate(), 0.0, rTS->dayCounter())
117 std::vector<ext::shared_ptr<GeneralizedBlackScholesProcess> > processes;
118 processes.reserve(futureFixings);
119 for (
Size i=0; i < futureFixings; ++i) {
120 const Date& fixingDate = fixingDates[i];
122 * std::sqrt(fixingTimes[i]/fixingTimes.back());
124 processes.emplace_back(
125 ext::make_shared<GeneralizedBlackScholesProcess>(
127 ext::make_shared<SimpleQuote>(
128 process_->x0()*qTS->discount(fixingDate)/rTS->discount(fixingDate)
133 ext::make_shared<BlackConstantVol>(
134 volRefDate, volTS->calendar(),
144 ext::make_shared<AverageBasketPayoff>(
145 ext::make_shared<PlainVanillaPayoff>(
payoff->optionType(), strike),
146 Array(futureFixings, 1.0/(futureFixings + pastFixings))
148 ext::make_shared<EuropeanExercise>(fixingDates.back())
151 ext::make_shared<ChoiBasketEngine>(
157 else if (futureFixings == 1) {
161 process_->x0()/(pastFixings + futureFixings)
162 *qTS->discount(fixingDates.back())/rTS->discount(fixingDates.back()),
163 std::sqrt(volTS->blackVariance(fixingDates.back(), strike)),
164 rTS->discount(exerciseDate)
Basket option on a number of assets.
Black constant volatility, no time dependence, no strike dependence.
Black Scholes arithmetic Asian option engine.
Jaehyuk Choi: Sum of all Black-Scholes-Merton Models.
1-D array used in linear algebra.
Basket option on a number of assets.
const Size maxNrIntegrationSteps_
ChoiAsianEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > p, Real lambda=15, Size maxNrIntegrationSteps=2<< 21)
void calculate() const override
const ext::shared_ptr< GeneralizedBlackScholesProcess > process_
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.
Average::Type averageType
std::vector< Date > fixingDates
DiscreteAveragingAsianOption::results results_
DiscreteAveragingAsianOption::arguments arguments_
Shared handle to an observable.
Real NPV() const
returns the net present value of the instrument.
void setPricingEngine(const ext::shared_ptr< PricingEngine > &)
set the pricing engine to be used.
Matrix used in linear algebra.
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.
flat forward rate term structure
Real Time
continuous quantity with 1-year units
Real Volatility
volatility
std::size_t Size
size of a container
ext::shared_ptr< QuantLib::Payoff > payoff
Real blackFormula(Option::Type optionType, Real strike, Real forward, Real stdDev, Real discount, Real displacement)