Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
ProjectedVariateMultiPathGenerator Class Reference

#include <qle/methods/projectedvariatemultipathgenerator.hpp>

+ Inheritance diagram for ProjectedVariateMultiPathGenerator:
+ Collaboration diagram for ProjectedVariateMultiPathGenerator:

Public Member Functions

 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
 
void reset () override
 
- Public Member Functions inherited from MultiPathGeneratorBase
virtual ~MultiPathGeneratorBase ()
 
virtual const Sample< MultiPath > & next () const =0
 
virtual void reset ()=0
 

Private Attributes

const QuantLib::ext::shared_ptr< StochasticProcessprocess_
 
const TimeGrid timeGrid_
 
const std::vector< Size > stateProcessProjection_
 
const QuantLib::ext::shared_ptr< MultiPathVariateGeneratorBasevariateGenerator_
 
Size maxTargetIndex_
 
Sample< MultiPath > next_
 

Detailed Description

Definition at line 32 of file projectedvariatemultipathgenerator.hpp.

Constructor & Destructor Documentation

◆ ProjectedVariateMultiPathGenerator()

ProjectedVariateMultiPathGenerator ( const QuantLib::ext::shared_ptr< StochasticProcess > &  process,
const TimeGrid &  timeGrid,
const std::vector< Size > &  stateProcessProjection,
const QuantLib::ext::shared_ptr< MultiPathVariateGeneratorBase > &  variateGenerator 
)

If projection(j) = i for state process indices i from the projected process and j from the original process, then stateProcessProjection[i] = j, i.e. a state process component index from the projected model is mapped to the state process component index of the original model.

Definition at line 23 of file projectedvariatemultipathgenerator.cpp.

27 : process_(process), timeGrid_(timeGrid), stateProcessProjection_(stateProcessProjection),
28 variateGenerator_(variateGenerator), next_(MultiPath(process->size(), timeGrid), 1.0) {
29
30 for (Size s = 0; s < process_->size(); ++s)
31 next_.value[s][0] = process_->initialValues()[s];
32
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");
38
39 maxTargetIndex_ = *std::max_element(stateProcessProjection.begin(), stateProcessProjection.end());
40}
const QuantLib::ext::shared_ptr< StochasticProcess > process_
const QuantLib::ext::shared_ptr< MultiPathVariateGeneratorBase > variateGenerator_

Member Function Documentation

◆ next()

const Sample< MultiPath > & next ( ) const
overridevirtual

Implements MultiPathGeneratorBase.

Definition at line 42 of file projectedvariatemultipathgenerator.cpp.

42 {
43
44 Sample<std::vector<Array>> v = variateGenerator_->next();
45 next_.weight = v.weight;
46
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");
50
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_
54 << ")");
55
56 Size dim = process_->factors();
57 Size stateSize = process_->size();
58
59 Array dw(dim, 0.0);
60 Array state = process_->initialValues();
61 for (Size i = 0; i < timeGrid_.size() - 1; ++i) {
62 for (Size d = 0; d < dim; ++d)
63 dw[d] = v.value[i][stateProcessProjection_[d]];
64 state = process_->evolve(timeGrid_[i], state, timeGrid_.dt(i), dw);
65 for (Size s = 0; s < stateSize; ++s)
66 next_.value[s][i + 1] = state[s];
67 }
68 return next_;
69}

◆ reset()

void reset ( )
overridevirtual

Implements MultiPathGeneratorBase.

Definition at line 71 of file projectedvariatemultipathgenerator.cpp.

71{ variateGenerator_->reset(); }

Member Data Documentation

◆ process_

const QuantLib::ext::shared_ptr<StochasticProcess> process_
private

Definition at line 44 of file projectedvariatemultipathgenerator.hpp.

◆ timeGrid_

const TimeGrid timeGrid_
private

Definition at line 45 of file projectedvariatemultipathgenerator.hpp.

◆ stateProcessProjection_

const std::vector<Size> stateProcessProjection_
private

Definition at line 46 of file projectedvariatemultipathgenerator.hpp.

◆ variateGenerator_

const QuantLib::ext::shared_ptr<MultiPathVariateGeneratorBase> variateGenerator_
private

Definition at line 47 of file projectedvariatemultipathgenerator.hpp.

◆ maxTargetIndex_

Size maxTargetIndex_
private

Definition at line 49 of file projectedvariatemultipathgenerator.hpp.

◆ next_

Sample<MultiPath> next_
mutableprivate

Definition at line 51 of file projectedvariatemultipathgenerator.hpp.