27#ifndef quantlib_historical_forward_rates_analysis_hpp
28#define quantlib_historical_forward_rates_analysis_hpp
43 template<
class Traits,
class Interpolator>
46 std::vector<Date>& skippedDates,
47 std::vector<std::string>& skippedDatesErrorMessage,
48 std::vector<Date>& failedDates,
49 std::vector<std::string>& failedDatesErrorMessage,
50 std::vector<Period>& fixingPeriods,
51 const Date& startDate,
54 const ext::shared_ptr<InterestRateIndex>& fwdIndex,
57 const std::vector<ext::shared_ptr<IborIndex> >& iborIndexes,
58 const std::vector<ext::shared_ptr<SwapIndex> >& swapIndexes,
60 Real yieldCurveAccuracy = 1.0e-12,
61 const Interpolator& i = Interpolator()) {
66 skippedDatesErrorMessage.clear();
68 failedDatesErrorMessage.clear();
69 fixingPeriods.clear();
74 std::vector<ext::shared_ptr<RateHelper> > rateHelpers;
77 std::vector<ext::shared_ptr<SimpleQuote> > iborQuotes;
78 std::vector<ext::shared_ptr<IborIndex> >::const_iterator ibor;
79 for (ibor=iborIndexes.begin(); ibor!=iborIndexes.end(); ++ibor) {
80 ext::shared_ptr<SimpleQuote> quote(
new SimpleQuote);
81 iborQuotes.push_back(quote);
83 rateHelpers.push_back(ext::shared_ptr<RateHelper> (
new
86 (*ibor)->fixingDays(),
87 (*ibor)->fixingCalendar(),
88 (*ibor)->businessDayConvention(),
89 (*ibor)->endOfMonth(),
90 (*ibor)->dayCounter())));
94 std::vector<ext::shared_ptr<SimpleQuote> > swapQuotes;
95 std::vector<ext::shared_ptr<SwapIndex> >::const_iterator
swap;
96 for (
swap=swapIndexes.begin();
swap!=swapIndexes.end(); ++
swap) {
97 ext::shared_ptr<SimpleQuote> quote(
new SimpleQuote);
98 swapQuotes.push_back(quote);
100 rateHelpers.push_back(ext::shared_ptr<RateHelper> (
new
103 (*swap)->fixingCalendar(),
104 (*swap)->fixedLegTenor().frequency(),
105 (*swap)->fixedLegConvention(),
106 (*swap)->dayCounter(),
107 (*swap)->iborIndex())));
111 Period indexTenor = fwdIndex->tenor();
112 Period fixingPeriod = initialGap;
113 while (fixingPeriod<=horizon) {
114 fixingPeriods.push_back(fixingPeriod);
115 fixingPeriod += indexTenor;
118 Size nRates = fixingPeriods.size();
119 statistics.
reset(nRates);
120 std::vector<Rate> fwdRates(nRates);
121 std::vector<Rate> prevFwdRates(nRates);
122 std::vector<Rate> fwdRatesDiff(nRates);
123 DayCounter indexDayCounter = fwdIndex->dayCounter();
124 Calendar cal = fwdIndex->fixingCalendar();
132 yieldCurveDayCounter,
142 for (; currentDate<=endDate;
151 for (
Size i=0; i<iborIndexes.size(); ++i) {
152 Rate fixing = iborIndexes[i]->fixing(currentDate,
false);
153 iborQuotes[i]->setValue(fixing);
155 for (
Size i=0; i<swapIndexes.size(); ++i) {
156 Rate fixing = swapIndexes[i]->fixing(currentDate,
false);
157 swapQuotes[i]->setValue(fixing);
159 }
catch (std::exception& e) {
160 skippedDates.push_back(currentDate);
161 skippedDatesErrorMessage.emplace_back(e.what());
166 for (
Size i=0; i<nRates; ++i) {
168 Date d = currentDate + fixingPeriods[i];
169 fwdRates[i] = yc.forwardRate(
d,
174 }
catch (std::exception& e) {
175 failedDates.push_back(currentDate);
176 failedDatesErrorMessage.emplace_back(e.what());
183 for (
Size i=0; i<nRates; ++i)
184 fwdRatesDiff[i] = fwdRates[i]/prevFwdRates[i] -1.0;
186 statistics.
add(fwdRatesDiff.begin(), fwdRatesDiff.end());
192 std::swap(prevFwdRates, fwdRates);
208 template<
class Traits,
class Interpolator>
212 ext::shared_ptr<SequenceStatistics> stats,
213 const Date& startDate,
216 const ext::shared_ptr<InterestRateIndex>& fwdIndex,
219 const std::vector<ext::shared_ptr<IborIndex> >& iborIndexes,
220 const std::vector<ext::shared_ptr<SwapIndex> >& swapIndexes,
222 Real yieldCurveAccuracy);
227 const std::vector<Date>&
failedDates()
const override;
233 ext::shared_ptr<SequenceStatistics>
stats_;
242 template<
class Traits,
class Interpolator>
243 const std::vector<Period>&
245 return fixingPeriods_;
248 template<
class Traits,
class Interpolator>
249 inline const std::vector<Date>&
251 return skippedDates_;
254 template<
class Traits,
class Interpolator>
255 inline const std::vector<std::string>&
257 return skippedDatesErrorMessage_;
260 template<
class Traits,
class Interpolator>
261 inline const std::vector<Date>&
266 template<
class Traits,
class Interpolator>
267 inline const std::vector<std::string>&
269 return failedDatesErrorMessage_;
276 template <
class Traits,
class Interpolator>
278 ext::shared_ptr<SequenceStatistics> stats,
279 const Date& startDate,
282 const ext::shared_ptr<InterestRateIndex>& fwdIndex,
285 const std::vector<ext::shared_ptr<IborIndex> >& iborIndexes,
286 const std::vector<ext::shared_ptr<SwapIndex> >& swapIndexes,
288 Real yieldCurveAccuracy)
289 : stats_(
std::move(stats)) {
296 fwdIndex, initialGap, horizon,
297 iborIndexes, swapIndexes,
298 yieldCurveDayCounter, yieldCurveAccuracy);
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
Rate helper for bootstrapping over deposit rates.
Statistics analysis of N-dimensional (sequence) data.
void add(const Sequence &sample, Real weight=1.0)
void reset(Size dimension=0)
Shared handle to an observable.
virtual const std::vector< std::string > & failedDatesErrorMessage() const =0
virtual const std::vector< Period > & fixingPeriods() const =0
virtual const std::vector< std::string > & skippedDatesErrorMessage() const =0
virtual ~HistoricalForwardRatesAnalysis()=default
virtual const std::vector< Date > & skippedDates() const =0
virtual const std::vector< Date > & failedDates() const =0
Historical correlation class
const std::vector< Period > & fixingPeriods() const override
const std::vector< Date > & skippedDates() const override
std::vector< Period > fixingPeriods_
const std::vector< Date > & failedDates() const override
std::vector< Date > failedDates_
std::vector< Date > skippedDates_
HistoricalForwardRatesAnalysisImpl()=default
std::vector< std::string > failedDatesErrorMessage_
ext::shared_ptr< SequenceStatistics > stats_
const std::vector< std::string > & failedDatesErrorMessage() const override
const std::vector< std::string > & skippedDatesErrorMessage() const override
std::vector< std::string > skippedDatesErrorMessage_
Piecewise yield term structure.
Bootstrap< this_curve > bootstrap_type
DateProxy & evaluationDate()
the date at which pricing is to be performed.
bool & enforcesTodaysHistoricFixings()
market element returning a stored value
static Settings & instance()
access to the unique instance
Rate helper for bootstrapping over swap rates.
date- and time-related classes, typedefs and enumerations
unsigned QL_INTEGER Natural
positive integer
std::size_t Size
size of a container
base class for Inter-Bank-Offered-Rate indexes
matrix used in linear algebra.
void historicalForwardRatesAnalysis(SequenceStatistics &statistics, std::vector< Date > &skippedDates, std::vector< std::string > &skippedDatesErrorMessage, std::vector< Date > &failedDates, std::vector< std::string > &failedDatesErrorMessage, std::vector< Period > &fixingPeriods, const Date &startDate, const Date &endDate, const Period &step, const ext::shared_ptr< InterestRateIndex > &fwdIndex, const Period &initialGap, const Period &horizon, const std::vector< ext::shared_ptr< IborIndex > > &iborIndexes, const std::vector< ext::shared_ptr< SwapIndex > > &swapIndexes, const DayCounter &yieldCurveDayCounter, Real yieldCurveAccuracy=1.0e-12, const Interpolator &i=Interpolator())
void swap(Array &v, Array &w) noexcept
piecewise-interpolated term structure
deposit, FRA, futures, and various swap rate helpers
Statistics tools for sequence (vector, list, array) samples.