38 :
a_(
std::move(a)), sig_(
std::move(sig)), K_(K) {
40 "Arrays must have the same size");
87 [](
Real x) ->
bool { return x >= 0.0; }
89 "a*sig should not be negative"
95 [](
Real x) ->
bool { return x > 0;}
99 "non-positive strikes only allowed for spread options");
104 ? std::min(10.0, std::max(-10.0,
119 QL_FAIL(
"unknown strategy type");
125 std::vector<ext::shared_ptr<GeneralizedBlackScholesProcess> > p,
128 n_(p.size()), processes_(
std::move(p)) {
131 [
this](
const auto& p) { registerWith(p); });
135 const ext::shared_ptr<AverageBasketPayoff> avgPayoff =
137 QL_REQUIRE(avgPayoff,
"average basket payoff expected");
138 const ext::shared_ptr<PlainVanillaPayoff>
payoff =
139 ext::dynamic_pointer_cast<PlainVanillaPayoff>(avgPayoff->basePayoff());
143 const Array weights = avgPayoff->weights();
145 "wrong number of weights arguments in payoff");
147 const ext::shared_ptr<EuropeanExercise> exercise =
149 QL_REQUIRE(exercise,
"not an European exercise");
150 const Date maturityDate = exercise->lastDate();
158 const Array v = stdDev*stdDev;
160 const Array fwdBasket = weights *
s * dq /dr0;
165 [](
Real x) ->
bool { return close_enough(x, 0.0); }
168 std::accumulate(fwdBasket.
begin(), fwdBasket.
end(),
Real(0.0)));
172 fwdBasket*
Exp(-0.5*
v), stdDev, strike)
181 Real(-strike*N(cp*
d)),
1-D array used in linear algebra.
const_iterator end() const
Size size() const
dimension of the array
const_iterator begin() const
Cumulative normal distribution function.
BasketOption::results results_
BasketOption::arguments arguments_
std::map< std::string, ext::any > additionalResults
ext::shared_ptr< Exercise > exercise
ext::shared_ptr< Payoff > payoff
void calculate() const override
SingleFactorBsmBasketEngine(std::vector< ext::shared_ptr< GeneralizedBlackScholesProcess > > p, Real xTol=1e4 *QL_EPSILON)
const std::vector< ext::shared_ptr< GeneralizedBlackScholesProcess > > processes_
Real solve(const F &f, Real accuracy, Real guess, Real step) const
Real derivative(Real x) const
Real operator()(Real x) const
Size getDerivativeCtr() const
SumExponentialsRootSolver(Array a, Array sig, Real K)
Real secondDerivative(Real x) const
Size getSecondDerivativeCtr() const
Real getRoot(Real xTol=1e6 *QL_EPSILON, Strategy strategy=Brent) const
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Option exercise classes and payoff function.
Real DiscountFactor
discount factor between dates
std::size_t Size
size of a container
ext::shared_ptr< QuantLib::Payoff > payoff
functionals and combinators not included in the STL
Array Exp(const Array &v)
normal, cumulative and inverse cumulative distributions
ext::shared_ptr< BlackVolTermStructure > v
Basket engine where all underlyings are driven by one stochastic factor.