QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
mc_discr_geom_av_price_heston.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) 2020 Jack Gillett
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 Real strike,
27 DiscountFactor discount,
28 std::vector<Size> fixingIndices,
29 Real runningProduct,
30 Size pastFixings)
31 : payoff_(type, strike), discount_(discount), fixingIndices_(std::move(fixingIndices)),
32 runningProduct_(runningProduct), pastFixings_(pastFixings) {
33 QL_REQUIRE(strike>=0.0,
34 "strike less than zero not allowed");
35 }
36
38 const Path& path = multiPath[0];
39 const Size n = multiPath.pathSize();
40 QL_REQUIRE(n>0, "the path cannot be empty");
41
42 Real averagePrice = 1.0;
43 Real product = runningProduct_;
44 Size fixings = pastFixings_ + fixingIndices_.size();
45
46 // care must be taken not to overflow product
47 constexpr double maxValue = QL_MAX_REAL;
48 for (unsigned long fixingIndice : fixingIndices_) {
49 Real price = path[fixingIndice];
50 if (product < maxValue/price) {
51 product *= price;
52 } else {
53 averagePrice *= std::pow(product, 1.0/fixings);
54 product = price;
55 }
56 }
57
58 averagePrice *= std::pow(product, 1.0/fixings);
59 return discount_ * payoff_(averagePrice);
60 }
61
62}
GeometricAPOHestonPathPricer(Option::Type type, Real strike, DiscountFactor discount, std::vector< Size > fixingIndices, Real runningProduct=1.0, Size pastFixings=0)
Real operator()(const MultiPath &multiPath) const override
Correlated multiple asset paths.
Definition: multipath.hpp:39
Size pathSize() const
Definition: multipath.hpp:48
single-factor random walk
Definition: path.hpp:40
#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_
#define QL_MAX_REAL
Definition: qldefines.hpp:176
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
Heston MC engine for discrete geometric average price Asian.
Definition: any.hpp:35
STL namespace.