QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
multisteppathwisewrapper.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4Copyright (C) 2009 Mark Joshi
5
6This file is part of QuantLib, a free-software/open-source library
7for financial quantitative analysts and developers - http://quantlib.org/
8
9QuantLib is free software: you can redistribute it and/or modify it
10under the terms of the QuantLib license. You should have received a
11copy of the license along with this program; if not, please email
12<quantlib-dev@lists.sf.net>. The license is also available online at
13<http://quantlib.org/license.shtml>.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
24
25namespace QuantLib
26{
28 : innerProduct_(innerProduct), cashFlowsGenerated_ (innerProduct.numberOfProducts(), std::vector<MarketModelPathwiseMultiProduct::CashFlow>(innerProduct.maxNumberOfCashFlowsPerProductPerStep())),
29 numberOfProducts_(innerProduct.numberOfProducts())
30 {
31
32 for (auto& i : cashFlowsGenerated_)
33 for (auto& j : i)
34 j.amount.resize(1 + innerProduct.evolution().numberOfRates());
35 }
36
38 {
39 return innerProduct_->possibleCashFlowTimes();
40 }
41
43 {
44 return innerProduct_->numberOfProducts();
45 }
46
48 {
49 return innerProduct_->maxNumberOfCashFlowsPerProductPerStep();
50 }
51
53 {
54 innerProduct_->reset();
55 }
56
58 const CurveState& currentState,
59 std::vector<Size>& numberCashFlowsThisStep,
60 std::vector<std::vector<CashFlow> >& cashFlowsGenerated)
61 {
62 bool done = innerProduct_->nextTimeStep(currentState, numberCashFlowsThisStep,cashFlowsGenerated_);
63
64 // tranform the data
65 for (Size i=0; i < numberOfProducts_; ++i)
66 for (Size j=0; j< numberCashFlowsThisStep[i]; ++j)
67 {
68 cashFlowsGenerated[i][j].timeIndex =cashFlowsGenerated_[i][j].timeIndex;
69 cashFlowsGenerated[i][j].amount =cashFlowsGenerated_[i][j].amount[0];
70 }
71
72
73 return done;
74 }
75
77 {
78 return innerProduct_->suggestedNumeraires();
79 }
80
82 {
83 return innerProduct_->evolution();
84 }
85
86 std::unique_ptr<MarketModelMultiProduct>
88 {
89 return std::unique_ptr<MarketModelMultiProduct>(new MultiProductPathwiseWrapper(*this));
90 }
91
92
93
94}
95
Curve state for market-model simulations
Definition: curvestate.hpp:41
Market-model evolution description.
virtual const EvolutionDescription & evolution() const =0
std::vector< Size > suggestedNumeraires() const override
Clone< MarketModelPathwiseMultiProduct > innerProduct_
std::unique_ptr< MarketModelMultiProduct > clone() const override
returns a newly-allocated copy of itself
MultiProductPathwiseWrapper(const MarketModelPathwiseMultiProduct &innerProduct_)
std::vector< std::vector< MarketModelPathwiseMultiProduct::CashFlow > > cashFlowsGenerated_
bool nextTimeStep(const CurveState &currentState, std::vector< Size > &numberCashFlowsThisStep, std::vector< std::vector< CashFlow > > &cashFlowsGenerated) override
return value indicates whether path is finished, TRUE means done
std::vector< Time > possibleCashFlowTimes() const override
const EvolutionDescription & evolution() const override
void reset() override
during simulation put product at start of path
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.
std::vector< std::vector< CashFlow > > cashFlowsGenerated_