42 std::vector<std::vector<NodeData> >& collectedData) {
44 std::vector<Real> numerairesHeld;
47 "a single product is required");
55 std::vector<Size> numberCashFlowsThisStep(1);
56 std::vector<std::vector<CashFlow> > cashFlowsGenerated(1);
57 cashFlowsGenerated[0].resize(
69 n = cashFlowTimes.size();
70 std::vector<MarketModelDiscounter> productDiscounters;
71 productDiscounters.reserve(
n);
73 productDiscounters.emplace_back(cashFlowTimes[i], rateTimes);
75 n = rebateTimes.size();
76 std::vector<MarketModelDiscounter> rebateDiscounters;
77 rebateDiscounters.reserve(
n);
79 rebateDiscounters.emplace_back(rebateTimes[i], rateTimes);
80 n = controlTimes.size();
81 std::vector<MarketModelDiscounter> controlDiscounters;
82 controlDiscounters.reserve(
n);
84 controlDiscounters.emplace_back(controlTimes[i], rateTimes);
87 const std::vector<Size>& numeraires = evolver.
numeraires();
89 const std::vector<Time>& evolutionTimes = evolution.
evolutionTimes();
91 std::valarray<bool> isProductTime =
94 std::valarray<bool> isRebateTime =
97 std::valarray<bool> isControlTime =
100 std::valarray<bool> isBasisTime =
103 std::valarray<bool> isExerciseTime(
false,evolutionTimes.size());
105 Size exercises = 0, idx = 0;
106 for (i=0; i<evolutionTimes.size(); ++i) {
107 if (isRebateTime[i]) {
109 isExerciseTime[i] =
true;
115 collectedData.resize(exercises+1);
116 for (i=0; i<collectedData.size(); ++i)
117 collectedData[i].resize(numberOfPaths);
120 for (i=0; i<numberOfPaths; ++i) {
125 dataProvider.
reset();
126 Real principalInNumerairePortfolio = 1.0;
129 Size nextExercise = 0;
130 collectedData[0][i].cumulatedCashFlows = 0.0;
135 Size numeraire = numeraires[currentStep];
137 if (isRebateTime[currentStep])
139 if (isControlTime[currentStep])
141 if (isBasisTime[currentStep])
142 dataProvider.
nextStep(currentState);
144 if (isExerciseTime[currentStep]) {
145 NodeData& data = collectedData[nextExercise+1][i];
150 rebateDiscounters[exerciseValue.timeIndex]
151 .numeraireBonds(currentState, numeraire) /
152 principalInNumerairePortfolio;
154 dataProvider.
values(currentState,
160 controlDiscounters[controlValue.timeIndex]
161 .numeraireBonds(currentState, numeraire) /
162 principalInNumerairePortfolio;
171 if (isProductTime[currentStep]) {
173 numberCashFlowsThisStep,
176 for (
Size j=0; j<numberCashFlowsThisStep[0]; ++j) {
177 const CashFlow& cf = cashFlowsGenerated[0][j];
178 collectedData[nextExercise][i].cumulatedCashFlows +=
180 productDiscounters[cf.timeIndex]
181 .numeraireBonds(currentState, numeraire) /
182 principalInNumerairePortfolio;
187 Size nextNumeraire = numeraires[currentStep+1];
188 principalInNumerairePortfolio *=
196 for (
Size j = nextExercise; j < exercises; ++j) {
197 NodeData& data = collectedData[j+1][i];
Base class for cash flows.
virtual Real amount() const =0
returns the amount of the cash flow
Curve state for market-model simulations
virtual Real discountRatio(Size i, Size j) const =0
Market-model evolution description.
const std::vector< Time > & rateTimes() const
const std::vector< Time > & evolutionTimes() const
virtual const std::vector< Size > & numeraires() const =0
virtual Real advanceStep()=0
virtual const CurveState & currentState() const =0
virtual Size currentStep() const =0
virtual Real startNewPath()=0
virtual std::vector< Time > possibleCashFlowTimes() const =0
virtual MarketModelMultiProduct::CashFlow value(const CurveState &) const =0
virtual std::valarray< bool > isExerciseTime() const =0
virtual const EvolutionDescription & evolution() const =0
virtual void nextStep(const CurveState &)=0
virtual std::vector< Time > possibleCashFlowTimes() const =0
virtual Size numberOfProducts() const =0
virtual void reset()=0
during simulation put product at start of path
virtual Size maxNumberOfCashFlowsPerProductPerStep() const =0
virtual const EvolutionDescription & evolution() const =0
virtual bool nextTimeStep(const CurveState ¤tState, std::vector< Size > &numberCashFlowsThisStep, std::vector< std::vector< CashFlow > > &cashFlowsGenerated)=0
return value indicates whether path is finished, TRUE means done
virtual void values(const CurveState &, std::vector< Real > &results) const =0
virtual const EvolutionDescription & evolution() const =0
virtual void nextStep(const CurveState &)=0
Classes and functions for error handling.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
std::size_t Size
size of a container
std::valarray< bool > isInSubset(const std::vector< Time > &set, const std::vector< Time > &subset)
void collectNodeData(MarketModelEvolver &evolver, MarketModelMultiProduct &product, MarketModelNodeDataProvider &dataProvider, MarketModelExerciseValue &rebate, MarketModelExerciseValue &control, Size numberOfPaths, std::vector< std::vector< NodeData > > &collectedData)
ext::shared_ptr< BlackVolTermStructure > v
std::vector< Real > values