QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
mcpathbasketengine.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) 2008 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
21#include <utility>
22
23namespace QuantLib {
24
26 ext::shared_ptr<PathPayoff>& payoff,
27 std::vector<Size> timePositions,
28 std::vector<Handle<YieldTermStructure> > forwardTermStructures,
29 Array discounts)
30 : payoff_(payoff), timePositions_(std::move(timePositions)),
31 forwardTermStructures_(std::move(forwardTermStructures)), discounts_(std::move(discounts)) {}
32
34 const {
35
36 Size n = multiPath.pathSize();
37 QL_REQUIRE(n > 0, "the path cannot be empty");
38
39 Size numberOfAssets = multiPath.assetNumber();
40 QL_REQUIRE(numberOfAssets > 0, "there must be some paths");
41
42 const Size numberOfTimes = timePositions_.size();
43
44 Matrix path(numberOfAssets, numberOfTimes, Null<Real>());
45
46 for (Size i = 0; i < numberOfTimes; ++i) {
47 const Size pos = timePositions_[i];
48 for (Size j = 0; j < numberOfAssets; ++j)
49 path[j][i] = multiPath[j][pos];
50 }
51
52 Array values(numberOfTimes, 0.0);
53
54 // ignored
55 Array exercises;
56 std::vector<Array> states;
57
58 payoff_->value(path, forwardTermStructures_, values, exercises, states);
59
60 // in this engine we ignore early exercise
61
62 Real discountedPayoff = DotProduct(values, discounts_);
63
64 return discountedPayoff;
65 }
66
67}
68
1-D array used in linear algebra.
Definition: array.hpp:52
ext::shared_ptr< PathPayoff > payoff_
std::vector< Handle< YieldTermStructure > > forwardTermStructures_
Real operator()(const MultiPath &multiPath) const override
EuropeanPathMultiPathPricer(ext::shared_ptr< PathPayoff > &payoff, std::vector< Size > timePositions, std::vector< Handle< YieldTermStructure > > forwardTermStructures, Array discounts)
Shared handle to an observable.
Definition: handle.hpp:41
Matrix used in linear algebra.
Definition: matrix.hpp:41
Correlated multiple asset paths.
Definition: multipath.hpp:39
Size pathSize() const
Definition: multipath.hpp:48
Size assetNumber() const
Definition: multipath.hpp:47
template class providing a null value for a given type.
Definition: null.hpp:76
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
const ext::shared_ptr< Payoff > payoff_
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
ext::shared_ptr< QuantLib::Payoff > payoff
Path-dependent European basket MC engine.
Definition: any.hpp:35
Real DotProduct(const Array &v1, const Array &v2)
Definition: array.hpp:553
STL namespace.