52 <<
" require multiple of " << ((
int)this->
frequency()) <<
" factors "
57 <<
", only semi-annual through daily permitted.");
76 Date curveBaseDate = lim.second;
80 for (
Size i = 1; i < nTest; i++) {
82 QL_REQUIRE(std::fabs(factorAt-factorBase)<eps,
"seasonality is inconsistent with inflation term structure, factors "
83 << factorBase <<
" and later factor " << factorAt <<
", " << i <<
" years later from inflation curve "
84 <<
" with base date at " << curveBaseDate);
92 const std::vector<Rate>& seasonalityFactors)
98 const std::vector<Rate>& seasonalityFactors)
140 Date curveBaseDate = lim.second;
150 Period factorPeriod(factorFrequency);
156 Integer diffDays = std::abs(to - from);
158 if(from > to)dir = -1;
163 diff = dir * (diffDays / 7);
166 diff = diffDays / (31*factorPeriod.
length());
167 Date go = from + dir*diff*factorPeriod;
168 while ( !(lim.first <= go && go <= lim.second) ) {
169 go += dir*factorPeriod;
174 QL_FAIL(
"seasonality period time unit is not allowed to be : " << factorPeriod.
units());
181 which = diff % nFactors;
183 which = (nFactors - (-diff % nFactors)) % nFactors;
194 const Date& curveBaseDate,
195 const bool isZeroRate)
const {
206 Real seasonalityAt = factorAt / factorBase;
209 f = std::pow(seasonalityAt, 1/timeFromCurveBase);
213 f = factorAt / factor1Ybefore;
216 return (rate + 1)*
f - 1;
229 if (toMonth < fromMonth)
231 Size dummy = fromMonth;
239 "12 monthly seasonal factors needed for Kerkhof Seasonality:"
242 Real seasonalCorrection = 1.0;
243 for (
Size i = fromMonth ; i<toMonth; i++)
251 seasonalCorrection = 1/seasonalCorrection;
254 return seasonalCorrection;
260 const Date& curveBaseDate,
261 const bool isZeroRate)
const {
270 f = std::pow(indexFactor, 1/timeFromCurveBase);
273 QL_FAIL(
"Seasonal Kerkhof model is not defined on YoY rates");
276 return (rate + 1)*
f - 1;
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Interface for inflation term structures.
virtual Date baseDate() const
minimum (base) date
virtual Frequency frequency() const
Rate seasonalityCorrection(Rate rate, const Date &atDate, const DayCounter &dc, const Date &curveBaseDate, bool isZeroRate) const override
Real seasonalityFactor(const Date &to) const override
The factor returned is NOT normalized relative to ANYTHING.
virtual std::vector< Rate > seasonalityFactors() const
virtual Date seasonalityBaseDate() const
inspectors
Date seasonalityBaseDate_
Rate correctYoYRate(const Date &d, Rate r, const InflationTermStructure &iTS) const override
Rate correctZeroRate(const Date &d, Rate r, const InflationTermStructure &iTS) const override
virtual void validate() const
virtual Rate seasonalityCorrection(Rate r, const Date &d, const DayCounter &dc, const Date &curveBaseDate, bool isZeroRate) const
std::vector< Rate > seasonalityFactors_
virtual void set(const Date &seasonalityBaseDate, Frequency frequency, const std::vector< Rate > &seasonalityFactors)
virtual Frequency frequency() const
virtual Rate seasonalityFactor(const Date &d) const
The factor returned is NOT normalized relative to ANYTHING.
bool isConsistent(const InflationTermStructure &iTS) const override
MultiplicativePriceSeasonality()=default
virtual bool isConsistent(const InflationTermStructure &iTS) const
virtual DayCounter dayCounter() const
the day counter used for date/time conversion
Classes and functions for error handling.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Frequency
Frequency of events.
@ Biweekly
every second week
@ Bimonthly
every second month
@ Quarterly
every third month
@ EveryFourthMonth
every fourth month
Real Time
continuous quantity with 1-year units
QL_INTEGER Integer
integer number
std::size_t Size
size of a container
Base classes for inflation term structures.
std::pair< Date, Date > inflationPeriod(const Date &d, Frequency frequency)
utility function giving the inflation period for a given date
ext::shared_ptr< YieldTermStructure > r