QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
mc_discr_arith_av_strike.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis
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
24#ifndef quantlib_mc_discrete_arithmetic_average_strike_asian_engine_hpp
25#define quantlib_mc_discrete_arithmetic_average_strike_asian_engine_hpp
26
27#include <ql/exercise.hpp>
28#include <ql/pricingengines/asian/mcdiscreteasianenginebase.hpp>
29#include <ql/processes/blackscholesprocess.hpp>
30#include <utility>
31
32namespace QuantLib {
33
35
36 template <class RNG = PseudoRandom, class S = Statistics>
38 : public MCDiscreteAveragingAsianEngineBase<SingleVariate,RNG,S> {
39 public:
40 typedef
47 // constructor
49 const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
50 bool brownianBridge,
51 bool antitheticVariate,
52 Size requiredSamples,
53 Real requiredTolerance,
54 Size maxSamples,
55 BigNatural seed);
56 protected:
57 ext::shared_ptr<path_pricer_type> pathPricer() const override;
58 };
59
60
61 class ArithmeticASOPathPricer : public PathPricer<Path> {
62 public:
64 DiscountFactor discount,
65 Real runningSum = 0.0,
66 Size pastFixings = 0);
67 Real operator()(const Path& path) const override;
68
69 private:
74 };
75
76
77
78 // inline definitions
79
80 template <class RNG, class S>
81 inline
83 const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
84 bool brownianBridge,
85 bool antitheticVariate,
86 Size requiredSamples,
87 Real requiredTolerance,
88 Size maxSamples,
89 BigNatural seed)
91 brownianBridge,
92 antitheticVariate,
93 false,
94 requiredSamples,
95 requiredTolerance,
96 maxSamples,
97 seed) {}
98
99 template <class RNG, class S>
100 inline
101 ext::shared_ptr<
104
105 ext::shared_ptr<PlainVanillaPayoff> payoff =
106 ext::dynamic_pointer_cast<PlainVanillaPayoff>(
107 this->arguments_.payoff);
108 QL_REQUIRE(payoff, "non-plain payoff given");
109
110 ext::shared_ptr<EuropeanExercise> exercise =
111 ext::dynamic_pointer_cast<EuropeanExercise>(
112 this->arguments_.exercise);
113 QL_REQUIRE(exercise, "wrong exercise given");
114
115 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
116 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(
117 this->process_);
118 QL_REQUIRE(process, "Black-Scholes process required");
119
120 return ext::shared_ptr<typename
123 payoff->optionType(),
124 process->riskFreeRate()->discount(exercise->lastDate()),
125 this->arguments_.runningAccumulator,
126 this->arguments_.pastFixings));
127 }
128
129
130
131 template <class RNG = PseudoRandom, class S = Statistics>
133 public:
135 ext::shared_ptr<GeneralizedBlackScholesProcess> process);
136 // named parameters
143 // conversion to pricing engine
144 operator ext::shared_ptr<PricingEngine>() const;
145 private:
146 ext::shared_ptr<GeneralizedBlackScholesProcess> process_;
147 bool antithetic_ = false;
150 bool brownianBridge_ = true;
152 };
153
154 template <class RNG, class S>
156 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
157 : process_(std::move(process)), samples_(Null<Size>()), maxSamples_(Null<Size>()),
158 tolerance_(Null<Real>()) {}
159
160 template <class RNG, class S>
163 QL_REQUIRE(tolerance_ == Null<Real>(),
164 "tolerance already set");
165 samples_ = samples;
166 return *this;
167 }
168
169 template <class RNG, class S>
172 Real tolerance) {
173 QL_REQUIRE(samples_ == Null<Size>(),
174 "number of samples already set");
175 QL_REQUIRE(RNG::allowsErrorEstimate,
176 "chosen random generator policy "
177 "does not allow an error estimate");
178 tolerance_ = tolerance;
179 return *this;
180 }
181
182 template <class RNG, class S>
185 maxSamples_ = samples;
186 return *this;
187 }
188
189 template <class RNG, class S>
192 seed_ = seed;
193 return *this;
194 }
195
196 template <class RNG, class S>
199 brownianBridge_ = b;
200 return *this;
201 }
202
203 template <class RNG, class S>
206 antithetic_ = b;
207 return *this;
208 }
209
210 template <class RNG, class S>
211 inline
213 operator ext::shared_ptr<PricingEngine>() const {
214 return ext::shared_ptr<PricingEngine>(
216 brownianBridge_,
217 antithetic_,
218 samples_, tolerance_,
219 maxSamples_,
220 seed_));
221 }
222
223}
224
225
226#endif
Real operator()(const Path &path) const override
Monte Carlo pricing engine for discrete arithmetic average-strike Asian.
MCDiscreteAveragingAsianEngineBase< SingleVariate, RNG, S >::path_pricer_type path_pricer_type
MCDiscreteAveragingAsianEngineBase< SingleVariate, RNG, S >::path_generator_type path_generator_type
MCDiscreteArithmeticASEngine(const ext::shared_ptr< GeneralizedBlackScholesProcess > &process, bool brownianBridge, bool antitheticVariate, Size requiredSamples, Real requiredTolerance, Size maxSamples, BigNatural seed)
ext::shared_ptr< path_pricer_type > pathPricer() const override
MCDiscreteAveragingAsianEngineBase< SingleVariate, RNG, S >::stats_type stats_type
Pricing engine for discrete average Asians using Monte Carlo simulation.
McSimulation< MC, RNG, S >::path_generator_type path_generator_type
McSimulation< MC, RNG, S >::path_pricer_type path_pricer_type
MakeMCDiscreteArithmeticASEngine & withSeed(BigNatural seed)
MakeMCDiscreteArithmeticASEngine & withMaxSamples(Size samples)
MakeMCDiscreteArithmeticASEngine & withBrownianBridge(bool b=true)
MakeMCDiscreteArithmeticASEngine & withAbsoluteTolerance(Real tolerance)
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
MakeMCDiscreteArithmeticASEngine & withAntitheticVariate(bool b=true)
MakeMCDiscreteArithmeticASEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process)
MakeMCDiscreteArithmeticASEngine & withSamples(Size samples)
template class providing a null value for a given type.
Definition: null.hpp:76
single-factor random walk
Definition: path.hpp:40
base class for path pricers
Definition: pathpricer.hpp:40
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
unsigned QL_BIG_INTEGER BigNatural
large positive integer
Definition: types.hpp:46
STL namespace.
default Monte Carlo traits for single-variate models
Definition: mctraits.hpp:39