Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
modelcgimpl.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
23
28
29#include <ql/math/comparison.hpp>
30#include <ql/quotes/simplequote.hpp>
31
32namespace ore {
33namespace data {
34
35using namespace QuantLib;
36
37ModelCGImpl::ModelCGImpl(const DayCounter& dayCounter, const Size size, const std::vector<std::string>& currencies,
38 const std::vector<std::pair<std::string, QuantLib::ext::shared_ptr<InterestRateIndex>>>& irIndices,
39 const std::vector<std::pair<std::string, QuantLib::ext::shared_ptr<ZeroInflationIndex>>>& infIndices,
40 const std::vector<std::string>& indices, const std::vector<std::string>& indexCurrencies,
41 const std::set<Date>& simulationDates, const IborFallbackConfig& iborFallbackConfig)
42 : ModelCG(size), dayCounter_(dayCounter), currencies_(currencies), indexCurrencies_(indexCurrencies),
43 simulationDates_(simulationDates), iborFallbackConfig_(iborFallbackConfig) {
44
45 // populate index vectors
46
47 for (auto const& str : indices) {
48 indices_.push_back(IndexInfo(str));
49 }
50
51 for (auto const& p : irIndices) {
52 irIndices_.push_back(std::make_pair(IndexInfo(p.first), p.second));
53 }
54
55 for (auto const& p : infIndices) {
56 infIndices_.push_back(std::make_pair(IndexInfo(p.first), p.second));
57 }
58
59 // check consistency of inputs
60
61 QL_REQUIRE(indexCurrencies_.size() == indices_.size(), "mismatch of indexCurrencies (" << indexCurrencies_.size()
62 << ") and indices ("
63 << indices_.size() << ")");
64
65 for (auto const& c : currencies_)
66 QL_REQUIRE(!c.empty(), "empty currency string");
67
68 // look for fx indices, check consistency with currencies and index currencies vectors
69
70 for (Size i = 0; i < indices_.size(); ++i) {
71 if (indices_[i].isFx()) {
72 QL_REQUIRE(indices_[i].fx()->targetCurrency().code() == currencies_.front(),
73 "fx index domestic currency (" << indices_[i].fx()->targetCurrency().code()
74 << ") does not match base currency (" << currencies_.front()
75 << ")");
76 QL_REQUIRE(indices_[i].fx()->sourceCurrency().code() == indexCurrencies_[i],
77 "fx index foreign currency (" << indices_[i].fx()->sourceCurrency().code()
78 << ") does not match index currency (" << indexCurrencies_[i]);
79 auto ccy = std::find(currencies_.begin(), currencies_.end(), indexCurrencies_[i]);
80 QL_REQUIRE(ccy != currencies_.end(),
81 "fx index foreign currency (" << indexCurrencies_[i] << ") not found in model currencies");
82 }
83 }
84
85 // register with observables
86
87 for (auto const& i : irIndices_)
88 registerWith(i.second);
89
90 for (auto const& i : infIndices_)
91 registerWith(i.second);
92
93 for (auto const& i : indices_) {
94 if (i.isComm()) {
95 for (auto const& d : simulationDates_)
96 registerWith(i.index(d));
97 } else
98 registerWith(i.index());
99 }
100
101} // ModelCGImpl ctor
102
103std::size_t ModelCGImpl::dt(const Date& d1, const Date& d2) const {
104 return cg_const(*g_, dayCounter_.yearFraction(d1, d2));
105}
106
107std::size_t ModelCGImpl::pay(const std::size_t amount, const Date& obsdate, const Date& paydate,
108 const std::string& currency) const {
109 calculate();
110
111 std::string id = "__pay_" + ore::data::to_string(obsdate) + "_" + ore::data::to_string(paydate) + "_" + currency;
112
113 std::size_t n;
114 if (n = cg_var(*g_, id, ComputationGraph::VarDoesntExist::Nan); n == ComputationGraph::nan) {
115
116 // result is as of max(obsdate, refDate) by definition of pay()
117
118 Date effectiveDate = std::max(obsdate, referenceDate());
119 auto c = std::find(currencies_.begin(), currencies_.end(), currency);
120 QL_REQUIRE(c != currencies_.end(), "currency " << currency << " not handled");
121 Size cidx = std::distance(currencies_.begin(), c);
122
123 // do we have a dynamic fx underlying to convert to base at the effective date?
124
125 std::size_t fxSpot = 0;
126 for (Size i = 0; i < indexCurrencies_.size(); ++i) {
127 if (indices_.at(i).isFx() && currency == indexCurrencies_[i]) {
128 fxSpot = getIndexValue(i, effectiveDate);
129 break;
130 }
131 }
132
133 // if no we use the zero vol fx spot at the effective date
134
135 if (fxSpot == 0) {
136 if (cidx > 0)
137 fxSpot =
138 cg_div(*g_, cg_mult(*g_, getFxSpot(cidx - 1), getDiscount(cidx, referenceDate(), effectiveDate)),
139 getDiscount(0, referenceDate(), effectiveDate));
140 else
141 fxSpot = cg_const(*g_, 1.0);
142 }
143
144 // discount from pay to obs date on ccy curve, convert to base ccy and divide by the numeraire
145
146 n = cg_mult(*g_, cg_div(*g_, getDiscount(cidx, effectiveDate, paydate), getNumeraire(effectiveDate)), fxSpot);
147 g_->setVariable(id, n);
148 }
149
150 return cg_mult(*g_, amount, n);
151}
152
153std::size_t ModelCGImpl::discount(const Date& obsdate, const Date& paydate, const std::string& currency) const {
154 calculate();
155 auto c = std::find(currencies_.begin(), currencies_.end(), currency);
156 QL_REQUIRE(c != currencies_.end(), "currency " << currency << " not handled");
157 Size cidx = std::distance(currencies_.begin(), c);
158 return getDiscount(cidx, obsdate, paydate);
159}
160
161namespace {
162struct comp {
163 comp(const std::string& indexInput) : indexInput_(indexInput) {}
164 template <typename T> bool operator()(const std::pair<IndexInfo, QuantLib::ext::shared_ptr<T>>& p) const {
165 return p.first.name() == indexInput_;
166 }
167 const std::string indexInput_;
168};
169} // namespace
170
171std::size_t ModelCGImpl::getInflationIndexFixing(const bool returnMissingFixingAsNull, const std::string& indexInput,
172 const QuantLib::ext::shared_ptr<ZeroInflationIndex>& infIndex,
173 const Size indexNo, const Date& limDate, const Date& obsdate,
174 const Date& fwddate, const Date& baseDate) const {
175 std::size_t res;
176 Real f = infIndex->timeSeries()[limDate];
177 // we exclude historical fixings
178 // - which are "impossible" to know (limDate > refDate)
179 // - which have to be projected because a fwd date is given and they are later than the obsdate
180 if (f != Null<Real>() && !(limDate > referenceDate()) && (fwddate == Null<Date>() || limDate <= obsdate)) {
181 res = cg_const(*g_, f);
182 } else {
183 Date effectiveObsDate = std::min(obsdate, limDate);
184 if (effectiveObsDate >= baseDate) {
185 res = getInfIndexValue(indexNo, effectiveObsDate, limDate);
186 } else if (returnMissingFixingAsNull) {
188 } else {
189 QL_FAIL("missing " << indexInput << " fixing for " << QuantLib::io::iso_date(limDate) << " (obsdate="
190 << QuantLib::io::iso_date(obsdate) << ", fwddate=" << QuantLib::io::iso_date(fwddate)
191 << ", basedate=" << QuantLib::io::iso_date(baseDate) << ")");
192 }
193 }
194 return res;
195}
196
197std::size_t ModelCGImpl::eval(const std::string& indexInput, const Date& obsdate, const Date& fwddate,
198 const bool returnMissingFixingAsNull, const bool ignoreTodaysFixing) const {
199 calculate();
200
201 std::string id = "__eval_" + indexInput + "_" + ore::data::to_string(obsdate) + "_" +
202 ore::data::to_string(fwddate) + "_" + (returnMissingFixingAsNull ? "1" : "0") + "_" +
203 (ignoreTodaysFixing ? "1" : "0");
204
205 if (std::size_t n = cg_var(*g_, id, ComputationGraph::VarDoesntExist::Nan); n != ComputationGraph::nan) {
206 return n;
207 }
208
209 std::string index = indexInput;
210 IndexInfo indexInfo(index);
211
212 // 1 handle inflation indices
213 QL_DEPRECATED_DISABLE_WARNING
214 if (indexInfo.isInf()) {
215 auto inf = std::find_if(infIndices_.begin(), infIndices_.end(), comp(indexInput));
216 QL_REQUIRE(inf != infIndices_.end(),
217 "ModelCGImpl::eval(): did not find inflation index '" << indexInput << "' in model index list.");
218 Date baseDate = inf->second->zeroInflationTermStructure()->baseDate();
219 Date effectiveFixingDate = fwddate != Null<Date>() ? fwddate : obsdate;
220 std::pair<Date, Date> lim = inflationPeriod(effectiveFixingDate, inf->second->frequency());
221 std::size_t indexStart =
222 getInflationIndexFixing(returnMissingFixingAsNull, indexInput, inf->second,
223 std::distance(infIndices_.begin(), inf), lim.first, obsdate, fwddate, baseDate);
224 // if the index is not interpolated we are done
225 if (!indexInfo.inf()->interpolated()) {
226 return indexStart;
227 }
228 // otherwise we need to get a second value and interpolate as in ZeroInflationIndex
229 std::size_t indexEnd = getInflationIndexFixing(returnMissingFixingAsNull, indexInput, inf->second,
230 std::distance(infIndices_.begin(), inf), lim.second + 1, obsdate,
231 fwddate, baseDate);
232 // this is not entirely correct, since we should use the days in the lagged period, but we don't know the lag
233 std::size_t n = cg_add(*g_, indexStart,
234 cg_mult(*g_, cg_subtract(*g_, indexEnd, indexStart),
235 cg_const(*g_, (static_cast<Real>(effectiveFixingDate - lim.first) /
236 static_cast<Real>(lim.second + 1 - lim.first)))));
237 g_->setVariable(id, n);
238 return n;
239 }
240 QL_DEPRECATED_ENABLE_WARNING
241 // 2 handle non-inflation indices
242
243 // 2a handle historical fixings and today's fixings (if given as a historical fixing)
244 // for fx indices try to get the fixing both from the straight and the inverse index
245
246 if (fwddate == Null<Date>()) {
247 if (obsdate < referenceDate() || (obsdate == referenceDate() && !ignoreTodaysFixing)) {
249 // handle ibor fallback indices, they don't fit into the below treatment...
250 auto ir = std::find_if(irIndices_.begin(), irIndices_.end(), comp(indexInput));
251 if (ir != irIndices_.end()) {
252 std::size_t n =
253 cg_const(*g_, ir->second->fixing(ir->second->fixingCalendar().adjust(obsdate, Preceding)));
254 g_->setVariable(id, n);
255 return n;
256 } else {
257 QL_FAIL("ir (fallback ibor) index '" << indexInput
258 << "' not found in ir indices list, internal error.");
259 }
260 } else {
261 // handle all other cases than ibor fallback indices
262 QuantLib::ext::shared_ptr<Index> idx = indexInfo.index(obsdate);
263 Real fixing = Null<Real>();
264 try {
265 fixing = idx->fixing(idx->fixingCalendar().adjust(obsdate, Preceding));
266 } catch (...) {
267 }
268 if (fixing != Null<Real>()) {
269 std::size_t n = cg_const(*g_, fixing);
270 g_->setVariable(id, n);
271 return n;
272 } else {
273 // for dates < refDate we are stuck now
274 if (obsdate != referenceDate()) {
275 if (returnMissingFixingAsNull) {
276 std::size_t n = ComputationGraph::nan;
277 g_->setVariable(id, n);
278 return n;
279 } else {
280 QL_FAIL("missing "
281 << idx->name() << " fixing for " << QuantLib::io::iso_date(obsdate)
282 << " (adjusted fixing date = "
283 << QuantLib::io::iso_date(idx->fixingCalendar().adjust(obsdate, Preceding)) << ")");
284 }
285 }
286 }
287 }
288 }
289 } else {
290 // if fwd date is given, ensure we can project
291 QL_REQUIRE(obsdate >= referenceDate(), "if fwd date is given ("
292 << QuantLib::io::iso_date(fwddate) << "), obsdate ("
293 << QuantLib::io::iso_date(obsdate) << ") must be >= refdate ("
294 << QuantLib::io::iso_date(referenceDate()) << ")");
295 }
296
297 // 2b handle fixings >= today (and fwd fixings, in which case we know fwddate > obsdate >= refdate)
298
299 // 2b1 handle IR indices
300
301 if (indexInfo.isIr()) {
302 auto ir = std::find_if(irIndices_.begin(), irIndices_.end(), comp(indexInput));
303 if (ir != irIndices_.end()) {
304 std::size_t res = getIrIndexValue(std::distance(irIndices_.begin(), ir), obsdate, fwddate);
305 QL_REQUIRE(res != ComputationGraph::nan, "internal error: could not project "
306 << ir->second->name() << " fixing for (obsdate/fwddate) = ("
307 << QuantLib::io::iso_date(obsdate) << ","
308 << QuantLib::io::iso_date(fwddate) << ")");
309 g_->setVariable(id, res);
310 return res;
311 }
312 }
313
314 // 2b2 handle FX, EQ, COMM indices
315
316 // if we have an FX index, we "normalise" the tag by GENERIC (since it does not matter for projections)
317
318 if (indexInfo.isFx())
319 indexInfo = IndexInfo("FX-GENERIC-" + indexInfo.fx()->sourceCurrency().code() + "-" +
320 indexInfo.fx()->targetCurrency().code());
321
322 std::size_t res;
323 auto i = std::find(indices_.begin(), indices_.end(), indexInfo);
324 if (i != indices_.end()) {
325 // we have the index directly as an underlying
326 res = getIndexValue(std::distance(indices_.begin(), i), obsdate, fwddate);
327 } else {
328 // if not, we can only try something else for FX indices
329 QL_REQUIRE(indexInfo.isFx(), "ModelCGImpl::eval(): index " << index << " not handled");
330 // is it a trivial fx index (CCY-CCY) or can we triangulate it?
331 std::size_t fx1 = cg_const(*g_, 1.0), fx2 = cg_const(*g_, 1.0);
332 if (indexInfo.fx()->sourceCurrency() == indexInfo.fx()->targetCurrency()) {
333 res = fx1;
334 // no fwd correction required, if ccy1=ccy2 we have spot = fwd = 1
335 } else {
336 Size ind1 = Null<Size>(), ind2 = Null<Size>();
337 for (Size i = 0; i < indexCurrencies_.size(); ++i) {
338 if (indices_[i].isFx()) {
339 if (indexInfo.fx()->sourceCurrency().code() == indexCurrencies_[i])
340 ind1 = i;
341 if (indexInfo.fx()->targetCurrency().code() == indexCurrencies_[i])
342 ind2 = i;
343 }
344 }
345 if (ind1 != Null<Size>()) {
346 fx1 = getIndexValue(ind1, obsdate);
347 }
348 if (ind2 != Null<Size>()) {
349 fx2 = getIndexValue(ind2, obsdate);
350 }
351 res = cg_div(*g_, fx1, fx2);
352 if (fwddate != Null<Date>()) {
353 auto ind1 = std::find(currencies_.begin(), currencies_.end(), indexInfo.fx()->sourceCurrency().code());
354 auto ind2 = std::find(currencies_.begin(), currencies_.end(), indexInfo.fx()->targetCurrency().code());
355 QL_REQUIRE(ind1 != currencies_.end(), "currency " << indexInfo.fx()->sourceCurrency().code()
356 << " in index " << index << " not handled");
357 QL_REQUIRE(ind2 != currencies_.end(), "currency " << indexInfo.fx()->targetCurrency().code()
358 << " in index " << index << " not handled");
359 res = cg_mult(*g_, res,
360 cg_div(*g_, getDiscount(std::distance(currencies_.begin(), ind1), obsdate, fwddate),
361 getDiscount(std::distance(currencies_.begin(), ind2), obsdate, fwddate)));
362 }
363 }
364 }
365 g_->setVariable(id, res);
366 return res;
367}
368
369std::size_t ModelCGImpl::fxSpotT0(const std::string& forCcy, const std::string& domCcy) const {
370 calculate();
371 std::string id = "__fxspott0_" + forCcy + "_" + domCcy;
372 std::size_t fx;
373 if (fx = cg_var(*g_, id, ComputationGraph::VarDoesntExist::Nan); fx == ComputationGraph::nan) {
374 auto c1 = std::find(currencies_.begin(), currencies_.end(), forCcy);
375 auto c2 = std::find(currencies_.begin(), currencies_.end(), domCcy);
376 QL_REQUIRE(c1 != currencies_.end(), "currency " << forCcy << " not handled");
377 QL_REQUIRE(c2 != currencies_.end(), "currency " << domCcy << " not handled");
378 Size cidx1 = std::distance(currencies_.begin(), c1);
379 Size cidx2 = std::distance(currencies_.begin(), c2);
380 std::size_t fx = cg_const(*g_, 1.0);
381 if (cidx1 > 0)
382 fx = cg_mult(*g_, fx, getFxSpot(cidx1 - 1));
383 if (cidx2 > 0)
384 fx = cg_div(*g_, fx, getFxSpot(cidx2 - 1));
385 g_->setVariable(id, fx);
386 }
387 return fx;
388}
389
390std::size_t ModelCGImpl::barrierProbability(const std::string& index, const Date& obsdate1, const Date& obsdate2,
391 const std::size_t barrier, const bool above) const {
392
393 calculate();
394
395 // determine the fixing calendar (assume that for commodity this is the same for different futures)
396
397 IndexInfo ind(index);
398 auto qlIndex = ind.index(obsdate1);
399
400 // handle all dates < reference date here
401
402 std::size_t barrierHit = cg_const(*g_, 0.0);
403 Date d = obsdate1;
404 while (d < std::min(referenceDate(), obsdate2)) {
405 if (qlIndex->fixingCalendar().isBusinessDay(d)) {
406 std::size_t f = eval(index, d, Null<Date>(), true);
407 if (f != ComputationGraph::nan) {
408 if (above) {
409 barrierHit =
410 cg_min(*g_, cg_const(*g_, 1.0), cg_add(*g_, barrierHit, cg_indicatorGeq(*g_, f, barrier)));
411 } else {
412 barrierHit = cg_min(
413 *g_, cg_const(*g_, 1.0),
414 cg_add(*g_, barrierHit, cg_subtract(*g_, cg_const(*g_, 1.0), cg_indicatorGt(*g_, f, barrier))));
415 }
416 } else {
417 // lax check of historical fixings, since e.g. for equity underlyings
418 // we can't expect to get the actual fixing calendar from index info
419 // TODO can we improve this by using the correct calendars?
420 TLOG("ignore missing fixing for " << qlIndex->name() << " on " << QuantLib::io::iso_date(d)
421 << " in ModelCGImpl::barrierProbability()");
422 }
423 }
424 ++d;
425 }
426
427 if (obsdate2 < referenceDate()) {
428 return barrierHit;
429 }
430
431 // handle future part (call into derived classes, this is model dependent)
432
433 std::size_t futureBarrierHit =
434 getFutureBarrierProb(index, std::max<Date>(obsdate1, referenceDate()), obsdate2, barrier, above);
435
436 // combine historical and future part and return result
437
438 return cg_add(*g_, cg_mult(*g_, cg_subtract(*g_, cg_const(*g_, 1.0), barrierHit), futureBarrierHit), barrierHit);
439}
440
442
444 if (cgEvalDate_ != referenceDate()) {
445 ++cgVersion_;
447 randomVariates_.clear();
448 modelParameters_.clear();
449 g_->clear();
450 }
451}
452
453std::size_t ModelCGImpl::cgVersion() const {
454 calculate();
455 return cgVersion_;
456}
457
458const std::vector<std::vector<std::size_t>>& ModelCGImpl::randomVariates() const {
459 calculate();
460 return randomVariates_;
461}
462
463std::vector<std::pair<std::size_t, double>> ModelCGImpl::modelParameters() const {
464 calculate();
465 std::vector<std::pair<std::size_t, double>> res;
466 for (auto const& f : modelParameters_) {
467 res.push_back(std::make_pair(f.first, f.second()));
468 }
469 return res;
470}
471
472std::vector<std::pair<std::size_t, std::function<double(void)>>>& ModelCGImpl::modelParameterFunctors() const {
473 return modelParameters_;
474}
475
476std::size_t ModelCGImpl::addModelParameter(const std::string& id, std::function<double(void)> f) const {
477 return ::ore::data::addModelParameter(*g_, modelParameters_, id, f);
478}
479
480std::size_t addModelParameter(ComputationGraph& g, std::vector<std::pair<std::size_t, std::function<double(void)>>>& m,
481 const std::string& id, std::function<double(void)> f) {
482 std::size_t n;
483 if (n = g.variable(id, ComputationGraph::VarDoesntExist::Nan); n == ComputationGraph::nan) {
484 n = cg_var(g, id, ComputationGraph::VarDoesntExist::Create);
485 m.push_back(std::make_pair(n, f));
486 }
487 return n;
488}
489
490Date getSloppyDate(const Date& d, const bool sloppyDates, const std::set<Date>& dates) {
491 if (!sloppyDates)
492 return d;
493 auto s = std::lower_bound(dates.begin(), dates.end(), d);
494 if (s == dates.end())
495 return *dates.rbegin();
496 return *s;
497}
498
499} // namespace data
500} // namespace ore
const std::string indexInput_
const std::vector< std::string > & indexCurrencies_
std::size_t variable(const std::string &name, const bool createIfNotExists=false)
static std::size_t nan
QuantLib::ext::shared_ptr< Index > index(const Date &obsDate=Date()) const
Definition: utilities.cpp:449
QuantLib::ext::shared_ptr< ZeroInflationIndex > inf() const
Definition: utilities.hpp:123
bool isIr() const
Definition: utilities.hpp:103
QuantLib::ext::shared_ptr< FallbackIborIndex > irIborFallback(const IborFallbackConfig &iborFallbackConfig, const Date &asof=QuantLib::Date::maxDate()) const
Definition: utilities.cpp:501
bool isFx() const
Definition: utilities.hpp:100
QuantLib::ext::shared_ptr< FxIndex > fx() const
Definition: utilities.hpp:109
bool isInf() const
Definition: utilities.hpp:106
virtual const Date & referenceDate() const =0
QuantLib::ext::shared_ptr< QuantExt::ComputationGraph > g_
Definition: modelcg.hpp:149
void calculate() const override
Definition: modelcg.hpp:142
virtual std::size_t getInfIndexValue(const Size indexNo, const Date &d, const Date &fwd) const =0
std::size_t addModelParameter(const std::string &id, std::function< double(void)> f) const
void performCalculations() const override
const std::vector< std::string > currencies_
std::vector< std::vector< size_t > > randomVariates_
std::size_t pay(const std::size_t amount, const Date &obsdate, const Date &paydate, const std::string &currency) const override
Real extractT0Result(const RandomVariable &value) const override
std::size_t cgVersion() const override
std::size_t 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
std::vector< std::pair< std::size_t, std::function< double(void)> > > & modelParameterFunctors() const override
virtual std::size_t getIrIndexValue(const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const =0
std::size_t discount(const Date &obsdate, const Date &paydate, const std::string &currency) const override
std::vector< std::pair< std::size_t, std::function< double(void)> > > modelParameters_
std::vector< std::pair< IndexInfo, QuantLib::ext::shared_ptr< ZeroInflationIndex > > > infIndices_
virtual std::size_t getFutureBarrierProb(const std::string &index, const Date &obsdate1, const Date &obsdate2, const std::size_t barrier, const bool above) const =0
QuantLib::Date cgEvalDate_
std::size_t dt(const Date &d1, const Date &d2) const override
std::vector< IndexInfo > indices_
virtual std::size_t getFxSpot(const Size idx) const =0
ModelCGImpl(const DayCounter &dayCounter, const Size size, const std::vector< std::string > &currencies, const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< InterestRateIndex > > > &irIndices, const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< ZeroInflationIndex > > > &infIndices, const std::vector< std::string > &indices, const std::vector< std::string > &indexCurrencies, const std::set< Date > &simulationDates, const IborFallbackConfig &iborFallbackConfig)
Definition: modelcgimpl.cpp:37
virtual std::size_t getIndexValue(const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const =0
std::size_t barrierProbability(const std::string &index, const Date &obsdate1, const Date &obsdate2, const std::size_t barrier, const bool above) const override
const DayCounter dayCounter_
virtual std::size_t getDiscount(const Size idx, const Date &s, const Date &t) const =0
virtual std::size_t getNumeraire(const Date &s) const =0
std::vector< std::pair< IndexInfo, QuantLib::ext::shared_ptr< InterestRateIndex > > > irIndices_
std::size_t fxSpotT0(const std::string &forCcy, const std::string &domCcy) const override
std::vector< std::pair< std::size_t, double > > modelParameters() const override
const std::vector< std::vector< std::size_t > > & randomVariates() const override
const std::vector< std::string > indexCurrencies_
const IborFallbackConfig iborFallbackConfig_
const std::set< Date > simulationDates_
std::size_t eval(const std::string &index, const Date &obsdate, const Date &fwddate, const bool returnMissingMissingAsNull=false, const bool ignoreTodaysFixing=false) const override
SafeStack< ValueType > value
Map text representations to QuantLib/QuantExt types.
@ data
Definition: log.hpp:77
#define TLOG(text)
Logging Macro (Level = Data)
Definition: log.hpp:556
basis implementation for a script engine model
std::size_t cg_min(ComputationGraph &g, const std::size_t a, const std::size_t b, const std::string &label)
std::size_t cg_const(ComputationGraph &g, const double value)
std::size_t cg_indicatorGeq(ComputationGraph &g, const std::size_t a, const std::size_t b, const std::string &label)
std::size_t cg_subtract(ComputationGraph &g, const std::size_t a, const std::size_t b, const std::string &label)
RandomVariable expectation(const RandomVariable &r)
std::size_t cg_mult(ComputationGraph &g, const std::size_t a, const std::size_t b, const std::string &label)
std::size_t cg_add(ComputationGraph &g, const std::size_t a, const std::size_t b, const std::string &label)
std::size_t cg_var(ComputationGraph &g, const std::string &name, const bool createIfNotExists)
std::size_t cg_div(ComputationGraph &g, const std::size_t a, const std::size_t b, const std::string &label)
std::size_t cg_indicatorGt(ComputationGraph &g, const std::size_t a, const std::size_t b, const std::string &label)
Size size(const ValueType &v)
Definition: value.cpp:145
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
std::size_t addModelParameter(ComputationGraph &g, std::vector< std::pair< std::size_t, std::function< double(void)> > > &m, const std::string &id, std::function< double(void)> f)
Date getSloppyDate(const Date &d, const bool sloppyDates, const std::set< Date > &dates)
Serializable Credit Default Swap.
Definition: namespaces.docs:23
some utility functions
Real at(const Size i) const
string conversion utilities