| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|---|---|
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb |
| 5 | Copyright (C) 2004 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/discretizedasset.hpp> |
| 22 | |
| 23 | namespace QuantLib { |
| 24 | |
| 25 | void DiscretizedOption::postAdjustValuesImpl() { |
| 26 | /* In the real world, with time flowing forward, first |
| 27 | any payment is settled and only after options can be |
| 28 | exercised. Here, with time flowing backward, options |
| 29 | must be exercised before performing the adjustment. |
| 30 | */ |
| 31 | underlying_->partialRollback(to: time()); |
| 32 | underlying_->preAdjustValues(); |
| 33 | Size i; |
| 34 | switch (exerciseType_) { |
| 35 | case Exercise::American: |
| 36 | if (time_ >= exerciseTimes_[0] && time_ <= exerciseTimes_[1]) |
| 37 | applyExerciseCondition(); |
| 38 | break; |
| 39 | case Exercise::Bermudan: |
| 40 | case Exercise::European: |
| 41 | for (i=0; i<exerciseTimes_.size(); i++) { |
| 42 | Time t = exerciseTimes_[i]; |
| 43 | if (t >= 0.0 && isOnTime(t)) |
| 44 | applyExerciseCondition(); |
| 45 | } |
| 46 | break; |
| 47 | default: |
| 48 | QL_FAIL("invalid exercise type"); |
| 49 | } |
| 50 | underlying_->postAdjustValues(); |
| 51 | } |
| 52 | |
| 53 | } |
| 54 | |
| 55 |
