QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
adaptedpathpayoff.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2009 Andrea Odetti
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
20#include <ql/experimental/mcbasket/adaptedpathpayoff.hpp>
21
22namespace QuantLib {
23
24 /*
25 Initializing maximumTimeRead_ to -1 would make more sense,
26 but it is unsigned and 0 has exactly the same behaviour.
27 */
29 const Matrix& path,
30 const std::vector<Handle<YieldTermStructure> >& forwardTermStructures,
31 Array& payments,
32 Array& exercises,
33 std::vector<Array>& states)
34 : path_(path), forwardTermStructures_(forwardTermStructures), payments_(payments),
35 exercises_(exercises), states_(states)
36
37 {}
38
40 return path_.columns();
41 }
42
44 return path_.rows();
45 }
46
48 maximumTimeRead_ = std::max(maximumTimeRead_, time);
49
50 return path_[asset][time];
51 }
52
54 maximumTimeRead_ = std::max(maximumTimeRead_, time);
55
56 return forwardTermStructures_[time];
57 }
58
60 /*
61 This is to ensure the payoff is an adapted function.
62 We prevent payments to depend on future fixings.
63 */
64 QL_REQUIRE(time >= maximumTimeRead_,
65 "not adapted payoff: looking into the future");
66
67 payments_[time] = value;
68 }
69
71 Size time, Real exercise, Array & state) {
72 /*
73 This is to ensure the payoff is an adapted function.
74 We prevent payments to depend on future fixings.
75 */
76 QL_REQUIRE(time >= maximumTimeRead_,
77 "not adapted payoff: looking into the future");
78
79 if (!exercises_.empty())
80 exercises_[time] = exercise;
81
82 if (!states_.empty())
83 std::swap(states_[time], state);
84 }
85
86
88 const std::vector<Handle<YieldTermStructure> > & forwardTermStructures,
89 Array & payments,
90 Array & exercises,
91 std::vector<Array> & states) const {
92 ValuationData data(path, forwardTermStructures, payments, exercises, states);
93
94 operator()(data);
95 }
96}
void setExerciseData(Size time, Real exercise, Array &state)
const Handle< YieldTermStructure > & getYieldTermStructure(Size time)
ValuationData(const Matrix &path, const std::vector< Handle< YieldTermStructure > > &forwardTermStructures, Array &payments, Array &exercises, std::vector< Array > &states)
virtual void operator()(ValuationData &data) const =0
void value(const Matrix &path, const std::vector< Handle< YieldTermStructure > > &forwardTermStructures, Array &payments, Array &exercises, std::vector< Array > &states) const override
1-D array used in linear algebra.
Definition: array.hpp:52
Shared handle to an observable.
Definition: handle.hpp:41
Matrix used in linear algebra.
Definition: matrix.hpp:41
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35