QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
exerciseadapter.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006 Mark Joshi
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy 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
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
21
22namespace QuantLib {
23
25 const Clone<MarketModelExerciseValue>& exercise,
26 Size numberOfProducts)
27 : MultiProductMultiStep(exercise->evolution().rateTimes()),
28 exercise_(exercise), numberOfProducts_(numberOfProducts),
29 isExerciseTime_(exercise->isExerciseTime()) {}
30
32 const CurveState& currentState,
33 std::vector<Size>& numberCashFlowsThisStep,
34 std::vector<std::vector<MarketModelMultiProduct::CashFlow> >&
35 generatedCashFlows) {
36 std::fill(numberCashFlowsThisStep.begin(),
37 numberCashFlowsThisStep.end(), 0);
38 bool done = false;
39
40 exercise_->nextStep(currentState);
43 exercise_->value(currentState);
44 numberCashFlowsThisStep[0] = 1;
45 generatedCashFlows[0][0] = cashflow;
46 done = true;
47 }
49 return done || currentIndex_ == isExerciseTime_.size();
50 }
51
52 std::unique_ptr<MarketModelMultiProduct>
54 return std::unique_ptr<MarketModelMultiProduct>(new ExerciseAdapter(*this));
55 }
56
57}
58
cloning proxy to an underlying object
Definition: clone.hpp:40
Curve state for market-model simulations
Definition: curvestate.hpp:41
std::unique_ptr< MarketModelMultiProduct > clone() const override
returns a newly-allocated copy of itself
bool nextTimeStep(const CurveState &, std::vector< Size > &, std::vector< std::vector< CashFlow > > &) override
return value indicates whether path is finished, TRUE means done
Clone< MarketModelExerciseValue > exercise_
ExerciseAdapter(const Clone< MarketModelExerciseValue > &exercise, Size numberOfProducts=1)
std::valarray< bool > isExerciseTime_
Multiple-step market-model product.
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
const ParametricExercise & exercise_