Skip to content

Commit

Permalink
fix evaluation / reference date handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pcaspers committed Sep 28, 2023
1 parent efedbe7 commit 550a1a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
3 changes: 1 addition & 2 deletions ql/termstructures/volatility/swaption/swaptionvolcube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ namespace QuantLib {
swapIndexBase_->tenor() << ")");

registerWithVolatilitySpread();
registerWith(Settings::instance().evaluationDate());
evaluationDate_ = Settings::instance().evaluationDate();
cachedReferenceDate_ = referenceDate();
}

void SwaptionVolatilityCube::registerWithVolatilitySpread()
Expand Down
16 changes: 8 additions & 8 deletions ql/termstructures/volatility/swaption/swaptionvoldiscrete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ namespace QuantLib {
optionTenors_(optionTenors),
optionDates_(nOptionTenors_),
optionTimes_(nOptionTenors_),
optionDatesAsReal_(nOptionTenors_),
optionInterpolatorTimes_(nOptionTenors_ + 1),
optionInterpolatorDatesAsReal_(nOptionTenors_ + 1),
nSwapTenors_(swapTenors.size()),
swapTenors_(swapTenors),
swapLengths_(nSwapTenors_) {

checkOptionTenors();
evaluationDate_ = Settings::instance().evaluationDate();
initializeOptionDatesAndTimes();

checkSwapTenors();
Expand All @@ -54,8 +54,7 @@ namespace QuantLib {
optionInterpolatorDatesAsReal_.begin());
optionInterpolator_.update();
optionInterpolator_.enableExtrapolation();

registerWith(Settings::instance().evaluationDate());
cachedReferenceDate_ = referenceDate();
}

SwaptionVolatilityDiscrete::SwaptionVolatilityDiscrete(
Expand All @@ -70,6 +69,7 @@ namespace QuantLib {
optionTenors_(optionTenors),
optionDates_(nOptionTenors_),
optionTimes_(nOptionTenors_),
optionDatesAsReal_(nOptionTenors_),
optionInterpolatorTimes_(nOptionTenors_ + 1),
optionInterpolatorDatesAsReal_(nOptionTenors_ + 1),
nSwapTenors_(swapTenors.size()),
Expand Down Expand Up @@ -101,6 +101,7 @@ namespace QuantLib {
optionTenors_(nOptionTenors_),
optionDates_(optionDates),
optionTimes_(nOptionTenors_),
optionDatesAsReal_(nOptionTenors_),
optionInterpolatorTimes_(nOptionTenors_ + 1),
optionInterpolatorDatesAsReal_(nOptionTenors_ + 1),
nSwapTenors_(swapTenors.size()),
Expand Down Expand Up @@ -155,10 +156,10 @@ namespace QuantLib {
}

void SwaptionVolatilityDiscrete::initializeOptionDatesAndTimes() const {
optionInterpolatorDatesAsReal_[0] = static_cast<Real>(evaluationDate_.serialNumber());
optionInterpolatorDatesAsReal_[0] = static_cast<Real>(referenceDate().serialNumber());
for (Size i=0; i<nOptionTenors_; ++i) {
optionDates_[i] = optionDateFromTenor(optionTenors_[i]);
optionInterpolatorDatesAsReal_[i + 1] =
optionDatesAsReal_[i] = optionInterpolatorDatesAsReal_[i + 1] =
static_cast<Real>(optionDates_[i].serialNumber());
}
initializeOptionTimes();
Expand All @@ -179,9 +180,8 @@ namespace QuantLib {
void SwaptionVolatilityDiscrete::performCalculations() const {
// recalculate dates if necessary...
if (moving_) {
Date d = Settings::instance().evaluationDate();
if (evaluationDate_ != d) {
evaluationDate_ = d;
if (cachedReferenceDate_ != referenceDate()) {
cachedReferenceDate_ = referenceDate();
initializeOptionDatesAndTimes();
initializeSwapLengths();
optionInterpolator_.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ namespace QuantLib {
mutable std::vector<Date> optionDates_;
mutable std::vector<Time> optionTimes_;
mutable Interpolation optionInterpolator_;
mutable std::vector<Real> optionDatesAsReal_;
mutable std::vector<Time> optionInterpolatorTimes_;
mutable std::vector<Real> optionInterpolatorDatesAsReal_;

Size nSwapTenors_;
std::vector<Period> swapTenors_;
mutable std::vector<Time> swapLengths_;
mutable Date evaluationDate_;
mutable Date cachedReferenceDate_;
private:
void checkOptionTenors() const;
void checkOptionDates(const Date& reference) const;
Expand Down

0 comments on commit 550a1a4

Please sign in to comment.