/src/quantlib/ql/experimental/mcbasket/mcpathbasketengine.cpp
Line | Count | Source |
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 | | <https://www.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/mcpathbasketengine.hpp> |
21 | | #include <utility> |
22 | | |
23 | | namespace QuantLib { |
24 | | |
25 | | EuropeanPathMultiPathPricer::EuropeanPathMultiPathPricer( |
26 | | ext::shared_ptr<PathPayoff>& payoff, |
27 | | std::vector<Size> timePositions, |
28 | | std::vector<Handle<YieldTermStructure> > forwardTermStructures, |
29 | | Array discounts) |
30 | 0 | : payoff_(payoff), timePositions_(std::move(timePositions)), |
31 | 0 | forwardTermStructures_(std::move(forwardTermStructures)), discounts_(std::move(discounts)) {} |
32 | | |
33 | | Real EuropeanPathMultiPathPricer::operator()(const MultiPath& multiPath) |
34 | 0 | const { |
35 | |
|
36 | 0 | Size n = multiPath.pathSize(); |
37 | 0 | QL_REQUIRE(n > 0, "the path cannot be empty"); |
38 | | |
39 | 0 | Size numberOfAssets = multiPath.assetNumber(); |
40 | 0 | QL_REQUIRE(numberOfAssets > 0, "there must be some paths"); |
41 | | |
42 | 0 | const Size numberOfTimes = timePositions_.size(); |
43 | |
|
44 | 0 | Matrix path(numberOfAssets, numberOfTimes, Null<Real>()); |
45 | |
|
46 | 0 | for (Size i = 0; i < numberOfTimes; ++i) { |
47 | 0 | const Size pos = timePositions_[i]; |
48 | 0 | for (Size j = 0; j < numberOfAssets; ++j) |
49 | 0 | path[j][i] = multiPath[j][pos]; |
50 | 0 | } |
51 | |
|
52 | 0 | Array values(numberOfTimes, 0.0); |
53 | | |
54 | | // ignored |
55 | 0 | Array exercises; |
56 | 0 | std::vector<Array> states; |
57 | |
|
58 | 0 | payoff_->value(path, forwardTermStructures_, values, exercises, states); |
59 | | |
60 | | // in this engine we ignore early exercise |
61 | |
|
62 | 0 | Real discountedPayoff = DotProduct(values, discounts_); |
63 | |
|
64 | 0 | return discountedPayoff; |
65 | 0 | } |
66 | | |
67 | | } |
68 | | |