QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
lookbackoption.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006 Warren Chou
5 Copyright (C) 2007 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21#include <ql/instruments/lookbackoption.hpp>
22
23namespace QuantLib {
24
26 Real minmax,
27 const ext::shared_ptr<TypePayoff>& payoff,
28 const ext::shared_ptr<Exercise>& exercise)
29 : OneAssetOption(payoff, exercise),
30 minmax_(minmax) {}
31
33 PricingEngine::arguments* args) const {
34
36
37 auto* moreArgs = dynamic_cast<ContinuousFloatingLookbackOption::arguments*>(args);
38 QL_REQUIRE(moreArgs != nullptr, "wrong argument type");
39 moreArgs->minmax = minmax_;
40 }
41
43
44 OneAssetOption::arguments::validate();
45
46 QL_REQUIRE(minmax != Null<Real>(), "null prior extremum");
47 QL_REQUIRE(minmax >= 0.0, "nonnegative prior extremum required: "
48 << minmax << " not allowed");
49 }
50
51
53 Real minmax,
54 const ext::shared_ptr<StrikedTypePayoff>& payoff,
55 const ext::shared_ptr<Exercise>& exercise)
57 minmax_(minmax) {}
58
60 PricingEngine::arguments* args) const {
61
63
64 auto* moreArgs = dynamic_cast<ContinuousFixedLookbackOption::arguments*>(args);
65 QL_REQUIRE(moreArgs != nullptr, "wrong argument type");
66 moreArgs->minmax = minmax_;
67 }
68
70
71 OneAssetOption::arguments::validate();
72
73 QL_REQUIRE(minmax != Null<Real>(), "null prior extremum");
74 QL_REQUIRE(minmax >= 0.0, "nonnegative prior extremum required: "
75 << minmax << " not allowed");
76 }
77
79 Real minmax,
80 Real lambda,
81 Date lookbackPeriodEnd,
82 const ext::shared_ptr<TypePayoff>& payoff,
83 const ext::shared_ptr<Exercise>& exercise)
85 lambda_(lambda),
86 lookbackPeriodEnd_(lookbackPeriodEnd) {}
87
89 PricingEngine::arguments* args) const {
90
92
93 auto* moreArgs = dynamic_cast<ContinuousPartialFloatingLookbackOption::arguments*>(args);
94 QL_REQUIRE(moreArgs != nullptr, "wrong argument type");
95 moreArgs->lambda = lambda_;
96 moreArgs->lookbackPeriodEnd = lookbackPeriodEnd_;
97 }
98
100
102
103 ext::shared_ptr<EuropeanExercise> europeanExercise =
104 ext::dynamic_pointer_cast<EuropeanExercise>(exercise);
105 QL_REQUIRE(lookbackPeriodEnd <= europeanExercise->lastDate(),
106 "lookback start date must be earlier than exercise date");
107
108 ext::shared_ptr<FloatingTypePayoff> floatingTypePayoff =
109 ext::dynamic_pointer_cast<FloatingTypePayoff>(payoff);
110
111 if (floatingTypePayoff->optionType() == Option::Call) {
112 QL_REQUIRE(lambda >= 1.0,
113 "lambda should be greater than or equal to 1 for calls");
114 }
115 if (floatingTypePayoff->optionType() == Option::Put) {
116 QL_REQUIRE(lambda <= 1.0,
117 "lambda should be smaller than or equal to 1 for puts");
118 }
119 }
120
122 Date lookbackPeriodStart,
123 const ext::shared_ptr<StrikedTypePayoff>& payoff,
124 const ext::shared_ptr<Exercise>& exercise)
126 lookbackPeriodStart_(lookbackPeriodStart) {}
127
129 PricingEngine::arguments* args) const {
130
132
133 auto* moreArgs = dynamic_cast<ContinuousPartialFixedLookbackOption::arguments*>(args);
134 QL_REQUIRE(moreArgs != nullptr, "wrong argument type");
135 moreArgs->lookbackPeriodStart = lookbackPeriodStart_;
136 }
137
139
141
142 ext::shared_ptr<EuropeanExercise> europeanExercise =
143 ext::dynamic_pointer_cast<EuropeanExercise>(exercise);
144 QL_REQUIRE(lookbackPeriodStart <= europeanExercise->lastDate(),
145 "lookback start date must be earlier than exercise date");
146 }
147}
148
Arguments for continuous fixed lookback option calculation
Continuous-fixed lookback option.
void setupArguments(PricingEngine::arguments *) const override
ContinuousFixedLookbackOption(Real currentMinmax, const ext::shared_ptr< StrikedTypePayoff > &payoff, const ext::shared_ptr< Exercise > &exercise)
Arguments for continuous floating lookback option calculation
Continuous-floating lookback option.
void setupArguments(PricingEngine::arguments *) const override
ContinuousFloatingLookbackOption(Real currentMinmax, const ext::shared_ptr< TypePayoff > &payoff, const ext::shared_ptr< Exercise > &exercise)
Arguments for continuous partial fixed lookback option calculation
void setupArguments(PricingEngine::arguments *) const override
ContinuousPartialFixedLookbackOption(Date lookbackPeriodStart, const ext::shared_ptr< StrikedTypePayoff > &payoff, const ext::shared_ptr< Exercise > &exercise)
Arguments for continuous partial floating lookback option calculation
ContinuousPartialFloatingLookbackOption(Real currentMinmax, Real lambda, Date lookbackPeriodEnd, const ext::shared_ptr< TypePayoff > &payoff, const ext::shared_ptr< Exercise > &exercise)
void setupArguments(PricingEngine::arguments *) const override
Concrete date class.
Definition: date.hpp:125
virtual void setupArguments(PricingEngine::arguments *) const
Definition: instrument.cpp:45
template class providing a null value for a given type.
Definition: null.hpp:76
Base class for options on a single asset.
ext::shared_ptr< Payoff > payoff() const
Definition: option.hpp:45
ext::shared_ptr< Exercise > exercise() const
Definition: option.hpp:46
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35