28 class ValueEstimate :
public CostFunction {
30 ValueEstimate(
const std::vector<NodeData>& simulationData,
31 const ParametricExercise& exercise,
33 Real value(
const Array& parameters)
const override;
34 Array values(
const Array&)
const override {
35 QL_FAIL(
"values method not implemented");
45 ValueEstimate::ValueEstimate(
46 const std::vector<NodeData>& simulationData,
47 const ParametricExercise& exercise,
51 parameters_(exercise.numberOfParameters()[exerciseIndex]) {
59 Real ValueEstimate::value(
const Array& parameters)
const {
60 std::copy(parameters.begin(), parameters.end(),
68 sum += i.exerciseValue;
70 sum += i.cumulatedCashFlows;
81 std::vector<std::vector<NodeData> >& simulationData,
83 std::vector<std::vector<Real> >& parameters,
87 Size steps = simulationData.size();
88 parameters.resize(steps-1);
90 for (
Size i=steps-1; i!=0; --i) {
91 const std::vector<NodeData>& exerciseData = simulationData[i];
97 ValueEstimate
f(exerciseData, exercise, i-1);
99 Array guess(parameters[i-1].size());
100 exercise.
guess(i-1, parameters[i-1]);
101 std::copy(parameters[i-1].begin(), parameters[i-1].end(),
110 std::copy(result.
begin(), result.
end(),
111 parameters[i-1].begin());
113 std::vector<NodeData>& previousData = simulationData[i-1];
114 for (
Size j=0; j<previousData.size(); ++j) {
115 if (exerciseData[j].isValid) {
118 exerciseData[j].values))
119 previousData[j].cumulatedCashFlows +=
120 exerciseData[j].exerciseValue;
122 previousData[j].cumulatedCashFlows +=
123 exerciseData[j].cumulatedCashFlows;
129 const std::vector<NodeData>& initialData = simulationData.front();
130 for (
const auto& i : initialData)
131 sum += i.cumulatedCashFlows;
132 return sum/initialData.size();
1-D array used in linear algebra.
const_iterator end() const
const_iterator begin() const
Criteria to end optimization process:
Abstract class for constrained optimization method.
virtual EndCriteria::Type minimize(Problem &P, const EndCriteria &endCriteria)=0
minimize the optimization problem P
virtual void guess(Size exerciseNumber, std::vector< Real > ¶meters) const =0
virtual std::vector< Size > numberOfParameters() const =0
virtual bool exercise(Size exerciseNumber, const std::vector< Real > ¶meters, const std::vector< Real > &variables) const =0
Constrained optimization problem.
const Array & currentValue() const
current value of the local minimum
Abstract constraint class.
#define QL_FAIL(message)
throw an error (possibly with file and line information)
std::size_t Size
size of a container
Real genericEarlyExerciseOptimization(std::vector< std::vector< NodeData > > &simulationData, const ParametricExercise &exercise, std::vector< std::vector< Real > > ¶meters, const EndCriteria &endCriteria, OptimizationMethod &method)
returns the biased estimate obtained while optimizing
std::vector< Real > parameters_
const ParametricExercise & exercise_
const std::vector< NodeData > & simulationData_
Abstract optimization problem class.