QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
mceuropeanbasketengine.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003 Neil Firth
6 Copyright (C) 2003 Ferdinando Ametrano
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22#include <ql/pricingengines/basket/mceuropeanbasketengine.hpp>
23#include <utility>
24
25namespace QuantLib {
26
27 EuropeanMultiPathPricer::EuropeanMultiPathPricer(ext::shared_ptr<BasketPayoff> payoff,
28 DiscountFactor discount)
29 : payoff_(std::move(payoff)), discount_(discount) {}
30
32 const {
33 Size n = multiPath.pathSize();
34 QL_REQUIRE(n>0, "the path cannot be empty");
35
36 Size numAssets = multiPath.assetNumber();
37 QL_REQUIRE(numAssets>0, "there must be some paths");
38
39 Size j;
40 // calculate the final price of each asset
41 Array finalPrice(numAssets, 0.0);
42 for (j = 0; j < numAssets; j++)
43 finalPrice[j] = multiPath[j].back();
44 return (*payoff_)(finalPrice) * discount_;
45 }
46
47}
48
1-D array used in linear algebra.
Definition: array.hpp:52
ext::shared_ptr< BasketPayoff > payoff_
EuropeanMultiPathPricer(ext::shared_ptr< BasketPayoff > payoff, DiscountFactor discount)
Real operator()(const MultiPath &multiPath) const override
Correlated multiple asset paths.
Definition: multipath.hpp:39
Size pathSize() const
Definition: multipath.hpp:48
Size assetNumber() const
Definition: multipath.hpp:47
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.