47 class FdmStorageValue :
public FdmInnerValueCalculator {
49 explicit FdmStorageValue(ext::shared_ptr<FdmMesher> mesher)
52 Real innerValue(
const FdmLinearOpIterator& iter,
Time)
override {
57 Real avgInnerValue(
const FdmLinearOpIterator& iter,
Time t)
override {
58 return innerValue(iter,
t);
66 class LessButNotCloseEnough {
75 ext::shared_ptr<ExtendedOrnsteinUhlenbeckProcess> process,
76 ext::shared_ptr<YieldTermStructure> rTS,
80 ext::shared_ptr<Shape> shape,
82 : process_(
std::move(process)),
rTS_(
std::move(rTS)), tGrid_(tGrid), xGrid_(xGrid),
83 yGrid_(yGrid), shape_(
std::move(shape)), schemeDesc_(schemeDesc) {}
89 "Bermudan exercise supported only");
93 =
rTS_->dayCounter().yearFraction(
rTS_->referenceDate(),
96 const ext::shared_ptr<Fdm1dMesher> xMesher(
99 ext::shared_ptr<Fdm1dMesher> storageMesher;
104 storageValues.reserve(
109 storageValues.push_back(level);
113 const std::set<Real, LessButNotCloseEnough> orderedValues(
114 storageValues.begin(), storageValues.end());
115 storageValues.assign(orderedValues.begin(), orderedValues.end());
117 storageMesher = ext::shared_ptr<Fdm1dMesher>(
122 storageMesher = ext::shared_ptr<Fdm1dMesher>(
126 const ext::shared_ptr<FdmMesher> mesher (
130 ext::shared_ptr<FdmInnerValueCalculator> storageCalculator(
131 new FdmStorageValue(mesher));
134 std::list<ext::shared_ptr<StepCondition<Array> > > stepConditions;
135 std::list<std::vector<Time> > stoppingTimes;
138 std::vector<Time> exerciseTimes;
140 const Time t =
rTS_->dayCounter().yearFraction(
rTS_->referenceDate(), i);
142 QL_REQUIRE(
t >= 0,
"exercise dates must not contain past date");
143 exerciseTimes.push_back(
t);
145 stoppingTimes.push_back(exerciseTimes);
147 ext::shared_ptr<Payoff>
payoff(
150 ext::shared_ptr<FdmInnerValueCalculator> underlyingCalculator(
155 mesher, underlyingCalculator,
158 ext::shared_ptr<FdmStepConditionComposite> conditions(
166 storageCalculator, maturity,
tGrid_, 0 };
168 ext::shared_ptr<FdmSimple2dExtOUSolver> solver(
FdSimpleExtOUStorageEngine(ext::shared_ptr< ExtendedOrnsteinUhlenbeckProcess > p, ext::shared_ptr< YieldTermStructure > rTS, Size tGrid=50, Size xGrid=100, Size yGrid=Null< Size >(), ext::shared_ptr< Shape > shape=ext::shared_ptr< Shape >(), const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Douglas())
void calculate() const override
const ext::shared_ptr< Shape > shape_
const ext::shared_ptr< YieldTermStructure > rTS_
const ext::shared_ptr< ExtendedOrnsteinUhlenbeckProcess > process_
const FdmSchemeDesc schemeDesc_
VanillaStorageOption::results results_
VanillaStorageOption::arguments arguments_
Shared handle to an observable.
template class providing a null value for a given type.
condition to be applied at every time step
ext::shared_ptr< BermudanExercise > exercise
floating-point comparisons
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
ext::function< Real(Real)> b
extended Ornstein-Uhlenbeck process
const ext::shared_ptr< YieldTermStructure > rTS_
inner value calculator for an exponential extended Ornstein Uhlenbeck grid
layer of abstraction to calculate the inner value
memory layout of a fdm linear operator
FdmMesher which is a composite of Fdm1dMesher.
solver for simple swing options based on ext OU process
One-dimensional grid mesher.
simple storage step condition
composite of fdm step conditions
const ext::shared_ptr< FdmMesher > mesher_
Finite Differences Black-Scholes engine for simple swing options.
Finite Differences extended OU engine for simple storage options.
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
ext::shared_ptr< QuantLib::Payoff > payoff
bool close_enough(const Quantity &m1, const Quantity &m2, Size n)
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
ext::shared_ptr< BlackVolTermStructure > v
One-dimensional mesher build from a given set of points.
Interest-rate term structure.