29 : arguments_(args), vanilla_(arguments_, process, grid) {
30 QL_REQUIRE(!args.exercise->dates().empty(),
"specify at least one stopping date");
35 process.
time(args.exercise->date(i));
61 bool stoppingTime =
false;
83 for (
Size j=0; j<optvalues.
size(); j++) {
89 optvalues[j] = std::max(
vanilla()[j],
98 optvalues[j] = std::max(
vanilla()[j],
112 else if (stoppingTime)
113 optvalues[j] = std::max(optvalues[j],
121 optvalues[j] = std::max(
vanilla()[j],
139 optvalues[j] = std::max(
vanilla()[j],
149 QL_FAIL(
"invalid barrier type");
160 : unenhanced_(args, process, grid) {
183 for (
Size j=0; j<optvalues.
size()-1; ++j) {
184 if (grid[j]<=barrier_lo && grid[j+1] > barrier_lo) {
187 Real ltob = (barrier_lo-grid[j]);
188 Real htob = (grid[j+1]-barrier_lo);
189 Real htol = (grid[j+1]-grid[j]);
192 optvalues[j+1] = std::max(0.0, (ltob*t1+htob*u1)/htol);
194 else if (grid[j] < barrier_hi && grid[j+1] >= barrier_hi) {
197 Real ltob = (barrier_hi-grid[j]);
198 Real htob = (grid[j+1]-barrier_hi);
199 Real htol = (grid[j+1]-grid[j]);
202 optvalues[j] = std::max(0.0, (ltob*u+htob*
t)/htol);
207 for (
Size j=0; j<optvalues.
size()-1; ++j) {
208 if (grid[j]<=barrier_lo && grid[j+1] > barrier_lo) {
211 Real a = (barrier_lo-grid[j])*rebate;
213 Real c = (grid[j+1]-grid[j]);
214 optvalues[j+1] = std::max(0.0, (a+
b)/c);
216 else if (grid[j] < barrier_hi && grid[j+1] >= barrier_hi) {
220 Real b = (grid[j+1]-barrier_hi)*rebate;
221 Real c = (grid[j+1]-grid[j]);
222 optvalues[j] = std::max(0.0, (a+
b)/c);
227 QL_FAIL(
"unsupported barrier type");
1-D array used in linear algebra.
Size size() const
dimension of the array
bool isOnTime(Time t) const
const Array & values() const
const ext::shared_ptr< Lattice > & method() const
void initialize(const ext::shared_ptr< Lattice > &, Time t)
DiscretizedDermanKaniDoubleBarrierOption(const DoubleBarrierOption::arguments &, const StochasticProcess &process, const TimeGrid &grid=TimeGrid())
void postAdjustValuesImpl() override
DiscretizedDoubleBarrierOption unenhanced_
void adjustBarrier(Array &optvalues, const Array &grid)
void reset(Size size) override
DoubleBarrierOption::arguments arguments_
std::vector< Time > stoppingTimes_
const Array & vanilla() const
void checkBarrier(Array &optvalues, const Array &grid) const
DiscretizedVanillaOption vanilla_
void postAdjustValuesImpl() override
const DoubleBarrierOption::arguments & arguments() const
DiscretizedDoubleBarrierOption(const DoubleBarrierOption::arguments &, const StochasticProcess &process, const TimeGrid &grid=TimeGrid())
void reset(Size size) override
Arguments for double barrier option calculation
DoubleBarrier::Type barrierType
multi-dimensional stochastic process class.
virtual Time time(const Date &) const
Time closestTime(Time t) const
returns the time on the grid closest to the given t
discretized double barrier option
#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)
ext::function< Real(Real)> b
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
@ KOKI
lower barrier KI, upper KO