Skip to content

Commit

Permalink
QPR-11992 include time zero and evaluation date in option date interp…
Browse files Browse the repository at this point in the history
…olation

ql pr is here: lballabio#1783
  • Loading branch information
pcaspers committed Sep 3, 2023
1 parent b22dcd3 commit 13360e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
38 changes: 22 additions & 16 deletions ql/termstructures/volatility/swaption/swaptionvoldiscrete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,26 @@ 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();
initializeSwapLengths();

optionInterpolator_= LinearInterpolation(optionTimes_.begin(),
optionTimes_.end(),
optionDatesAsReal_.begin());
optionInterpolator_= LinearInterpolation(optionInterpolatorTimes_.begin(),
optionInterpolatorTimes_.end(),
optionInterpolatorDatesAsReal_.begin());
optionInterpolator_.update();
optionInterpolator_.enableExtrapolation();

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

SwaptionVolatilityDiscrete::SwaptionVolatilityDiscrete(
Expand All @@ -69,7 +70,8 @@ namespace QuantLib {
optionTenors_(optionTenors),
optionDates_(nOptionTenors_),
optionTimes_(nOptionTenors_),
optionDatesAsReal_(nOptionTenors_),
optionInterpolatorTimes_(nOptionTenors_ + 1),
optionInterpolatorDatesAsReal_(nOptionTenors_ + 1),
nSwapTenors_(swapTenors.size()),
swapTenors_(swapTenors),
swapLengths_(nSwapTenors_) {
Expand All @@ -80,9 +82,9 @@ namespace QuantLib {
checkSwapTenors();
initializeSwapLengths();

optionInterpolator_= LinearInterpolation(optionTimes_.begin(),
optionTimes_.end(),
optionDatesAsReal_.begin());
optionInterpolator_= LinearInterpolation(optionInterpolatorTimes_.begin(),
optionInterpolatorTimes_.end(),
optionInterpolatorDatesAsReal_.begin());
optionInterpolator_.update();
optionInterpolator_.enableExtrapolation();
}
Expand All @@ -99,7 +101,8 @@ namespace QuantLib {
optionTenors_(nOptionTenors_),
optionDates_(optionDates),
optionTimes_(nOptionTenors_),
optionDatesAsReal_(nOptionTenors_),
optionInterpolatorTimes_(nOptionTenors_ + 1),
optionInterpolatorDatesAsReal_(nOptionTenors_ + 1),
nSwapTenors_(swapTenors.size()),
swapTenors_(swapTenors),
swapLengths_(nSwapTenors_) {
Expand All @@ -110,9 +113,9 @@ namespace QuantLib {
checkSwapTenors();
initializeSwapLengths();

optionInterpolator_= LinearInterpolation(optionTimes_.begin(),
optionTimes_.end(),
optionDatesAsReal_.begin());
optionInterpolator_= LinearInterpolation(optionInterpolatorTimes_.begin(),
optionInterpolatorTimes_.end(),
optionInterpolatorDatesAsReal_.begin());
optionInterpolator_.update();
optionInterpolator_.enableExtrapolation();
}
Expand Down Expand Up @@ -152,17 +155,20 @@ namespace QuantLib {
}

void SwaptionVolatilityDiscrete::initializeOptionDatesAndTimes() const {
optionInterpolatorDatesAsReal_[0] = static_cast<Real>(evaluationDate_.serialNumber());
for (Size i=0; i<nOptionTenors_; ++i) {
optionDates_[i] = optionDateFromTenor(optionTenors_[i]);
optionDatesAsReal_[i] =
optionInterpolatorDatesAsReal_[i + 1] =
static_cast<Real>(optionDates_[i].serialNumber());
}
initializeOptionTimes();
}

void SwaptionVolatilityDiscrete::initializeOptionTimes() const {
for (Size i=0; i<nOptionTenors_; ++i)
optionTimes_[i] = timeFromReference(optionDates_[i]);
optionInterpolatorTimes_[0] = 0.0;
for (Size i = 0; i < nOptionTenors_; ++i) {
optionTimes_[i] = optionInterpolatorTimes_[i + 1] = timeFromReference(optionDates_[i]);
}
}

void SwaptionVolatilityDiscrete::initializeSwapLengths() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ namespace QuantLib {
std::vector<Period> optionTenors_;
mutable std::vector<Date> optionDates_;
mutable std::vector<Time> optionTimes_;
mutable std::vector<Real> optionDatesAsReal_;
mutable Interpolation optionInterpolator_;
mutable std::vector<Time> optionInterpolatorTimes_;
mutable std::vector<Real> optionInterpolatorDatesAsReal_;

Size nSwapTenors_;
std::vector<Period> swapTenors_;
Expand Down

0 comments on commit 13360e3

Please sign in to comment.