QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
longstaffschwartzmultipathpricer.hpp
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) 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
28#include <ql/functional.hpp>
29#include <memory>
30
31namespace QuantLib {
32
33 //! Longstaff-Schwarz path pricer for early exercise options
34 /*! References:
35
36 Francis Longstaff, Eduardo Schwartz, 2001. Valuing American Options
37 by Simulation: A Simple Least-Squares Approach, The Review of
38 Financial Studies, Volume 14, No. 1, 113-147
39
40 \ingroup mcarlo
41
42 \test the correctness of the returned value is tested by
43 reproducing results available in web/literature
44 */
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
Maps function, bind and cref to either the boost or std implementation.
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
utility classes for Longstaff-Schwartz early-exercise Monte Carlo
Correlated multiple asset paths.
Definition: any.hpp:35
Option payoff classes.
base class for single-path pricers
Interest-rate term structure.