25 class LookbackFixedPathPricer :
public PathPricer<Path> {
30 Real operator()(
const Path& path)
const override;
37 class LookbackPartialFixedPathPricer :
public PathPricer<Path> {
39 LookbackPartialFixedPathPricer(
Time lookbackStart,
43 Real operator()(
const Path& path)
const override;
51 class LookbackFloatingPathPricer :
public PathPricer<Path> {
55 Real operator()(
const Path& path)
const override;
62 class LookbackPartialFloatingPathPricer :
public PathPricer<Path> {
64 LookbackPartialFloatingPathPricer(
Time lookbackEnd,
67 Real operator()(
const Path& path)
const override;
77 ext::shared_ptr<PathPricer<Path> >
82 ext::shared_ptr<PlainVanillaPayoff>
payoff =
83 ext::dynamic_pointer_cast<PlainVanillaPayoff>(args.payoff);
86 return ext::shared_ptr<PathPricer<Path> >(
87 new LookbackFixedPathPricer(
payoff->optionType(),
92 ext::shared_ptr<PathPricer<Path> >
97 ext::shared_ptr<PlainVanillaPayoff>
payoff =
98 ext::dynamic_pointer_cast<PlainVanillaPayoff>(args.payoff);
103 return ext::shared_ptr<PathPricer<Path> >(
104 new LookbackPartialFixedPathPricer(lookbackStart,
110 ext::shared_ptr<PathPricer<Path> >
115 ext::shared_ptr<FloatingTypePayoff>
payoff =
116 ext::dynamic_pointer_cast<FloatingTypePayoff>(args.payoff);
119 return ext::shared_ptr<PathPricer<Path> >(
120 new LookbackFloatingPathPricer(
payoff->optionType(),
124 ext::shared_ptr<PathPricer<Path> >
129 ext::shared_ptr<FloatingTypePayoff>
payoff =
130 ext::dynamic_pointer_cast<FloatingTypePayoff>(args.payoff);
135 return ext::shared_ptr<PathPricer<Path> >(
136 new LookbackPartialFloatingPathPricer(lookbackEnd,
144 LookbackFixedPathPricer::LookbackFixedPathPricer(
148 :
payoff_(type, strike), discount_(discount) {
150 "strike less than zero not allowed");
153 Real LookbackFixedPathPricer::operator()(
const Path& path)
const {
154 QL_REQUIRE(!path.empty(),
"the path cannot be empty");
157 switch (
payoff_.optionType()) {
159 underlying = *std::min_element(path.begin()+1, path.end());
162 underlying = *std::max_element(path.begin()+1, path.end());
165 QL_FAIL(
"unknown option type");
168 return payoff_(underlying) * discount_;
172 LookbackPartialFixedPathPricer::LookbackPartialFixedPathPricer(
177 : lookbackStart_(lookbackStart),
payoff_(type, strike), discount_(discount) {
179 "strike less than zero not allowed");
182 Real LookbackPartialFixedPathPricer::operator()(
const Path& path)
const {
183 QL_REQUIRE(!path.empty(),
"the path cannot be empty");
185 const TimeGrid& timeGrid = path.timeGrid();
186 Size startIndex = timeGrid.closestIndex(lookbackStart_);
188 switch (
payoff_.optionType()) {
190 underlying = *std::min_element(path.begin()+startIndex+1, path.end());
193 underlying = *std::max_element(path.begin()+startIndex+1, path.end());
196 QL_FAIL(
"unknown option type");
199 return payoff_(underlying) * discount_;
203 LookbackFloatingPathPricer::LookbackFloatingPathPricer(
206 :
payoff_(type), discount_(discount) {}
208 Real LookbackFloatingPathPricer::operator()(
const Path& path)
const {
209 QL_REQUIRE(!path.empty(),
"the path cannot be empty");
211 Real terminalPrice = path.back();
213 switch (
payoff_.optionType()) {
215 strike = *std::min_element(path.begin()+1, path.end());
218 strike = *std::max_element(path.begin()+1, path.end());
221 QL_FAIL(
"unknown option type");
224 return payoff_(terminalPrice, strike) * discount_;
228 LookbackPartialFloatingPathPricer::LookbackPartialFloatingPathPricer(
232 : lookbackEnd_(lookbackEnd),
payoff_(type), discount_(discount) {}
234 Real LookbackPartialFloatingPathPricer::operator()(
const Path& path)
const {
235 QL_REQUIRE(!path.empty(),
"the path cannot be empty");
237 const TimeGrid& timeGrid = path.timeGrid();
238 Size endIndex = timeGrid.closestIndex(lookbackEnd_);
239 Real terminalPrice = path.back();
242 switch (
payoff_.optionType()) {
244 strike = *std::min_element(path.begin()+1, path.begin()+endIndex+1);
247 strike = *std::max_element(path.begin()+1, path.begin()+endIndex+1);
250 QL_FAIL(
"unknown option type");
253 return payoff_(terminalPrice, strike) * discount_;
Arguments for continuous fixed lookback option calculation
Arguments for continuous floating lookback option calculation
Arguments for continuous partial fixed lookback option calculation
Arguments for continuous partial floating lookback option calculation
Generalized Black-Scholes stochastic process.
Time time(const Date &) const override
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
const ext::shared_ptr< Payoff > payoff_
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
std::size_t Size
size of a container
ext::shared_ptr< QuantLib::Payoff > payoff
Monte Carlo lookback fixed engines.
ext::shared_ptr< PathPricer< Path > > mc_lookback_path_pricer(const ContinuousFixedLookbackOption::arguments &args, const GeneralizedBlackScholesProcess &process, DiscountFactor discount)