Skip to content

Commit 705225d

Browse files
committed
need old generic constructor for yoy indexes
1 parent f129f06 commit 705225d

2 files changed

Lines changed: 31 additions & 120 deletions

File tree

ql/indexes/inflationindex.cpp

Lines changed: 30 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -372,122 +372,46 @@ namespace QuantLib {
372372
}
373373

374374

375-
Rate YoYInflationIndex::fixing(const Date& fixingDate,
376-
bool /*forecastTodaysFixing*/) const {
377-
378-
// <<<<<<< HEAD
375+
Rate YoYInflationIndex::fixing(const Date& fixingDate, bool /*forecastTodaysFixing*/) const {
379376
if (needsForecast(fixingDate)) {
380-
// =======
381-
// Date today = Settings::instance().evaluationDate();
382-
// Date todayMinusLag = today - availabilityLag_;
383-
// std::pair<Date,Date> lim = inflationPeriod(todayMinusLag, frequency_);
384-
// Date lastFix = lim.first-1;
385-
386-
// Date flatMustForecastOn = lastFix+1;
387-
// Date interpMustForecastOn = lastFix+1 - Period(frequency_);
388-
389-
// if (interpolated() && fixingDate >= interpMustForecastOn) {
390-
// >>>>>>> v1.31.1
391377
return forecastFixing(fixingDate);
392-
}
393-
else {
394-
395-
// four cases with ratio() and interpolated()
396-
397-
// <<<<<<< HEAD
378+
} else {
398379
const TimeSeries<Real>& ts = timeSeries();
399380
if (ratio()) {
400381

401-
if (interpolated()) { // IS ratio, IS interpolated
402-
403-
std::pair<Date, Date> lim = inflationPeriod(fixingDate, frequency_);
404-
Date fixMinus1Y = NullCalendar().advance(fixingDate, -1 * Years, ModifiedFollowing);
405-
std::pair<Date, Date> limBef = inflationPeriod(fixMinus1Y, frequency_);
406-
Real dp = lim.second + 1 - lim.first;
407-
Real dpBef = limBef.second + 1 - limBef.first;
408-
Real dl = fixingDate - lim.first;
409-
// potentially does not work on 29th Feb
410-
Real dlBef = fixMinus1Y - limBef.first;
411-
// get the four relevant fixings
412-
Rate limFirstFix = ts[lim.first];
413-
QL_REQUIRE(limFirstFix != Null<Rate>(),
414-
"Missing " << name() << " fixing for " << lim.first);
415-
Rate limSecondFix = ts[lim.second + 1];
416-
QL_REQUIRE(limSecondFix != Null<Rate>(),
417-
"Missing " << name() << " fixing for " << lim.second + 1);
418-
Rate limBefFirstFix = ts[limBef.first];
419-
QL_REQUIRE(limBefFirstFix != Null<Rate>(),
420-
"Missing " << name() << " fixing for " << limBef.first);
421-
Rate limBefSecondFix = ts[limBef.second + 1];
422-
// QL1.29 MergeConflict ours
423-
//Rate limBefSecondFix =
424-
// IndexManager::instance().getHistory(name())[limBef.second + 1];
425-
QL_REQUIRE(limBefSecondFix != Null<Rate>(),
426-
"Missing " << name() << " fixing for " << limBef.second + 1);
427-
428-
Real linearNow = limFirstFix + (limSecondFix - limFirstFix) * dl / dp;
429-
Real linearBef =
430-
limBefFirstFix + (limBefSecondFix - limBefFirstFix) * dlBef / dpBef;
431-
Rate wasYES = linearNow / linearBef - 1.0;
432-
433-
return wasYES;
382+
auto interpolationType = interpolated() ? CPI::Linear : CPI::Flat;
434383

435-
}
436-
else { // IS ratio, NOT interpolated
437-
std::pair<Date, Date> lim = inflationPeriod(fixingDate, frequency_);
438-
Rate pastFixing = ts[lim.first];
439-
QL_REQUIRE(pastFixing != Null<Rate>(),
440-
"Missing " << name() << " fixing for " << fixingDate);
441-
Date previousDate = fixingDate - 1 * Years;
442-
std::pair<Date, Date> limBef = inflationPeriod(previousDate, frequency_);
443-
Rate previousFixing = ts[limBef.first];
444-
QL_REQUIRE(previousFixing != Null<Rate>(),
445-
"Missing " << name() << " fixing for " << limBef.first);
446-
447-
return pastFixing / previousFixing - 1.0;
448-
}
449-
450-
}
451-
else { // NOT ratio
452-
// =======
453-
// const TimeSeries<Real>& ts = timeSeries();
454-
// if (ratio()) {
384+
Rate pastFixing = CPI::laggedFixing(underlyingIndex_, fixingDate, Period(0, Months),
385+
interpolationType);
386+
Rate previousFixing = CPI::laggedFixing(underlyingIndex_, fixingDate - 1 * Years,
387+
Period(0, Months), interpolationType);
455388

456-
// auto interpolationType = interpolated() ? CPI::Linear : CPI::Flat;
457-
458-
// Rate pastFixing = CPI::laggedFixing(underlyingIndex_, fixingDate, Period(0, Months), interpolationType);
459-
// Rate previousFixing = CPI::laggedFixing(underlyingIndex_, fixingDate - 1*Years, Period(0, Months), interpolationType);
460-
461-
// return pastFixing/previousFixing - 1.0;
462-
// >>>>>>> v1.31.1
389+
return pastFixing / previousFixing - 1.0;
463390

391+
} else { // NOT ratio
464392
if (interpolated()) { // NOT ratio, IS interpolated
465393

466-
std::pair<Date, Date> lim = inflationPeriod(fixingDate, frequency_);
467-
Real dp = lim.second + 1 - lim.first;
468-
Real dl = fixingDate - lim.first;
469-
Rate limFirstFix = ts[lim.first];
470-
QL_REQUIRE(limFirstFix != Null<Rate>(),
471-
"Missing " << name() << " fixing for "
472-
<< lim.first);
473-
Rate limSecondFix = ts[lim.second + 1];
474-
QL_REQUIRE(limSecondFix != Null<Rate>(),
475-
"Missing " << name() << " fixing for "
476-
<< lim.second + 1);
477-
Real linearNow = limFirstFix + (limSecondFix - limFirstFix) * dl / dp;
478-
479-
return linearNow;
480-
481-
}
482-
else { // NOT ratio, NOT interpolated
483-
// so just flat
484-
485-
std::pair<Date, Date> lim = inflationPeriod(fixingDate, frequency_);
486-
Rate pastFixing = ts[lim.first];
487-
QL_REQUIRE(pastFixing != Null<Rate>(),
488-
"Missing " << name() << " fixing for " << lim.first);
489-
return pastFixing;
490-
394+
std::pair<Date, Date> lim = inflationPeriod(fixingDate, frequency_);
395+
Real dp = lim.second + 1 - lim.first;
396+
Real dl = fixingDate - lim.first;
397+
Rate limFirstFix = ts[lim.first];
398+
QL_REQUIRE(limFirstFix != Null<Rate>(),
399+
"Missing " << name() << " fixing for " << lim.first);
400+
Rate limSecondFix = ts[lim.second + 1];
401+
QL_REQUIRE(limSecondFix != Null<Rate>(),
402+
"Missing " << name() << " fixing for " << lim.second + 1);
403+
Real linearNow = limFirstFix + (limSecondFix - limFirstFix) * dl / dp;
404+
405+
return linearNow;
406+
407+
} else { // NOT ratio, NOT interpolated
408+
// so just flat
409+
410+
std::pair<Date, Date> lim = inflationPeriod(fixingDate, frequency_);
411+
Rate pastFixing = ts[lim.first];
412+
QL_REQUIRE(pastFixing != Null<Rate>(),
413+
"Missing " << name() << " fixing for " << lim.first);
414+
return pastFixing;
491415
}
492416
}
493417
}
@@ -509,21 +433,10 @@ namespace QuantLib {
509433

510434
ext::shared_ptr<YoYInflationIndex> YoYInflationIndex::clone(
511435
const Handle<YoYInflationTermStructure>& h) const {
512-
/*
513-
if (ratio_) {
514-
return ext::make_shared<YoYInflationIndex>(underlyingIndex_, interpolated_, h);
515-
} else {
516-
return ext::make_shared<YoYInflationIndex>(familyName_, region_, revised_,
517-
interpolated_, frequency_,
518-
availabilityLag_, currency_, h);
519-
}
520-
*/
521436
return ext::make_shared<YoYInflationIndex>(
522437
familyName_, region_, revised_,
523438
interpolated_, ratio_, frequency_,
524439
availabilityLag_, currency_, h);
525-
526-
527440
}
528441

529442

ql/indexes/inflationindex.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,8 @@ namespace QuantLib {
263263
year-on-year values; if `ratio` is true, they must be the
264264
past fixings of the underlying index.
265265
266-
\deprecated Use one of the other constructors instead.
267-
Deprecated in version 1.31.
266+
Deprecated in QL version 1.31 but needed in ORE
268267
*/
269-
QL_DEPRECATED
270268
YoYInflationIndex(
271269
const std::string& familyName,
272270
const Region& region,

0 commit comments

Comments
 (0)