Skip to content

Commit

Permalink
Deprecate inherited members
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Nov 15, 2021
1 parent 1795f0e commit b52cd47
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 64 deletions.
36 changes: 0 additions & 36 deletions Examples/FRA/FRA.cpp
Expand Up @@ -228,24 +228,6 @@ int main(int, char* []) {
cout << "FRA market quote: "
<< io::rate(threeMonthFraQuote[monthsToStart[i]])
<< endl;
cout << "FRA spot value: "
<< myFRA.spotValue()
<< endl;
cout << "FRA forward value: "
<< myFRA.forwardValue()
<< endl;
cout << "FRA implied Yield: "
<< myFRA.impliedYield(myFRA.spotValue(),
myFRA.forwardValue(),
settlementDate,
Simple,
fraDayCounter)
<< endl;
cout << "market Zero Rate: "
<< discountingTermStructure->zeroRate(fraMaturityDate,
fraDayCounter,
Simple)
<< endl;
cout << "FRA amount [should be zero]: "
<< myFRA.amount()
<< endl;
Expand Down Expand Up @@ -310,24 +292,6 @@ int main(int, char* []) {
cout << "FRA market quote: "
<< io::rate(threeMonthFraQuote[monthsToStart[i]])
<< endl;
cout << "FRA spot value: "
<< myFRA.spotValue()
<< endl;
cout << "FRA forward value: "
<< myFRA.forwardValue()
<< endl;
cout << "FRA implied Yield: "
<< myFRA.impliedYield(myFRA.spotValue(),
myFRA.forwardValue(),
settlementDate,
Simple,
fraDayCounter)
<< endl;
cout << "market Zero Rate: "
<< discountingTermStructure->zeroRate(fraMaturityDate,
fraDayCounter,
Simple)
<< endl;
cout << "FRA amount [should be positive]: "
<< myFRA.amount()
<< endl;
Expand Down
22 changes: 15 additions & 7 deletions ql/instruments/forwardrateagreement.cpp
Expand Up @@ -23,6 +23,8 @@

namespace QuantLib {

QL_DEPRECATED_DISABLE_WARNING

ForwardRateAgreement::ForwardRateAgreement(
const Date& valueDate,
const Date& maturityDate,
Expand All @@ -32,13 +34,11 @@ namespace QuantLib {
const ext::shared_ptr<IborIndex>& index,
const Handle<YieldTermStructure>& discountCurve,
bool useIndexedCoupon)
:
fraType_(type), notionalAmount_(notionalAmount), index_(index),
: fraType_(type), notionalAmount_(notionalAmount), index_(index),
useIndexedCoupon_(useIndexedCoupon), dayCounter_(std::move(index->dayCounter())),
calendar_(index->fixingCalendar()),
businessDayConvention_(index->businessDayConvention()), settlementDays_(index->fixingDays()),
payoff_(ext::shared_ptr<Payoff>()), valueDate_(valueDate),
maturityDate_(maturityDate), discountCurve_(std::move(discountCurve)) {
valueDate_(valueDate), maturityDate_(maturityDate), discountCurve_(std::move(discountCurve)) {

maturityDate_ = calendar_.adjust(maturityDate_, businessDayConvention_);

Expand All @@ -53,12 +53,14 @@ namespace QuantLib {
Real strike = notionalAmount_ *
strikeForwardRate_.compoundFactor(valueDate_,
maturityDate_);

payoff_ = ext::shared_ptr<Payoff>(new ForwardTypePayoff(fraType_,
strike));
// incomeDiscountCurve_ is irrelevant to an FRA
incomeDiscountCurve_ = discountCurve_;
// income is irrelevant to FRA - set it to zero
underlyingIncome_ = 0.0;

registerWith(index_);
}

Expand All @@ -67,13 +69,14 @@ namespace QuantLib {
settlementDays_, Days);
}

QL_DEPRECATED_ENABLE_WARNING

Date ForwardRateAgreement::fixingDate() const {
return calendar_.advance(valueDate_,
-static_cast<Integer>(settlementDays_), Days);
return index_->fixingDate(valueDate_);
}

bool ForwardRateAgreement::isExpired() const {
return detail::simple_event(valueDate_).hasOccurred(settlementDate());
return detail::simple_event(valueDate_).hasOccurred();
}

Real ForwardRateAgreement::spotIncome(
Expand Down Expand Up @@ -118,8 +121,10 @@ namespace QuantLib {

NPV_ = amount_ * discount->discount(valueDate_);

QL_DEPRECATED_DISABLE_WARNING
underlyingSpotValue_ = spotValue();
underlyingIncome_ = 0.0;
QL_DEPRECATED_ENABLE_WARNING
}

void ForwardRateAgreement::calculateForwardRate() const {
Expand Down Expand Up @@ -147,6 +152,8 @@ namespace QuantLib {
amount_ = notionalAmount_ * sign * (F - K) * T / (1.0 + F * T);
}

QL_DEPRECATED_DISABLE_WARNING

Real ForwardRateAgreement::forwardValue() const {
calculate();
return (underlyingSpotValue_ - underlyingIncome_) / discountCurve_->discount(maturityDate_);
Expand All @@ -164,4 +171,5 @@ namespace QuantLib {
return InterestRate::impliedRate(compoundingFactor, dayCounter, comp, Annual, t);
}

QL_DEPRECATED_ENABLE_WARNING
}
82 changes: 61 additions & 21 deletions ql/instruments/forwardrateagreement.hpp
Expand Up @@ -30,6 +30,8 @@ namespace QuantLib {

class IborIndex;

QL_DEPRECATED_DISABLE_WARNING

//! %Forward rate agreement (FRA) class
/*! 1. Unlike the forward contract conventions on carryable
financial assets (stocks, bonds, commodities), the
Expand Down Expand Up @@ -80,41 +82,55 @@ namespace QuantLib {
bool isExpired() const override;
//! The payoff on the value date
Real amount() const;
/*! This returns evaluationDate + settlementDays (not FRA
valueDate).

/*! \deprecated This used to be inherited from Forward, but it's not correct for FRAs.
Deprecated in version 1.25.
*/
QL_DEPRECATED
Date settlementDate() const;

const Calendar& calendar() const;
BusinessDayConvention businessDayConvention() const;
const DayCounter& dayCounter() const;
//! term structure relevant to the contract (e.g. repo curve)
Handle<YieldTermStructure> discountCurve() const;
//! term structure that discounts the underlying's income cash flows

/*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
Deprecated in version 1.25.
*/
QL_DEPRECATED
Handle<YieldTermStructure> incomeDiscountCurve() const;

Date fixingDate() const;
/*! Income is zero for a FRA */

/*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
Deprecated in version 1.25.
*/
QL_DEPRECATED
Real spotIncome(const Handle<YieldTermStructure>& incomeDiscountCurve) const;
//! Spot value (NPV) of the underlying loan
/*! This has always a positive value (asset), even if short the FRA */
/*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
Deprecated in version 1.25.
*/
QL_DEPRECATED
Real spotValue() const;

//! Returns the relevant forward rate associated with the FRA term
InterestRate forwardRate() const;

/*! Simple yield calculation based on underlying spot and
forward values, taking into account underlying income.
When \f$ t>0 \f$, call with:
underlyingSpotValue=spotValue(t),
forwardValue=strikePrice, to get current yield. For a
repo, if \f$ t=0 \f$, impliedYield should reproduce the
spot repo rate. For FRA's, this should reproduce the
relevant zero rate at the FRA's maturityDate_;
/*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
Deprecated in version 1.25.
*/
QL_DEPRECATED
InterestRate impliedYield(Real underlyingSpotValue,
Real forwardValue,
Date settlementDate,
Compounding compoundingConvention,
const DayCounter& dayCounter);

/*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
Deprecated in version 1.25.
*/
QL_DEPRECATED
virtual Real forwardValue() const;
//@}

Expand All @@ -130,23 +146,43 @@ namespace QuantLib {
ext::shared_ptr<IborIndex> index_;
bool useIndexedCoupon_;

/*! derived classes must set this, typically via spotIncome() */
/*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
Deprecated in version 1.25.
*/
QL_DEPRECATED
mutable Real underlyingIncome_;
/*! derived classes must set this, typically via spotValue() */
/*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
Deprecated in version 1.25.
*/
QL_DEPRECATED
mutable Real underlyingSpotValue_;

DayCounter dayCounter_;
Calendar calendar_;
BusinessDayConvention businessDayConvention_;

/*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
Deprecated in version 1.25.
*/
QL_DEPRECATED
Natural settlementDays_;
ext::shared_ptr<Payoff> payoff_;
/*! valueDate = settlement date (date the fwd contract starts
accruing)

/*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
Deprecated in version 1.25.
*/
QL_DEPRECATED
ext::shared_ptr<Payoff> payoff_;

//! the valueDate is the date the underlying index starts accruing and the FRA is settled.
Date valueDate_;
//! maturityDate of the forward contract or delivery date of underlying
//! maturityDate of the underlying index; not the date the FRA is settled.
Date maturityDate_;
Handle<YieldTermStructure> discountCurve_;
/*! must set this in derived classes, based on particular underlying */

/*! \deprecated This used to be inherited from Forward, but it doesn't make sense for FRAs.
Deprecated in version 1.25.
*/
QL_DEPRECATED
Handle<YieldTermStructure> incomeDiscountCurve_;

private:
Expand All @@ -155,6 +191,8 @@ namespace QuantLib {
mutable Real amount_;
};

QL_DEPRECATED_ENABLE_WARNING

inline const Calendar& ForwardRateAgreement::calendar() const { return calendar_; }

inline BusinessDayConvention ForwardRateAgreement::businessDayConvention() const {
Expand All @@ -168,7 +206,9 @@ namespace QuantLib {
}

inline Handle<YieldTermStructure> ForwardRateAgreement::incomeDiscountCurve() const {
QL_DEPRECATED_DISABLE_WARNING
return incomeDiscountCurve_;
QL_DEPRECATED_ENABLE_WARNING
}

}
Expand Down

0 comments on commit b52cd47

Please sign in to comment.