24 const QuantLib::ext::shared_ptr<StochasticProcess>& process,
const TimeGrid& timeGrid,
25 const std::vector<Size>& stateProcessProjection,
26 const QuantLib::ext::shared_ptr<MultiPathVariateGeneratorBase>& variateGenerator)
27 : process_(process), timeGrid_(timeGrid), stateProcessProjection_(stateProcessProjection),
28 variateGenerator_(variateGenerator), next_(MultiPath(process->size(), timeGrid), 1.0) {
30 for (Size s = 0; s <
process_->size(); ++s)
33 QL_REQUIRE(stateProcessProjection.size() == process->factors(),
34 "ProjectedVariateMultiPathGenerator: state process projection source size ("
35 << stateProcessProjection.size() <<
") does not match process factors (" << process->factors());
36 QL_REQUIRE(!stateProcessProjection.empty(),
37 "ProjectedVariateMultiPathGenerator: state process projection is empty");
39 maxTargetIndex_ = *std::max_element(stateProcessProjection.begin(), stateProcessProjection.end());
45 next_.weight = v.weight;
47 QL_REQUIRE(v.value.size() ==
timeGrid_.size() - 1,
48 "ProjectedVariateMultiPathGenerator::next(): variate generator returns "
49 << v.value.size() <<
" variates for " << (
timeGrid_.size() - 1) <<
" time steps to evolve");
51 QL_REQUIRE(v.value.size() == 0 ||
maxTargetIndex_ < v.value.front().size(),
52 "ProjectedVariateMultiPathGenerator::next(): variate generator returns variate of size "
53 << v.value.front().size() <<
", this is required to be > max target index (" <<
maxTargetIndex_
60 Array state =
process_->initialValues();
61 for (Size i = 0; i <
timeGrid_.size() - 1; ++i) {
62 for (Size d = 0; d < dim; ++d)
65 for (Size s = 0; s < stateSize; ++s)
66 next_.value[s][i + 1] = state[s];
const QuantLib::ext::shared_ptr< StochasticProcess > process_
Sample< MultiPath > next_
const std::vector< Size > stateProcessProjection_
const QuantLib::ext::shared_ptr< MultiPathVariateGeneratorBase > variateGenerator_
ProjectedVariateMultiPathGenerator(const QuantLib::ext::shared_ptr< StochasticProcess > &process, const TimeGrid &timeGrid, const std::vector< Size > &stateProcessProjection, const QuantLib::ext::shared_ptr< MultiPathVariateGeneratorBase > &variateGenerator)
const Sample< MultiPath > & next() const override
multi path generator projecting variates from another variate generator