Skip to content

Commit

Permalink
Cache rate in FuturesConvAdjustmentQuote (#2145)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio authored Jan 28, 2025
2 parents 8f1cbbe + a907444 commit 51a77aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
24 changes: 14 additions & 10 deletions ql/quotes/futuresconvadjustmentquote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace QuantLib {
registerWith(futuresQuote_);
registerWith(volatility_);
registerWith(meanReversion_);
registerWith(Settings::instance().evaluationDate());
}

FuturesConvAdjustmentQuote::FuturesConvAdjustmentQuote(const ext::shared_ptr<IborIndex>& index,
Expand All @@ -50,19 +51,22 @@ namespace QuantLib {
registerWith(futuresQuote_);
registerWith(volatility_);
registerWith(meanReversion_);
registerWith(Settings::instance().evaluationDate());
}

Real FuturesConvAdjustmentQuote::value() const {

Date settlementDate = Settings::instance().evaluationDate();
Time startTime = dc_.yearFraction(settlementDate, futuresDate_);
Time indexMaturity = dc_.yearFraction(settlementDate,
indexMaturityDate_);
return HullWhite::convexityBias(futuresQuote_->value(),
startTime,
indexMaturity,
volatility_->value(),
meanReversion_->value());
if (rate_ == Null<Real>()) {
Date settlementDate = Settings::instance().evaluationDate();
Time startTime = dc_.yearFraction(settlementDate, futuresDate_);
Time indexMaturity = dc_.yearFraction(settlementDate,
indexMaturityDate_);
rate_ = HullWhite::convexityBias(futuresQuote_->value(),
startTime,
indexMaturity,
volatility_->value(),
meanReversion_->value());
}
return rate_;
}

bool FuturesConvAdjustmentQuote::isValid() const {
Expand Down
5 changes: 4 additions & 1 deletion ql/quotes/futuresconvadjustmentquote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ql/types.hpp>
#include <ql/handle.hpp>
#include <ql/indexes/iborindex.hpp>
#include <ql/utilities/null.hpp>

namespace QuantLib {

Expand Down Expand Up @@ -65,11 +66,13 @@ namespace QuantLib {
Handle<Quote> futuresQuote_;
Handle<Quote> volatility_;
Handle<Quote> meanReversion_;
mutable Real rate_ = Null<Real>();
};

// inline

inline void FuturesConvAdjustmentQuote::update(){
inline void FuturesConvAdjustmentQuote::update() {
rate_ = Null<Real>();
notifyObservers();
}

Expand Down

0 comments on commit 51a77aa

Please sign in to comment.