Skip to content

Commit

Permalink
Pass Handle by value and move (part 1) (#1975)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio authored May 21, 2024
2 parents af6a1a4 + ed32de7 commit ae2646c
Show file tree
Hide file tree
Showing 77 changed files with 485 additions and 495 deletions.
6 changes: 3 additions & 3 deletions ql/indexes/bmaindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ namespace QuantLib {

}

BMAIndex::BMAIndex(const Handle<YieldTermStructure>& h)
BMAIndex::BMAIndex(Handle<YieldTermStructure> h)
: InterestRateIndex("BMA",
1 * Weeks,
1,
USDCurrency(),
UnitedStates(UnitedStates::GovernmentBond),
ActualActual(ActualActual::ISDA)),
termStructure_(h) {
registerWith (h);
termStructure_(std::move(h)) {
registerWith(termStructure_);
}

bool BMAIndex::isValidFixingDate(const Date& date) const {
Expand Down
2 changes: 1 addition & 1 deletion ql/indexes/bmaindex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace QuantLib {
*/
class BMAIndex : public InterestRateIndex {
public:
explicit BMAIndex(const Handle<YieldTermStructure>& h = {});
explicit BMAIndex(Handle<YieldTermStructure> h = {});
//! \name Index interface
//@{
/*! BMA is fixed weekly on Wednesdays.
Expand Down
14 changes: 7 additions & 7 deletions ql/indexes/equityindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ namespace QuantLib {
if (result != Null<Real>())
// if historical fixing is present use it
return result;

if (fixingDate == today && !spot_.empty())
// Today's fixing is missing, but spot is
// provided, so use it as proxy
return spot_->value();

QL_FAIL("Missing " << name() << " fixing for " << fixingDate);
}

Expand All @@ -92,9 +92,9 @@ namespace QuantLib {
return forward;
}

ext::shared_ptr<EquityIndex> EquityIndex::clone(const Handle<YieldTermStructure>& interest,
const Handle<YieldTermStructure>& dividend,
const Handle<Quote>& spot) const {
return ext::make_shared<EquityIndex>(name(), fixingCalendar(), interest, dividend, spot);
ext::shared_ptr<EquityIndex> EquityIndex::clone(Handle<YieldTermStructure> interest,
Handle<YieldTermStructure> dividend,
Handle<Quote> spot) const {
return ext::make_shared<EquityIndex>(name(), fixingCalendar(), std::move(interest), std::move(dividend), std::move(spot));
}
}
}
10 changes: 5 additions & 5 deletions ql/indexes/equityindex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace QuantLib {
term structure, or just the interest rate term structure
in which case one can provide a term structure of equity
forwards implied from, e.g. option prices.
In case of the first method, the forward is calculated as:
\f[
I(t, T) = I(t, t) \frac{P_{D}(t, T)}{P_{R}(t, T)},
Expand Down Expand Up @@ -98,9 +98,9 @@ namespace QuantLib {
//@{
//! returns a copy of itself linked to different interest, dividend curves
//! or spot quote
virtual ext::shared_ptr<EquityIndex> clone(const Handle<YieldTermStructure>& interest,
const Handle<YieldTermStructure>& dividend,
const Handle<Quote>& spot) const;
virtual ext::shared_ptr<EquityIndex> clone(Handle<YieldTermStructure> interest,
Handle<YieldTermStructure> dividend,
Handle<Quote> spot) const;
// @}
private:
std::string name_;
Expand All @@ -117,4 +117,4 @@ namespace QuantLib {
inline void EquityIndex::update() { notifyObservers(); }
}

#endif
#endif
4 changes: 2 additions & 2 deletions ql/indexes/ibor/aonia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ namespace QuantLib {
*/
class Aonia : public OvernightIndex {
public:
explicit Aonia(const Handle<YieldTermStructure>& h = {})
explicit Aonia(Handle<YieldTermStructure> h = {})
: OvernightIndex("Aonia", 0, AUDCurrency(),
Australia(),
Actual365Fixed(), h) {}
Actual365Fixed(), std::move(h)) {}
};

}
Expand Down
4 changes: 2 additions & 2 deletions ql/indexes/ibor/audlibor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ namespace QuantLib {
class AUDLibor : public Libor {
public:
AUDLibor(const Period& tenor,
const Handle<YieldTermStructure>& h = {})
Handle<YieldTermStructure> h = {})
: Libor("AUDLibor", tenor,
2,
AUDCurrency(),
Australia(),
Actual360(), h) {}
Actual360(), std::move(h)) {}
};

}
Expand Down
28 changes: 14 additions & 14 deletions ql/indexes/ibor/bbsw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ namespace QuantLib {
class Bbsw : public IborIndex {
public:
Bbsw(const Period& tenor,
const Handle<YieldTermStructure>& h = {})
Handle<YieldTermStructure> h = {})
: IborIndex("Bbsw", tenor,
0, // settlement days
AUDCurrency(), Australia(),
HalfMonthModifiedFollowing, true,
Actual365Fixed(), h) {
Actual365Fixed(), std::move(h)) {
QL_REQUIRE(this->tenor().units() != Days,
"for daily tenors (" << this->tenor() <<
") dedicated DailyTenor constructor must be used");
Expand All @@ -54,43 +54,43 @@ namespace QuantLib {
//! 1-month %Bbsw index
class Bbsw1M : public Bbsw {
public:
explicit Bbsw1M(const Handle<YieldTermStructure>& h = {})
: Bbsw(Period(1, Months), h) {}
explicit Bbsw1M(Handle<YieldTermStructure> h = {})
: Bbsw(Period(1, Months), std::move(h)) {}
};

//! 2-months %Bbsw index
class Bbsw2M : public Bbsw {
public:
explicit Bbsw2M(const Handle<YieldTermStructure>& h = {})
: Bbsw(Period(2, Months), h) {}
explicit Bbsw2M(Handle<YieldTermStructure> h = {})
: Bbsw(Period(2, Months), std::move(h)) {}
};

//! 3-months %Bbsw index
class Bbsw3M : public Bbsw {
public:
explicit Bbsw3M(const Handle<YieldTermStructure>& h = {})
: Bbsw(Period(3, Months), h) {}
explicit Bbsw3M(Handle<YieldTermStructure> h = {})
: Bbsw(Period(3, Months), std::move(h)) {}
};

//! 4-months %Bbsw index
class Bbsw4M : public Bbsw {
public:
explicit Bbsw4M(const Handle<YieldTermStructure>& h = {})
: Bbsw(Period(4, Months), h) {}
explicit Bbsw4M(Handle<YieldTermStructure> h = {})
: Bbsw(Period(4, Months), std::move(h)) {}
};

//! 5-months %Bbsw index
class Bbsw5M : public Bbsw {
public:
explicit Bbsw5M(const Handle<YieldTermStructure>& h = {})
: Bbsw(Period(5, Months), h) {}
explicit Bbsw5M(Handle<YieldTermStructure> h = {})
: Bbsw(Period(5, Months), std::move(h)) {}
};

//! 6-months %Bbsw index
class Bbsw6M : public Bbsw {
public:
explicit Bbsw6M(const Handle<YieldTermStructure>& h = {})
: Bbsw(Period(6, Months), h) {}
explicit Bbsw6M(Handle<YieldTermStructure> h = {})
: Bbsw(Period(6, Months), std::move(h)) {}
};

}
Expand Down
5 changes: 2 additions & 3 deletions ql/indexes/ibor/bibor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ namespace QuantLib {

}

Bibor::Bibor(const Period& tenor,
const Handle<YieldTermStructure>& h)
Bibor::Bibor(const Period& tenor, Handle<YieldTermStructure> h)
: IborIndex("Bibor", tenor,
2, // settlement days
THBCurrency(), Thailand(),
BiborConvention(tenor), BiborEOM(tenor),
Actual365Fixed(), h) {
Actual365Fixed(), std::move(h)) {
QL_REQUIRE(this->tenor().units()!=Days,
"for daily tenors (" << this->tenor() <<
") dedicated DailyTenor constructor must be used");
Expand Down
31 changes: 15 additions & 16 deletions ql/indexes/ibor/bibor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,59 +33,58 @@ namespace QuantLib {
*/
class Bibor : public IborIndex {
public:
Bibor(const Period& tenor,
const Handle<YieldTermStructure>& h = {});
Bibor(const Period& tenor, Handle<YieldTermStructure> h = {});
};


//! 1-week %Bibor index
class BiborSW : public Bibor {
public:
explicit BiborSW(const Handle<YieldTermStructure>& h = {})
: Bibor(Period(1, Weeks), h) {}
explicit BiborSW(Handle<YieldTermStructure> h = {})
: Bibor(Period(1, Weeks), std::move(h)) {}
};


//! 1-month %Euribor index
class Bibor1M : public Bibor {
public:
explicit Bibor1M(const Handle<YieldTermStructure>& h = {})
: Bibor(Period(1, Months), h) {}
explicit Bibor1M(Handle<YieldTermStructure> h = {})
: Bibor(Period(1, Months), std::move(h)) {}
};

//! 2-months %Euribor index
class Bibor2M : public Bibor {
public:
explicit Bibor2M(const Handle<YieldTermStructure>& h = {})
: Bibor(Period(2, Months), h) {}
explicit Bibor2M(Handle<YieldTermStructure> h = {})
: Bibor(Period(2, Months), std::move(h)) {}
};

//! 3-months %Bibor index
class Bibor3M : public Bibor {
public:
explicit Bibor3M(const Handle<YieldTermStructure>& h = {})
: Bibor(Period(3, Months), h) {}
explicit Bibor3M(Handle<YieldTermStructure> h = {})
: Bibor(Period(3, Months), std::move(h)) {}
};

//! 6-months %Bibor index
class Bibor6M : public Bibor {
public:
explicit Bibor6M(const Handle<YieldTermStructure>& h = {})
: Bibor(Period(6, Months), h) {}
explicit Bibor6M(Handle<YieldTermStructure> h = {})
: Bibor(Period(6, Months), std::move(h)) {}
};

//! 9-months %Bibor index
class Bibor9M : public Bibor {
public:
explicit Bibor9M(const Handle<YieldTermStructure>& h = {})
: Bibor(Period(9, Months), h) {}
explicit Bibor9M(Handle<YieldTermStructure> h = {})
: Bibor(Period(9, Months), std::move(h)) {}
};

//! 1-year %Bibor index
class Bibor1Y : public Bibor {
public:
explicit Bibor1Y(const Handle<YieldTermStructure>& h = {})
: Bibor(Period(1, Years), h) {}
explicit Bibor1Y(Handle<YieldTermStructure> h = {})
: Bibor(Period(1, Years), std::move(h)) {}
};

}
Expand Down
29 changes: 14 additions & 15 deletions ql/indexes/ibor/bkbm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ namespace QuantLib {
*/
class Bkbm : public IborIndex {
public:
Bkbm(const Period& tenor,
const Handle<YieldTermStructure>& h = {})
Bkbm(const Period& tenor, Handle<YieldTermStructure> h = {})
: IborIndex("Bkbm", tenor,
0, // settlement days
NZDCurrency(), NewZealand(),
ModifiedFollowing, true,
Actual365Fixed(), h) {
Actual365Fixed(), std::move(h)) {
QL_REQUIRE(this->tenor().units() != Days,
"for daily tenors (" << this->tenor() <<
") dedicated DailyTenor constructor must be used");
Expand All @@ -54,43 +53,43 @@ namespace QuantLib {
//! 1-month %Bkbm index
class Bkbm1M : public Bkbm {
public:
explicit Bkbm1M(const Handle<YieldTermStructure>& h = {})
: Bkbm(Period(1, Months), h) {}
explicit Bkbm1M(Handle<YieldTermStructure> h = {})
: Bkbm(Period(1, Months), std::move(h)) {}
};

//! 2-months %Bkbm index
class Bkbm2M : public Bkbm {
public:
explicit Bkbm2M(const Handle<YieldTermStructure>& h = {})
: Bkbm(Period(2, Months), h) {}
explicit Bkbm2M(Handle<YieldTermStructure> h = {})
: Bkbm(Period(2, Months), std::move(h)) {}
};

//! 3-months %Bkbm index
class Bkbm3M : public Bkbm {
public:
explicit Bkbm3M(const Handle<YieldTermStructure>& h = {})
: Bkbm(Period(3, Months), h) {}
explicit Bkbm3M(Handle<YieldTermStructure> h = {})
: Bkbm(Period(3, Months), std::move(h)) {}
};

//! 4-months %Bkbm index
class Bkbm4M : public Bkbm {
public:
explicit Bkbm4M(const Handle<YieldTermStructure>& h = {})
: Bkbm(Period(4, Months), h) {}
explicit Bkbm4M(Handle<YieldTermStructure> h = {})
: Bkbm(Period(4, Months), std::move(h)) {}
};

//! 5-months %Bkbm index
class Bkbm5M : public Bkbm {
public:
explicit Bkbm5M(const Handle<YieldTermStructure>& h = {})
: Bkbm(Period(5, Months), h) {}
explicit Bkbm5M(Handle<YieldTermStructure> h = {})
: Bkbm(Period(5, Months), std::move(h)) {}
};

//! 6-months %Bkbm index
class Bkbm6M : public Bkbm {
public:
explicit Bkbm6M(const Handle<YieldTermStructure>& h = {})
: Bkbm(Period(6, Months), h) {}
explicit Bkbm6M(Handle<YieldTermStructure> h = {})
: Bkbm(Period(6, Months), std::move(h)) {}
};

}
Expand Down
8 changes: 4 additions & 4 deletions ql/indexes/ibor/cadlibor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ namespace QuantLib {
class CADLibor : public Libor {
public:
CADLibor(const Period& tenor,
const Handle<YieldTermStructure>& h = {})
Handle<YieldTermStructure> h = {})
: Libor("CADLibor", tenor,
0,
CADCurrency(),
Canada(),
Actual365Fixed(), h) {}
Actual365Fixed(), std::move(h)) {}
};

//! Overnight %CAD %Libor index
class CADLiborON : public DailyTenorLibor {
public:
explicit CADLiborON(const Handle<YieldTermStructure>& h = {})
explicit CADLiborON(Handle<YieldTermStructure> h = {})
: DailyTenorLibor("CADLibor",
0,
CADCurrency(),
Canada(),
Actual365Fixed(), h) {}
Actual365Fixed(), std::move(h)) {}
};

}
Expand Down
4 changes: 2 additions & 2 deletions ql/indexes/ibor/cdor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ namespace QuantLib {
class Cdor : public IborIndex {
public:
Cdor(const Period& tenor,
const Handle<YieldTermStructure>& h = {})
Handle<YieldTermStructure> h = {})
: IborIndex("CDOR", tenor, 0, CADCurrency(),
Canada(), ModifiedFollowing, false,
Actual365Fixed(), h) {}
Actual365Fixed(), std::move(h)) {}
};

}
Expand Down
Loading

0 comments on commit ae2646c

Please sign in to comment.