/src/quantlib/ql/instruments/lookbackoption.cpp
Line | Count | Source |
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 | | <https://www.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 | | |
23 | | namespace QuantLib { |
24 | | |
25 | | ContinuousFloatingLookbackOption::ContinuousFloatingLookbackOption( |
26 | | Real minmax, |
27 | | const ext::shared_ptr<TypePayoff>& payoff, |
28 | | const ext::shared_ptr<Exercise>& exercise) |
29 | 0 | : OneAssetOption(payoff, exercise), |
30 | 0 | minmax_(minmax) {}Unexecuted instantiation: QuantLib::ContinuousFloatingLookbackOption::ContinuousFloatingLookbackOption(double, boost::shared_ptr<QuantLib::TypePayoff> const&, boost::shared_ptr<QuantLib::Exercise> const&) Unexecuted instantiation: QuantLib::ContinuousFloatingLookbackOption::ContinuousFloatingLookbackOption(double, boost::shared_ptr<QuantLib::TypePayoff> const&, boost::shared_ptr<QuantLib::Exercise> const&) |
31 | | |
32 | | void ContinuousFloatingLookbackOption::setupArguments( |
33 | 0 | PricingEngine::arguments* args) const { |
34 | |
|
35 | 0 | OneAssetOption::setupArguments(args); |
36 | |
|
37 | 0 | auto* moreArgs = dynamic_cast<ContinuousFloatingLookbackOption::arguments*>(args); |
38 | 0 | QL_REQUIRE(moreArgs != nullptr, "wrong argument type"); |
39 | 0 | moreArgs->minmax = minmax_; |
40 | 0 | } |
41 | | |
42 | 0 | void ContinuousFloatingLookbackOption::arguments::validate() const { |
43 | |
|
44 | 0 | OneAssetOption::arguments::validate(); |
45 | |
|
46 | 0 | QL_REQUIRE(minmax != Null<Real>(), "null prior extremum"); |
47 | 0 | QL_REQUIRE(minmax >= 0.0, "nonnegative prior extremum required: " |
48 | 0 | << minmax << " not allowed"); |
49 | 0 | } |
50 | | |
51 | | |
52 | | ContinuousFixedLookbackOption::ContinuousFixedLookbackOption( |
53 | | Real minmax, |
54 | | const ext::shared_ptr<StrikedTypePayoff>& payoff, |
55 | | const ext::shared_ptr<Exercise>& exercise) |
56 | 0 | : OneAssetOption(payoff, exercise), |
57 | 0 | minmax_(minmax) {}Unexecuted instantiation: QuantLib::ContinuousFixedLookbackOption::ContinuousFixedLookbackOption(double, boost::shared_ptr<QuantLib::StrikedTypePayoff> const&, boost::shared_ptr<QuantLib::Exercise> const&) Unexecuted instantiation: QuantLib::ContinuousFixedLookbackOption::ContinuousFixedLookbackOption(double, boost::shared_ptr<QuantLib::StrikedTypePayoff> const&, boost::shared_ptr<QuantLib::Exercise> const&) |
58 | | |
59 | | void ContinuousFixedLookbackOption::setupArguments( |
60 | 0 | PricingEngine::arguments* args) const { |
61 | |
|
62 | 0 | OneAssetOption::setupArguments(args); |
63 | |
|
64 | 0 | auto* moreArgs = dynamic_cast<ContinuousFixedLookbackOption::arguments*>(args); |
65 | 0 | QL_REQUIRE(moreArgs != nullptr, "wrong argument type"); |
66 | 0 | moreArgs->minmax = minmax_; |
67 | 0 | } |
68 | | |
69 | 0 | void ContinuousFixedLookbackOption::arguments::validate() const { |
70 | |
|
71 | 0 | OneAssetOption::arguments::validate(); |
72 | |
|
73 | 0 | QL_REQUIRE(minmax != Null<Real>(), "null prior extremum"); |
74 | 0 | QL_REQUIRE(minmax >= 0.0, "nonnegative prior extremum required: " |
75 | 0 | << minmax << " not allowed"); |
76 | 0 | } |
77 | | |
78 | | ContinuousPartialFloatingLookbackOption::ContinuousPartialFloatingLookbackOption( |
79 | | Real minmax, |
80 | | Real lambda, |
81 | | Date lookbackPeriodEnd, |
82 | | const ext::shared_ptr<TypePayoff>& payoff, |
83 | | const ext::shared_ptr<Exercise>& exercise) |
84 | 0 | : ContinuousFloatingLookbackOption(minmax, payoff, exercise), |
85 | 0 | lambda_(lambda), |
86 | 0 | lookbackPeriodEnd_(lookbackPeriodEnd) {}Unexecuted instantiation: QuantLib::ContinuousPartialFloatingLookbackOption::ContinuousPartialFloatingLookbackOption(double, double, QuantLib::Date, boost::shared_ptr<QuantLib::TypePayoff> const&, boost::shared_ptr<QuantLib::Exercise> const&) Unexecuted instantiation: QuantLib::ContinuousPartialFloatingLookbackOption::ContinuousPartialFloatingLookbackOption(double, double, QuantLib::Date, boost::shared_ptr<QuantLib::TypePayoff> const&, boost::shared_ptr<QuantLib::Exercise> const&) |
87 | | |
88 | | void ContinuousPartialFloatingLookbackOption::setupArguments( |
89 | 0 | PricingEngine::arguments* args) const { |
90 | |
|
91 | 0 | ContinuousFloatingLookbackOption::setupArguments(args); |
92 | |
|
93 | 0 | auto* moreArgs = dynamic_cast<ContinuousPartialFloatingLookbackOption::arguments*>(args); |
94 | 0 | QL_REQUIRE(moreArgs != nullptr, "wrong argument type"); |
95 | 0 | moreArgs->lambda = lambda_; |
96 | 0 | moreArgs->lookbackPeriodEnd = lookbackPeriodEnd_; |
97 | 0 | } |
98 | | |
99 | 0 | void ContinuousPartialFloatingLookbackOption::arguments::validate() const { |
100 | |
|
101 | 0 | ContinuousFloatingLookbackOption::arguments::validate(); |
102 | |
|
103 | 0 | ext::shared_ptr<EuropeanExercise> europeanExercise = |
104 | 0 | ext::dynamic_pointer_cast<EuropeanExercise>(exercise); |
105 | 0 | QL_REQUIRE(lookbackPeriodEnd <= europeanExercise->lastDate(), |
106 | 0 | "lookback start date must be earlier than exercise date"); |
107 | | |
108 | 0 | ext::shared_ptr<FloatingTypePayoff> floatingTypePayoff = |
109 | 0 | ext::dynamic_pointer_cast<FloatingTypePayoff>(payoff); |
110 | | |
111 | 0 | if (floatingTypePayoff->optionType() == Option::Call) { |
112 | 0 | QL_REQUIRE(lambda >= 1.0, |
113 | 0 | "lambda should be greater than or equal to 1 for calls"); |
114 | 0 | } |
115 | 0 | if (floatingTypePayoff->optionType() == Option::Put) { |
116 | 0 | QL_REQUIRE(lambda <= 1.0, |
117 | 0 | "lambda should be smaller than or equal to 1 for puts"); |
118 | 0 | } |
119 | 0 | } |
120 | | |
121 | | ContinuousPartialFixedLookbackOption::ContinuousPartialFixedLookbackOption( |
122 | | Date lookbackPeriodStart, |
123 | | const ext::shared_ptr<StrikedTypePayoff>& payoff, |
124 | | const ext::shared_ptr<Exercise>& exercise) |
125 | 0 | : ContinuousFixedLookbackOption(0, payoff, exercise), |
126 | 0 | lookbackPeriodStart_(lookbackPeriodStart) {}Unexecuted instantiation: QuantLib::ContinuousPartialFixedLookbackOption::ContinuousPartialFixedLookbackOption(QuantLib::Date, boost::shared_ptr<QuantLib::StrikedTypePayoff> const&, boost::shared_ptr<QuantLib::Exercise> const&) Unexecuted instantiation: QuantLib::ContinuousPartialFixedLookbackOption::ContinuousPartialFixedLookbackOption(QuantLib::Date, boost::shared_ptr<QuantLib::StrikedTypePayoff> const&, boost::shared_ptr<QuantLib::Exercise> const&) |
127 | | |
128 | | void ContinuousPartialFixedLookbackOption::setupArguments( |
129 | 0 | PricingEngine::arguments* args) const { |
130 | |
|
131 | 0 | ContinuousFixedLookbackOption::setupArguments(args); |
132 | |
|
133 | 0 | auto* moreArgs = dynamic_cast<ContinuousPartialFixedLookbackOption::arguments*>(args); |
134 | 0 | QL_REQUIRE(moreArgs != nullptr, "wrong argument type"); |
135 | 0 | moreArgs->lookbackPeriodStart = lookbackPeriodStart_; |
136 | 0 | } |
137 | | |
138 | 0 | void ContinuousPartialFixedLookbackOption::arguments::validate() const { |
139 | |
|
140 | 0 | ContinuousFixedLookbackOption::arguments::validate(); |
141 | |
|
142 | 0 | ext::shared_ptr<EuropeanExercise> europeanExercise = |
143 | 0 | ext::dynamic_pointer_cast<EuropeanExercise>(exercise); |
144 | | QL_REQUIRE(lookbackPeriodStart <= europeanExercise->lastDate(), |
145 | 0 | "lookback start date must be earlier than exercise date"); |
146 | 0 | } |
147 | | } |
148 | | |