Skip to content

Commit

Permalink
QPR-12849 avoid copying the time series of fixings
Browse files Browse the repository at this point in the history
  • Loading branch information
pcaspers committed Oct 4, 2024
1 parent 8bd5703 commit 03a5ea0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions ql/index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace QuantLib {
bool forceOverwrite = false) {
checkNativeFixingsAllowed();
std::string tag = name();
TimeSeries<Real> h = IndexManager::instance().getHistory(tag);
TimeSeries<Real>& h = IndexManager::instance().getHistoryRef(tag);
bool noInvalidFixing = true, noDuplicatedFixing = true;
Date invalidDate, duplicatedDate;
Real nullValue = Null<Real>();
Expand All @@ -128,7 +128,6 @@ namespace QuantLib {
invalidValue = *(vBegin++);
}
}
IndexManager::instance().setHistory(tag, h);
QL_REQUIRE(noInvalidFixing, "At least one invalid fixing provided: "
<< invalidDate.weekday() << " " << invalidDate << ", "
<< invalidValue);
Expand Down
4 changes: 4 additions & 0 deletions ql/indexes/indexmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ namespace QuantLib {
return data_[name].value();
}

TimeSeries<Real>& IndexManager::getHistoryRef(const std::string& name) {
return data_[name].ref();
}

void IndexManager::setHistory(const std::string& name, TimeSeries<Real> history) {
data_[name] = std::move(history);
}
Expand Down
2 changes: 2 additions & 0 deletions ql/indexes/indexmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace QuantLib {
bool hasHistory(const std::string& name) const;
//! returns the (possibly empty) history of the index fixings
const TimeSeries<Real>& getHistory(const std::string& name) const;
//! returns a ref to the (possibly empty) history of the index fixings
TimeSeries<Real>& getHistoryRef(const std::string& name);
//! stores the historical fixings of the index
void setHistory(const std::string& name, TimeSeries<Real> history);
//! observer notifying of changes in the index fixings
Expand Down
6 changes: 6 additions & 0 deletions ql/utilities/observablevalue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ namespace QuantLib {
operator ext::shared_ptr<Observable>() const;
//! explicit inspector
const T& value() const;
//! explicit reference
T& ref();
private:
T value_;
ext::shared_ptr<Observable> observable_;
Expand Down Expand Up @@ -118,6 +120,10 @@ namespace QuantLib {
return value_;
}

template <class T>
T& ObservableValue<T>::ref() {
return value_;
}
}

#endif

0 comments on commit 03a5ea0

Please sign in to comment.