182 {
183 calculate();
184
185 std::string index = indexInput;
186 IndexInfo indexInfo(index);
187
188
189 QL_DEPRECATED_DISABLE_WARNING
190
191 if (indexInfo.isInf()) {
194 "ModelImpl::eval(): did not find inflation index '" << indexInput << "' in model index list.");
195 Date baseDate = inf->second->zeroInflationTermStructure()->baseDate();
196 Date effectiveFixingDate = fwddate != Null<Date>() ? fwddate : obsdate;
197 std::pair<Date, Date> lim = inflationPeriod(effectiveFixingDate, inf->second->frequency());
198 RandomVariable indexStart =
200 std::distance(
infIndices_.begin(), inf), lim.first, obsdate, fwddate, baseDate);
201
202 if (!indexInfo.inf()->interpolated()) {
203 return indexStart;
204 }
205 ALOG(
"Interpolated Inflation Indices are deprecated, adjust your script to handle interpolation there");
206
208 std::distance(
infIndices_.begin(), inf), lim.second + 1,
209 obsdate, fwddate, baseDate);
210
211 return indexStart +
212 (indexEnd - indexStart) * RandomVariable(
size(),
static_cast<Real
>(effectiveFixingDate - lim.first) /
213 static_cast<Real>(lim.second + 1 - lim.first));
214 }
215 QL_DEPRECATED_ENABLE_WARNING
216
217
218
219
220
221 if (fwddate == Null<Date>()) {
224
227 return RandomVariable(
size(),
228 ir->second->fixing(ir->second->fixingCalendar().adjust(obsdate, Preceding)));
229 } else {
230 QL_FAIL("ir (fallback ibor) index '" << indexInput
231 << "' not found in ir indices list, internal error.");
232 }
233 } else {
234
235 QuantLib::ext::shared_ptr<Index> idx = indexInfo.index(obsdate);
236 Real fixing = Null<Real>();
237 try {
238 fixing = idx->fixing(idx->fixingCalendar().adjust(obsdate, Preceding));
239 } catch (...) {
240 }
241 if (fixing != Null<Real>())
242 return RandomVariable(
size(), fixing);
243 else {
244
246 if (returnMissingFixingAsNull)
247 return RandomVariable();
248 else {
249 QL_FAIL("missing "
250 << idx->name() << " fixing for " << QuantLib::io::iso_date(obsdate)
251 << " (adjusted fixing date = "
252 << QuantLib::io::iso_date(idx->fixingCalendar().adjust(obsdate, Preceding)) << ")");
253 }
254 }
255 }
256 }
257 }
258 } else {
259
260 QL_REQUIRE(obsdate >=
referenceDate(),
"if fwd date is given ("
261 << QuantLib::io::iso_date(fwddate) << "), obsdate ("
262 << QuantLib::io::iso_date(obsdate) << ") must be >= refdate ("
264 }
265
266
267
268
269
270 if (indexInfo.isIr()) {
274 QL_REQUIRE(res.initialised(), "internal error: could not project "
275 << ir->second->name() << " fixing for (obsdate/fwddate) = ("
276 << QuantLib::io::iso_date(obsdate) << ","
277 << QuantLib::io::iso_date(fwddate) << ")");
278 return res;
279 }
280 }
281
282
283
284
285
286 if (indexInfo.isFx())
287 indexInfo = IndexInfo("FX-GENERIC-" + indexInfo.fx()->sourceCurrency().code() + "-" +
288 indexInfo.fx()->targetCurrency().code());
289
290 RandomVariable res;
293
295 } else {
296
297 QL_REQUIRE(indexInfo.isFx(), "ModelImpl::eval(): index " << index << " not handled");
298
299 RandomVariable fx1(
size(), 1.0), fx2(
size(), 1.0);
300 if (indexInfo.fx()->sourceCurrency() == indexInfo.fx()->targetCurrency()) {
301 res = fx1;
302
303 } else {
304 Size ind1 = Null<Size>(), ind2 = Null<Size>();
308 ind1 = i;
310 ind2 = i;
311 }
312 }
313 if (ind1 != Null<Size>()) {
315 }
316 if (ind2 != Null<Size>()) {
318 }
319 res = fx1 / fx2;
320 if (fwddate != Null<Date>()) {
323 QL_REQUIRE(ind1 !=
currencies_.end(),
"currency " << indexInfo.fx()->sourceCurrency().code()
324 << " in index " << index << " not handled");
325 QL_REQUIRE(ind2 !=
currencies_.end(),
"currency " << indexInfo.fx()->targetCurrency().code()
326 << " in index " << index << " not handled");
329 }
330 }
331 }
332
333 return res;
334}
RandomVariable getInflationIndexFixing(const bool returnMissingFixingAsNull, const std::string &indexInput, const QuantLib::ext::shared_ptr< ZeroInflationIndex > &infIndex, const Size indexNo, const Date &limDate, const Date &obsdate, const Date &fwddate, const Date &baseDate) const
virtual RandomVariable getIrIndexValue(const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const =0
#define ALOG(text)
Logging Macro (Level = Alert)