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));
62 bool stoppingTime =
false;
84 for (
Size j=0; j<optvalues.
size(); j++) {
102 else if (stoppingTime) {
103 optvalues[j] = std::max(optvalues[j],
123 else if (stoppingTime)
124 optvalues[j] = std::max(optvalues[j],
128 QL_FAIL(
"invalid barrier type");
139 : unenhanced_(args, process, grid) {
161 for (
Size j=0; j<optvalues.
size()-1; ++j) {
162 if (grid[j]<=barrier && grid[j+1] > barrier) {
165 Real ltob = (barrier-grid[j]);
166 Real htob = (grid[j+1]-barrier);
167 Real htol = (grid[j+1]-grid[j]);
170 optvalues[j+1] = std::max(0.0, (ltob*t1+htob*u1)/htol);
175 for (
Size j=0; j<optvalues.
size()-1; ++j) {
176 if (grid[j]<=barrier && grid[j+1] > barrier) {
179 Real a = (barrier-grid[j])*rebate;
181 Real c = (grid[j+1]-grid[j]);
182 optvalues[j+1] = std::max(0.0, (a+
b)/c);
187 for (
Size j=0; j<optvalues.
size()-1; ++j) {
188 if (grid[j] < barrier && grid[j+1] >= barrier) {
191 Real ltob = (barrier-grid[j]);
192 Real htob = (grid[j+1]-barrier);
193 Real htol = (grid[j+1]-grid[j]);
196 optvalues[j] = std::max(0.0, (ltob*u+htob*
t)/htol);
201 for (
Size j=0; j<optvalues.
size()-1; ++j) {
202 if (grid[j] < barrier && grid[j+1] >= barrier) {
206 Real b = (grid[j+1]-barrier)*rebate;
207 Real c = (grid[j+1]-grid[j]);
208 optvalues[j] = std::max(0.0, (a+
b)/c);
1-D array used in linear algebra.
Size size() const
dimension of the array
Arguments for barrier option calculation
Barrier::Type barrierType
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)
std::vector< Time > stoppingTimes_
const Array & vanilla() const
void checkBarrier(Array &optvalues, const Array &grid) const
const BarrierOption::arguments & arguments() const
DiscretizedVanillaOption vanilla_
DiscretizedBarrierOption(const BarrierOption::arguments &, const StochasticProcess &process, const TimeGrid &grid=TimeGrid())
void postAdjustValuesImpl() override
BarrierOption::arguments arguments_
void reset(Size size) override
void postAdjustValuesImpl() override
DiscretizedDermanKaniBarrierOption(const BarrierOption::arguments &, const StochasticProcess &process, const TimeGrid &grid=TimeGrid())
void adjustBarrier(Array &optvalues, const Array &grid)
void reset(Size size) override
DiscretizedBarrierOption unenhanced_
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 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