QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
longstaffschwartzmultipathpricer.hpp
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#ifndef quantlib_longstaff_schwartz_multi_path_pricer_hpp
21#define quantlib_longstaff_schwartz_multi_path_pricer_hpp
22
23#include <ql/termstructures/yieldtermstructure.hpp>
24#include <ql/methods/montecarlo/pathpricer.hpp>
25#include <ql/methods/montecarlo/multipath.hpp>
26#include <ql/methods/montecarlo/lsmbasissystem.hpp>
27#include <ql/experimental/mcbasket/pathpayoff.hpp>
28#include <ql/functional.hpp>
29#include <memory>
30
31namespace QuantLib {
32
34
45 class LongstaffSchwartzMultiPathPricer : public PathPricer<MultiPath> {
46 public:
47 LongstaffSchwartzMultiPathPricer(const ext::shared_ptr<PathPayoff>& payoff,
48 const std::vector<Size>& timePositions,
49 std::vector<Handle<YieldTermStructure> > forwardTermStructure,
50 Array discounts,
51 Size polynomialOrder,
52 LsmBasisSystem::PolynomialType polynomialType);
53
54 Real operator()(const MultiPath& multiPath) const override;
55 virtual void calibrate();
56
57 protected:
58 struct PathInfo {
59 explicit PathInfo(Size numberOfTimes);
60
61 Size pathLength() const;
62
65 std::vector<Array> states;
66 };
67
68 PathInfo transformPath(const MultiPath& path) const;
69
70 bool calibrationPhase_ = true;
71
72 const ext::shared_ptr<PathPayoff> payoff_;
73
74 std::unique_ptr<Array[]> coeff_;
75 std::unique_ptr<Real[]> lowerBounds_;
76
77 const std::vector<Size> timePositions_;
78 const std::vector<Handle<YieldTermStructure> > forwardTermStructures_;
79 const Array dF_;
80
81 mutable std::vector<PathInfo> paths_;
82 const std::vector<ext::function<Real(Array)> > v_;
83 };
84
85}
86
87
88#endif
1-D array used in linear algebra.
Definition: array.hpp:52
Shared handle to an observable.
Definition: handle.hpp:41
Longstaff-Schwarz path pricer for early exercise options.
const std::vector< Handle< YieldTermStructure > > forwardTermStructures_
const std::vector< ext::function< Real(Array)> > v_
Real operator()(const MultiPath &multiPath) const override
Correlated multiple asset paths.
Definition: multipath.hpp:39
base class for path pricers
Definition: pathpricer.hpp:40
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