Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ql/termstructures/yield/forwardstructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@
namespace QuantLib {

ForwardRateStructure::ForwardRateStructure(const DayCounter& dc)
: YieldTermStructure(dc) {}
: ZeroYieldStructure(dc) {}

ForwardRateStructure::ForwardRateStructure(
const Date& refDate,
const Calendar& cal,
const DayCounter& dc,
const std::vector<Handle<Quote> >& jumps,
const std::vector<Date>& jumpDates)
: YieldTermStructure(refDate, cal, dc, jumps, jumpDates) {}
: ZeroYieldStructure(refDate, cal, dc, jumps, jumpDates) {}

ForwardRateStructure::ForwardRateStructure(
Natural settlDays,
const Calendar& cal,
const DayCounter& dc,
const std::vector<Handle<Quote> >& jumps,
const std::vector<Date>& jumpDates)
: YieldTermStructure(settlDays, cal, dc, jumps, jumpDates) {}
: ZeroYieldStructure(settlDays, cal, dc, jumps, jumpDates) {}

Rate ForwardRateStructure::zeroYieldImpl(Time t) const {
if (t == 0.0)
Expand Down
29 changes: 6 additions & 23 deletions ql/termstructures/yield/forwardstructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,24 @@
#ifndef quantlib_forward_structure_hpp
#define quantlib_forward_structure_hpp

#include <ql/termstructures/yieldtermstructure.hpp>
#include <ql/termstructures/yield/zeroyieldstructure.hpp>

namespace QuantLib {

//! %Forward-rate term structure
/*! This abstract class acts as an adapter to YieldTermStructure allowing
the programmer to implement only the <tt>forwardImpl(Time)</tt> method
in derived classes.
in derived classes. However, it is strongly recommended to provide an
efficient implementation of <tt>zeroYieldImpl(Time)</tt> as well if
possible.

Zero yields and discounts are calculated from forwards.

Forward rates are assumed to be annual continuous compounding.

\ingroup yieldtermstructures
*/
class ForwardRateStructure : public YieldTermStructure {
class ForwardRateStructure : public ZeroYieldStructure {
public:
/*! \name Constructors
See the TermStructure documentation for issues regarding
Expand Down Expand Up @@ -85,29 +87,10 @@ namespace QuantLib {
Derived classes should override it if a more efficient
implementation is available.
*/
virtual Rate zeroYieldImpl(Time) const;
//@}

//! \name YieldTermStructure implementation
//@{
/*! Returns the discount factor for the given date calculating it
from the zero rate as \f$ d(t) = \exp \left( -z(t) t \right) \f$
*/
DiscountFactor discountImpl(Time) const override;
Rate zeroYieldImpl(Time) const override;
//@}
};


// inline definitions

inline DiscountFactor ForwardRateStructure::discountImpl(Time t) const {
if (t == 0.0) // this acts as a safe guard in cases where
return 1.0; // zeroYieldImpl(0.0) would throw.

Rate r = zeroYieldImpl(t);
return DiscountFactor(std::exp(-r*t));
}

}

#endif
8 changes: 0 additions & 8 deletions ql/termstructures/yield/zerospreadedtermstructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ namespace QuantLib {
protected:
//! returns the spreaded zero yield rate
Rate zeroYieldImpl(Time) const override;
//! returns the spreaded forward rate
/* This method must disappear should the spread become a curve */
Rate forwardImpl(Time) const;
private:
Handle<YieldTermStructure> originalCurve_;
Handle<Quote> spread_;
Expand Down Expand Up @@ -140,11 +137,6 @@ namespace QuantLib {
return spreadedRate.equivalentRate(Continuous, NoFrequency, t);
}

inline Rate ZeroSpreadedTermStructure::forwardImpl(Time t) const {
return originalCurve_->forwardRate(t, t, comp_, freq_, true)
+ spread_->value();
}

}

#endif
Loading