56#include <ql/tuple.hpp>
58#include <boost/graph/topological_sort.hpp>
59#include <boost/range/adaptor/map.hpp>
60#include <boost/range/adaptor/reversed.hpp>
61#include <boost/timer/timer.hpp>
77 const QuantLib::ext::shared_ptr<Loader>& loader,
78 const QuantLib::ext::shared_ptr<CurveConfigurations>&
curveConfigs,
const bool continueOnError,
79 const bool loadFixings,
const bool lazyBuild,
80 const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceData,
82 const bool buildCalibrationInfo,
const bool handlePseudoCurrencies)
84 continueOnError_(continueOnError), loadFixings_(loadFixings), lazyBuild_(lazyBuild),
85 preserveQuoteLinkage_(preserveQuoteLinkage), referenceData_(referenceData),
86 iborFallbackConfig_(iborFallbackConfig), buildCalibrationInfo_(buildCalibrationInfo) {
87 QL_REQUIRE(
params_,
"TodaysMarket: TodaysMarketParameters are null");
88 QL_REQUIRE(
loader_,
"TodaysMarket: Loader is null");
89 QL_REQUIRE(
curveConfigs_,
"TodaysMarket: CurveConfigurations are null");
95 void inc() { ++
count; }
102 std::map<std::string, boost::timer::nanosecond_type> timings;
103 std::map<std::string, Count> counts;
104 boost::timer::cpu_timer timer;
108 calibrationInfo_ = QuantLib::ext::make_shared<TodaysMarketCalibrationInfo>();
115 LOG(
"Todays Market Loading Fixings");
118 timings[
"1 load fixings"] = timer.elapsed().wall;
119 LOG(
"Todays Market Loading Fixing done.");
124 LOG(
"Todays Market Loading Dividends");
127 timings[
"2 load dividends"] = timer.elapsed().wall;
128 LOG(
"Todays Market Loading Dividends done.");
133 std::map<std::string, Handle<Quote>> fxQuotes;
135 QuantLib::ext::shared_ptr<FXSpotQuote> q = QuantLib::ext::dynamic_pointer_cast<FXSpotQuote>(md);
136 QL_REQUIRE(q,
"Failed to cast " << md->name() <<
" to FXSpotQuote");
137 fxQuotes[q->unitCcy() + q->ccy()] = q->quote();
139 fx_ = QuantLib::ext::make_shared<FXTriangulation>(fxQuotes);
141 WLOG(
"TodaysMarket::Initialise: no quotes available for date " <<
asof_);
144 timings[
"3 add all fx quotes"] = timer.elapsed().wall;
149 map<string, string> buildErrors;
151 for (
const auto& configuration :
params_->configurations()) {
156 timings[
"4 build dep graphs"] = timer.elapsed().wall;
165 for (
const auto& configuration :
params_->configurations()) {
166 map<string, string> discountCurves;
170 for (
const auto& dc : discountCurves)
176 for (
const auto& configuration :
params_->configurations()) {
178 LOG(
"Build objects in TodaysMarket configuration " << configuration.first);
184 IndexMap index = QuantLib::ext::get(boost::vertex_index, g);
185 std::vector<Vertex> order;
187 boost::topological_sort(g, std::back_inserter(order));
188 }
catch (
const std::exception& e) {
192 buildErrors[
"CurveDependencyGraph"] =
"Topological sort of dependency graph failed for configuration " +
194 "). Got cycle(s): " + getCycles(g);
196 timings[
"5 topological sort dep graphs"] += timer.elapsed().wall;
198 TLOG(
"Can build objects in the following order:");
199 for (
auto const& m : order) {
200 TLOG(
"vertex #" << index[m] <<
": " << g[m]);
205 Size countSuccess = 0, countError = 0;
206 for (
auto const& m : order) {
211 DLOG(
"built node " << g[m] <<
" in configuration " << configuration.first);
212 }
catch (
const std::exception& e) {
214 buildErrors[g[m].curveSpec->name()] = e.what();
216 buildErrors[g[m].name] = e.what();
218 ALOG(
"error while building node " << g[m] <<
" in configuration " << configuration.first <<
": "
225 LOG(
"Loaded CurvesSpecs: success: " << countSuccess <<
", error: " << countError);
229 LOG(
"Build objects in TodaysMarket lazily, i.e. when requested.");
234 LOG(
"TodaysMarket build stats:");
235 boost::timer::nanosecond_type
sum = 0;
236 for (
auto const& t : timings) {
237 std::size_t c = counts[t.first].count == 0 ? 1 : counts[t.first].count;
238 double timing =
static_cast<double>(t.second) / 1.0E6;
239 LOG(std::left << std::setw(34) << t.first <<
": " << std::right << std::setprecision(3) << std::setw(15)
240 << timing <<
" ms" << std::setw(10) << c << std::setw(15) << timing / c <<
" ms");
243 LOG(
"Total build time : " << std::setw(15) <<
static_cast<double>(
sum) / 1.0E6 <<
" ms");
247 if (!buildErrors.empty()) {
248 for (
auto const&
error : buildErrors) {
253 for (
auto const&
error : buildErrors) {
254 errStr +=
"(" +
error.first +
": " +
error.second +
"); ";
256 QL_FAIL(
"Cannot build all required curves! Building failed for: " << errStr);
274 "market object '" << node.
obj <<
"' (" << node.
name <<
") without curve spec, this is unexpected.");
275 const string& swapIndexName = node.
name;
276 const string& discountIndex = node.
mapping;
277 addSwapIndex(swapIndexName, discountIndex, configuration);
278 DLOG(
"Added SwapIndex " << swapIndexName <<
" with DiscountingIndex " << discountIndex);
280 swapIndices_.at(std::make_pair(configuration, swapIndexName)).currentLink();
287 switch (spec->baseType()) {
291 QuantLib::ext::shared_ptr<YieldCurveSpec> ycspec = QuantLib::ext::dynamic_pointer_cast<YieldCurveSpec>(spec);
292 QL_REQUIRE(ycspec,
"Failed to convert spec " << *spec <<
" to yield curve spec");
294 QuantLib::ext::shared_ptr<Conventions> conventions = InstrumentConventions::instance().conventions();
298 DLOG(
"Building YieldCurve for asof " <<
asof_);
299 QuantLib::ext::shared_ptr<YieldCurve>
yieldCurve = QuantLib::ext::make_shared<YieldCurve>(
304 DLOG(
"Added YieldCurve \"" << ycspec->name() <<
"\" to requiredYieldCurves map");
305 if (itr->second->currency().code() != ycspec->ccy()) {
306 WLOG(
"Warning: YieldCurve has ccy " << itr->second->currency() <<
" but spec has ccy "
312 DLOG(
"Adding DiscountCurve(" << node.
name <<
") with spec " << *ycspec <<
" to configuration "
317 DLOG(
"Adding YieldCurve(" << node.
name <<
") with spec " << *ycspec <<
" to configuration "
322 DLOG(
"Adding Index(" << node.
name <<
") with spec " << *ycspec <<
" to configuration "
328 QuantLib::ext::shared_ptr<IborIndex> rfrIndex;
329 auto f =
iborIndices_.find(make_pair(configuration, fallbackData.rfrIndex));
333 "Failed to build ibor fallback index '"
334 << node.
name <<
"', did not find rfr index '" << fallbackData.rfrIndex
335 <<
"' in configuration '" << configuration
336 <<
"' or default - is the rfr index configuration in todays market parameters?");
338 auto oi = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(*f->second);
341 << fallbackData.rfrIndex <<
"' as fallback for ibor index '" << node.
name
342 <<
"', but this is not an overnight index. Are the fallback rules correct here?");
343 if (
auto original = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(tmpIndex))
344 tmpIndex = QuantLib::ext::make_shared<QuantExt::FallbackOvernightIndex>(
345 original, oi, fallbackData.spread, fallbackData.switchDate,
348 tmpIndex = QuantLib::ext::make_shared<QuantExt::FallbackIborIndex>(
349 tmpIndex, oi, fallbackData.spread, fallbackData.switchDate,
351 TLOG(
"built ibor fall back index for '" << node.
name <<
"' in configuration " << configuration
352 <<
" using rfr index '" << fallbackData.rfrIndex
353 <<
"', spread " << fallbackData.spread
354 <<
", will use rfr curve in t0 market: " << std::boolalpha
357 iborIndices_[make_pair(configuration, node.
name)] = Handle<IborIndex>(tmpIndex);
359 QL_FAIL(
"unexpected market object type '"
360 << node.
obj <<
"' for yield curve, should be DiscountCurve, YieldCurve, IndexCurve");
367 DLOG(
"Building FXSpot (" << node.
name <<
") does not require any action.");
373 QuantLib::ext::shared_ptr<FXVolatilityCurveSpec> fxvolspec =
374 QuantLib::ext::dynamic_pointer_cast<FXVolatilityCurveSpec>(spec);
375 QL_REQUIRE(fxvolspec,
"Failed to convert spec " << *spec);
380 DLOG(
"Building FXVolatility for asof " <<
asof_);
381 QuantLib::ext::shared_ptr<FXVolCurve> fxVolCurve = QuantLib::ext::make_shared<FXVolCurve>(
384 calibrationInfo_->fxVolCalibrationInfo[fxvolspec->name()] = fxVolCurve->calibrationInfo();
388 DLOG(
"Adding FXVol (" << node.
name <<
") with spec " << *fxvolspec <<
" to configuration "
391 Handle<BlackVolTermStructure>(itr->second->volTermStructure());
397 QuantLib::ext::shared_ptr<SwaptionVolatilityCurveSpec> swvolspec =
398 QuantLib::ext::dynamic_pointer_cast<SwaptionVolatilityCurveSpec>(spec);
399 QL_REQUIRE(swvolspec,
"Failed to convert spec " << *spec);
403 DLOG(
"Building Swaption Volatility (" << node.
name <<
") for asof " <<
asof_);
404 QuantLib::ext::shared_ptr<SwaptionVolCurve> swaptionVolCurve = QuantLib::ext::make_shared<SwaptionVolCurve>(
407 calibrationInfo_->irVolCalibrationInfo[swvolspec->name()] = swaptionVolCurve->calibrationInfo();
411 QuantLib::ext::shared_ptr<SwaptionVolatilityCurveConfig> cfg =
412 curveConfigs_->swaptionVolCurveConfig(swvolspec->curveConfigID());
414 DLOG(
"Adding SwaptionVol (" << node.
name <<
") with spec " << *swvolspec <<
" to configuration "
417 Handle<SwaptionVolatilityStructure>(itr->second->volTermStructure());
419 cfg->proxySourceCurveId().empty()
420 ? make_pair(cfg->shortSwapIndexBase(), cfg->swapIndexBase())
421 : make_pair(cfg->proxyTargetShortSwapIndexBase(), cfg->proxyTargetSwapIndexBase());
427 QuantLib::ext::shared_ptr<YieldVolatilityCurveSpec> ydvolspec =
428 QuantLib::ext::dynamic_pointer_cast<YieldVolatilityCurveSpec>(spec);
429 QL_REQUIRE(ydvolspec,
"Failed to convert spec " << *spec);
432 DLOG(
"Building Yield Volatility for asof " <<
asof_);
433 QuantLib::ext::shared_ptr<YieldVolCurve> yieldVolCurve = QuantLib::ext::make_shared<YieldVolCurve>(
435 calibrationInfo_->irVolCalibrationInfo[ydvolspec->name()] = yieldVolCurve->calibrationInfo();
438 DLOG(
"Adding YieldVol (" << node.
name <<
") with spec " << *ydvolspec <<
" to configuration "
441 Handle<SwaptionVolatilityStructure>(itr->second->volTermStructure());
447 QuantLib::ext::shared_ptr<CapFloorVolatilityCurveSpec> cfVolSpec =
448 QuantLib::ext::dynamic_pointer_cast<CapFloorVolatilityCurveSpec>(spec);
449 QL_REQUIRE(cfVolSpec,
"Failed to convert spec " << *spec);
450 QuantLib::ext::shared_ptr<CapFloorVolatilityCurveConfig> cfg =
451 curveConfigs_->capFloorVolCurveConfig(cfVolSpec->curveConfigID());
455 DLOG(
"Building cap/floor volatility for asof " <<
asof_);
459 std::string iborIndexName = cfg->index();
460 QuantLib::Period rateComputationPeriod = cfg->rateComputationPeriod();
464 if (!cfg->discountCurve().empty()) {
467 << cfg->discountCurve()
468 <<
", not found in loaded yield curves");
473 QuantLib::ext::shared_ptr<IborIndex> sourceIndex, targetIndex;
474 if (!cfg->proxySourceCurveId().empty()) {
475 if (!cfg->proxySourceIndex().empty())
477 if (!cfg->proxyTargetIndex().empty()) {
479 iborIndexName = cfg->proxyTargetIndex();
480 rateComputationPeriod = cfg->proxyTargetRateComputationPeriod();
485 QuantLib::ext::shared_ptr<CapFloorVolCurve> capFloorVolCurve = QuantLib::ext::make_shared<CapFloorVolCurve>(
488 calibrationInfo_->irVolCalibrationInfo[cfVolSpec->name()] = capFloorVolCurve->calibrationInfo();
492 std::make_pair(capFloorVolCurve, std::make_pair(iborIndexName, rateComputationPeriod))))
496 DLOG(
"Adding CapFloorVol (" << node.
name <<
") with spec " << *cfVolSpec <<
" to configuration "
499 Handle<OptionletVolatilityStructure>(itr->second.first->capletVolStructure());
506 QuantLib::ext::shared_ptr<DefaultCurveSpec> defaultspec = QuantLib::ext::dynamic_pointer_cast<DefaultCurveSpec>(spec);
507 QL_REQUIRE(defaultspec,
"Failed to convert spec " << *spec);
511 DLOG(
"Building DefaultCurve for asof " <<
asof_);
512 QuantLib::ext::shared_ptr<DefaultCurve>
defaultCurve = QuantLib::ext::make_shared<DefaultCurve>(
516 DLOG(
"Adding DefaultCurve (" << node.
name <<
") with spec " << *defaultspec <<
" to configuration "
519 Handle<QuantExt::CreditCurve>(itr->second->creditCurve());
521 Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(itr->second->recoveryRate()));
527 QuantLib::ext::shared_ptr<CDSVolatilityCurveSpec> cdsvolspec =
528 QuantLib::ext::dynamic_pointer_cast<CDSVolatilityCurveSpec>(spec);
529 QL_REQUIRE(cdsvolspec,
"Failed to convert spec " << *spec);
532 DLOG(
"Building CDSVol for asof " <<
asof_);
533 QuantLib::ext::shared_ptr<CDSVolCurve> cdsVolCurve = QuantLib::ext::make_shared<CDSVolCurve>(
537 DLOG(
"Adding CDSVol (" << node.
name <<
") with spec " << *cdsvolspec <<
" to configuration "
540 Handle<QuantExt::CreditVolCurve>(itr->second->volTermStructure());
546 QuantLib::ext::shared_ptr<BaseCorrelationCurveSpec> baseCorrelationSpec =
547 QuantLib::ext::dynamic_pointer_cast<BaseCorrelationCurveSpec>(spec);
548 QL_REQUIRE(baseCorrelationSpec,
"Failed to convert spec " << *spec);
551 DLOG(
"Building BaseCorrelation for asof " <<
asof_);
552 QuantLib::ext::shared_ptr<BaseCorrelationCurve> baseCorrelationCurve = QuantLib::ext::make_shared<BaseCorrelationCurve>(
559 DLOG(
"Adding Base Correlation (" << node.
name <<
") with spec " << *baseCorrelationSpec
560 <<
" to configuration " << configuration);
562 Handle<QuantExt::BaseCorrelationTermStructure>(
563 itr->second->baseCorrelationTermStructure());
569 QuantLib::ext::shared_ptr<InflationCurveSpec> inflationspec = QuantLib::ext::dynamic_pointer_cast<InflationCurveSpec>(spec);
570 QL_REQUIRE(inflationspec,
"Failed to convert spec " << *spec <<
" to inflation curve spec");
573 DLOG(
"Building InflationCurve " << inflationspec->name() <<
" for asof " <<
asof_);
574 QuantLib::ext::shared_ptr<InflationCurve> inflationCurve = QuantLib::ext::make_shared<InflationCurve>(
578 inflationCurve->calibrationInfo();
582 DLOG(
"Adding ZeroInflationIndex (" << node.
name <<
") with spec " << *inflationspec
583 <<
" to configuration " << configuration);
584 QuantLib::ext::shared_ptr<ZeroInflationTermStructure> ts =
585 QuantLib::ext::dynamic_pointer_cast<ZeroInflationTermStructure>(itr->second->inflationTermStructure());
587 "expected zero inflation term structure for index " << node.
name <<
", but could not cast");
594 DLOG(
"Adding YoYInflationIndex (" << node.
name <<
") with spec " << *inflationspec
595 <<
" to configuration " << configuration);
596 QuantLib::ext::shared_ptr<YoYInflationTermStructure> ts =
597 QuantLib::ext::dynamic_pointer_cast<YoYInflationTermStructure>(itr->second->inflationTermStructure());
599 "expected yoy inflation term structure for index " << node.
name <<
", but could not cast");
601 Handle<YoYInflationIndex>(QuantLib::ext::make_shared<QuantExt::YoYInflationIndexWrapper>(
603 Handle<YoYInflationTermStructure>(ts)));
610 QuantLib::ext::shared_ptr<InflationCapFloorVolatilityCurveSpec> infcapfloorspec =
611 QuantLib::ext::dynamic_pointer_cast<InflationCapFloorVolatilityCurveSpec>(spec);
612 QL_REQUIRE(infcapfloorspec,
"Failed to convert spec " << *spec <<
" to inf cap floor spec");
615 DLOG(
"Building InflationCapFloorVolatilitySurface for asof " <<
asof_);
616 QuantLib::ext::shared_ptr<InflationCapFloorVolCurve> inflationCapFloorVolCurve =
620 .insert(make_pair(infcapfloorspec->name(), inflationCapFloorVolCurve))
625 DLOG(
"Adding InflationCapFloorVol (" << node.
name <<
") with spec " << *infcapfloorspec
626 <<
" to configuration " << configuration);
628 Handle<CPIVolatilitySurface>(itr->second->cpiInflationCapFloorVolSurface());
632 DLOG(
"Adding YoYOptionletVolatilitySurface (" << node.
name <<
") with spec " << *infcapfloorspec
633 <<
" to configuration " << configuration);
635 Handle<QuantExt::YoYOptionletVolatilitySurface>(itr->second->yoyInflationCapFloorVolSurface());
642 QuantLib::ext::shared_ptr<EquityCurveSpec> equityspec = QuantLib::ext::dynamic_pointer_cast<EquityCurveSpec>(spec);
643 QL_REQUIRE(equityspec,
"Failed to convert spec " << *spec);
646 DLOG(
"Building EquityCurve for asof " <<
asof_);
647 QuantLib::ext::shared_ptr<EquityCurve>
equityCurve = QuantLib::ext::make_shared<EquityCurve>(
653 DLOG(
"Adding EquityCurve (" << node.
name <<
") with spec " << *equityspec <<
" to configuration "
656 itr->second->equityIndex()->equityDividendCurve();
657 equitySpots_[make_pair(configuration, node.
name)] = itr->second->equityIndex()->equitySpot();
658 equityCurves_[make_pair(configuration, node.
name)] = Handle<EquityIndex2>(itr->second->equityIndex());
659 IndexNameTranslator::instance().add(itr->second->equityIndex()->name(),
660 "EQ-" + itr->second->equityIndex()->name());
667 QuantLib::ext::shared_ptr<EquityVolatilityCurveSpec> eqvolspec =
668 QuantLib::ext::dynamic_pointer_cast<EquityVolatilityCurveSpec>(spec);
670 QL_REQUIRE(eqvolspec,
"Failed to convert spec " << *spec);
673 LOG(
"Building EquityVol for asof " <<
asof_);
681 QuantLib::ext::shared_ptr<EquityVolCurve> eqVolCurve = QuantLib::ext::make_shared<EquityVolCurve>(
686 calibrationInfo_->eqVolCalibrationInfo[eqvolspec->name()] = eqVolCurve->calibrationInfo();
688 string eqName = node.
name;
689 DLOG(
"Adding EquityVol (" << eqName <<
") with spec " << *eqvolspec <<
" to configuration "
692 QuantLib::ext::shared_ptr<BlackVolTermStructure> bvts(itr->second->volTermStructure());
698 Handle<Quote> spot =
equitySpot(eqName, configuration);
699 Handle<YieldTermStructure> yts =
discountCurve(eqvolspec->ccy(), configuration);
701 bvts = QuantLib::ext::make_shared<QuantExt::BlackVolatilityWithATM>(bvts, spot, yts, divYts);
703 equityVols_[make_pair(configuration, node.
name)] = Handle<BlackVolTermStructure>(bvts);
709 QuantLib::ext::shared_ptr<SecuritySpec> securityspec = QuantLib::ext::dynamic_pointer_cast<SecuritySpec>(spec);
710 QL_REQUIRE(securityspec,
"Failed to convert spec " << *spec <<
" to security spec");
713 DLOG(
"Building Securities for asof " <<
asof_);
714 QuantLib::ext::shared_ptr<Security> security =
718 DLOG(
"Adding Security (" << node.
name <<
") with spec " << *securityspec <<
" to configuration "
720 if (!itr->second->spread().empty())
722 if (!itr->second->recoveryRate().empty())
724 if (!itr->second->cpr().empty())
725 cprs_[make_pair(configuration, node.
name)] = itr->second->cpr();
731 QuantLib::ext::shared_ptr<CommodityCurveSpec> commodityCurveSpec =
732 QuantLib::ext::dynamic_pointer_cast<CommodityCurveSpec>(spec);
733 QL_REQUIRE(commodityCurveSpec,
"Failed to convert spec, " << *spec <<
", to CommodityCurveSpec");
736 DLOG(
"Building CommodityCurve " << commodityCurveSpec->name() <<
" for asof " <<
asof_);
737 QuantLib::ext::shared_ptr<CommodityCurve> commodityCurve =
743 DLOG(
"Adding CommodityCurve, " << node.
name <<
", with spec " << *commodityCurveSpec <<
" to configuration "
745 Handle<CommodityIndex> commIdx(itr->second->commodityIndex());
747 calibrationInfo_->commodityCurveCalibrationInfo[commodityCurveSpec->name()] = itr->second->calibrationInfo();
754 QuantLib::ext::shared_ptr<CommodityVolatilityCurveSpec> commodityVolSpec =
755 QuantLib::ext::dynamic_pointer_cast<CommodityVolatilityCurveSpec>(spec);
756 QL_REQUIRE(commodityVolSpec,
"Failed to convert spec " << *spec <<
" to commodity volatility spec");
759 DLOG(
"Building commodity volatility for asof " <<
asof_);
760 QuantLib::ext::shared_ptr<CommodityVolCurve> commodityVolCurve = QuantLib::ext::make_shared<CommodityVolCurve>(
764 calibrationInfo_->commVolCalibrationInfo[commodityVolSpec->name()] = commodityVolCurve->calibrationInfo();
767 string commodityName = node.
name;
768 DLOG(
"Adding commodity volatility (" << commodityName <<
") with spec " << *commodityVolSpec
769 <<
" to configuration " << configuration);
772 QuantLib::ext::shared_ptr<BlackVolTermStructure> bvts(itr->second->volatility());
773 Handle<YieldTermStructure> discount =
discountCurve(commodityVolSpec->currency(), configuration);
775 Handle<YieldTermStructure> yield =
776 Handle<YieldTermStructure>(QuantLib::ext::make_shared<PriceTermStructureAdapter>(*priceCurve, *discount));
777 Handle<Quote> spot(QuantLib::ext::make_shared<SimpleQuote>(priceCurve->price(0,
true)));
779 bvts = QuantLib::ext::make_shared<QuantExt::BlackVolatilityWithATM>(bvts, spot, discount, yield);
780 commodityVols_[make_pair(configuration, node.
name)] = Handle<BlackVolTermStructure>(bvts);
786 QuantLib::ext::shared_ptr<CorrelationCurveSpec> corrspec = QuantLib::ext::dynamic_pointer_cast<CorrelationCurveSpec>(spec);
789 DLOG(
"Building CorrelationCurve for asof " <<
asof_);
790 QuantLib::ext::shared_ptr<CorrelationCurve> corrCurve = QuantLib::ext::make_shared<CorrelationCurve>(
796 DLOG(
"Adding CorrelationCurve (" << node.
name <<
") with spec " << *corrspec <<
" to configuration "
799 QL_REQUIRE(tokens.size() == 2,
"Invalid correlation spec " << node.
name);
801 Handle<QuantExt::CorrelationTermStructure>(itr->second->corrTermStructure());
806 QL_FAIL(
"Unhandled spec " << *spec);
816 const bool forceBuild)
const {
825 DLOG(
"market object " << o <<
"(" <<
name <<
") required for configuration '" << configuration <<
"'");
832 "Configuration '" + configuration +
833 "' not known - check why this is used. Will retry with default configuration.")
839 "Configuration 'default' not known, this is unexpected. Do nothing.")
847 Graph& g = tmp->second;
848 IndexMap index = QuantLib::ext::get(boost::vertex_index, g);
852 for (std::tie(v, vend) = boost::vertices(g); v != vend; ++v) {
853 if (g[*v].
obj == o) {
858 found = (g[*v].name ==
name);
870 DLOG(
"not found, retry with default configuration");
878 DLOG(
"not found, do nothing");
885 DLOG(
"node already built, do nothing.");
891 map<string, string> buildErrors;
892 std::vector<Vertex> order;
893 bool foundCycle =
false;
895 DfsVisitor<Vertex> dfs(order, foundCycle);
896 auto colorMap = boost::make_vector_property_map<boost::default_color_type>(index);
897 boost::depth_first_visit(g, node, dfs, colorMap);
901 buildErrors[g[node].curveSpec ? g[node].curveSpec->name() : g[node].name] =
"found cycle";
906 TLOG(
"Can build objects in the following order:");
907 for (
auto const& m : order) {
908 TLOG(
"vertex #" << index[m] <<
": " << g[m] << (g[m].built ?
" (already built)" :
" (not yet built)"));
911 Size countSuccess = 0, countError = 0;
912 for (
auto const& m : order) {
918 DLOG(
"built node " << g[m] <<
" in configuration " << configuration);
919 }
catch (
const std::exception& e) {
921 buildErrors[g[m].curveSpec->name()] = e.what();
923 buildErrors[g[m].name] = e.what();
925 ALOG(
"error while building node " << g[m] <<
" in configuration " << configuration <<
": " << e.what());
929 if (countSuccess + countError > 0) {
930 DLOG(
"Loaded CurvesSpecs: success: " << countSuccess <<
", error: " << countError);
935 if (!buildErrors.empty()) {
936 for (
auto const&
error : buildErrors) {
941 for (
auto const&
error : buildErrors) {
942 errStr +=
"(" +
error.first +
": " +
error.second +
"); ";
944 QL_FAIL(
"Cannot build all required curves! Building failed for: " << errStr);
Wrapper class for building base correlation structures.
Build optionlet volatility structures from cap floor configurations.
Class for building cds volatility structures.
@ InflationCapFloorVolatility
std::map< std::string, Graph > dependencies()
void buildDependencyGraph(const std::string &configuration, std::map< std::string, std::string > &buildErrors)
const FallbackData & fallbackData(const string &iborIndex) const
bool useRfrCurveInTodaysMarket() const
bool isIndexReplaced(const string &iborIndex, const QuantLib::Date &asof=QuantLib::Date::maxDate()) const
void log() const
generate Boost log record to pass to corresponding sinks
static const string defaultConfiguration
Default configuration label.
Handle< YieldTermStructure > discountCurve(const string &ccy, const string &configuration=Market::defaultConfiguration) const
map< pair< string, string >, Handle< OptionletVolatilityStructure > > capFloorCurves_
Handle< QuantExt::EquityIndex2 > equityCurve(const string &eqName, const string &configuration=Market::defaultConfiguration) const override
map< tuple< string, string, string >, Handle< QuantExt::CorrelationTermStructure > > correlationCurves_
map< pair< string, string >, QuantLib::Handle< QuantExt::EquityIndex2 > > equityCurves_
map< pair< string, string >, Handle< CPIVolatilitySurface > > cpiInflationCapFloorVolatilitySurfaces_
map< pair< string, string >, Handle< BlackVolTermStructure > > fxVols_
QuantLib::ext::shared_ptr< FXTriangulation > fx_
map< tuple< string, YieldCurveType, string >, Handle< YieldTermStructure > > yieldCurves_
map< pair< string, string >, QuantLib::Handle< QuantExt::CommodityIndex > > commodityIndices_
map< pair< string, string >, Handle< QuantExt::CreditCurve > > defaultCurves_
Handle< YieldTermStructure > equityDividendCurve(const string &eqName, const string &configuration=Market::defaultConfiguration) const override
map< pair< string, string >, Handle< IborIndex > > iborIndices_
map< pair< string, string >, Handle< YoYOptionletVolatilitySurface > > yoyCapFloorVolSurfaces_
Handle< QuantExt::CreditCurve > defaultCurve(const string &, const string &configuration=Market::defaultConfiguration) const override
Default Curves and Recovery Rates.
map< pair< string, string >, Handle< YoYInflationIndex > > yoyInflationIndices_
map< pair< string, string >, Handle< QuantExt::CreditVolCurve > > cdsVols_
map< pair< string, string >, Handle< Quote > > equitySpots_
map< pair< string, string >, Handle< QuantLib::SwaptionVolatilityStructure > > swaptionCurves_
map< pair< string, string >, Handle< QuantExt::BaseCorrelationTermStructure > > baseCorrelations_
map< pair< string, string >, Handle< Quote > > cprs_
map< pair< string, string >, Handle< Quote > > recoveryRates_
QuantLib::Handle< QuantExt::PriceTermStructure > commodityPriceCurve(const string &commodityName, const string &configuration=Market::defaultConfiguration) const override
Commodity curves.
Handle< Quote > equitySpot(const string &eqName, const string &configuration=Market::defaultConfiguration) const override
Equity curves.
map< pair< string, string >, Handle< ZeroInflationIndex > > zeroInflationIndices_
map< pair< string, string >, pair< string, string > > swaptionIndexBases_
map< pair< string, string >, Handle< BlackVolTermStructure > > equityVols_
map< pair< string, string >, Handle< QuantLib::SwaptionVolatilityStructure > > yieldVolCurves_
map< pair< string, string >, Handle< SwapIndex > > swapIndices_
map< pair< string, string >, Handle< Quote > > securitySpreads_
Handle< YieldTermStructure > yieldCurve(const YieldCurveType &type, const string &ccy, const string &configuration=Market::defaultConfiguration) const override
Yield Curves.
Handle< IborIndex > iborIndex(const string &indexName, const string &configuration=Market::defaultConfiguration) const override
map< pair< string, string >, QuantLib::Handle< QuantLib::BlackVolTermStructure > > commodityVols_
void addSwapIndex(const string &swapindex, const string &discountIndex, const string &configuration=Market::defaultConfiguration) const
add a swap index to the market
map< pair< string, string >, std::pair< string, QuantLib::Period > > capFloorIndexBase_
Utility class for Structured Curve errors, contains the curve ID.
map< string, QuantLib::ext::shared_ptr< GenericYieldVolCurve > > requiredGenericYieldVolCurves_
void initialise(const Date &asof)
map< string, std::pair< QuantLib::ext::shared_ptr< CapFloorVolCurve >, std::pair< std::string, QuantLib::Period > > > requiredCapFloorVolCurves_
const bool preserveQuoteLinkage_
const bool buildCalibrationInfo_
void require(const MarketObject o, const string &name, const string &configuration, const bool forceBuild=false) const override
map< string, QuantLib::ext::shared_ptr< DefaultCurve > > requiredDefaultCurves_
boost::graph_traits< Graph >::vertex_iterator VertexIterator
const bool continueOnError_
const QuantLib::ext::shared_ptr< const CurveConfigurations > curveConfigs_
boost::property_map< Graph, boost::vertex_index_t >::type IndexMap
map< string, QuantLib::ext::shared_ptr< FXVolCurve > > requiredFxVolCurves_
const QuantLib::ext::shared_ptr< TodaysMarketParameters > params_
map< string, QuantLib::ext::shared_ptr< CommodityCurve > > requiredCommodityCurves_
const QuantLib::ext::shared_ptr< ReferenceDataManager > referenceData_
map< string, map< string, QuantLib::ext::shared_ptr< SwapIndex > > > requiredSwapIndices_
map< string, QuantLib::ext::shared_ptr< CommodityVolCurve > > requiredCommodityVolCurves_
const QuantLib::ext::shared_ptr< Loader > loader_
map< string, QuantLib::ext::shared_ptr< InflationCurve > > requiredInflationCurves_
map< string, QuantLib::ext::shared_ptr< BaseCorrelationCurve > > requiredBaseCorrelationCurves_
map< string, QuantLib::ext::shared_ptr< CorrelationCurve > > requiredCorrelationCurves_
map< string, QuantLib::ext::shared_ptr< EquityCurve > > requiredEquityCurves_
boost::directed_graph< Node > Graph
std::map< std::string, Graph > dependencies_
map< string, QuantLib::ext::shared_ptr< YieldCurve > > requiredYieldCurves_
map< string, QuantLib::ext::shared_ptr< CDSVolCurve > > requiredCDSVolCurves_
boost::graph_traits< Graph >::vertex_descriptor Vertex
TodaysMarket(const Date &asof, const QuantLib::ext::shared_ptr< TodaysMarketParameters > ¶ms, const QuantLib::ext::shared_ptr< Loader > &loader, const QuantLib::ext::shared_ptr< CurveConfigurations > &curveConfigs, const bool continueOnError=false, const bool loadFixings=true, const bool lazyBuild=false, const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceData=nullptr, const bool preserveQuoteLinkage=false, const IborFallbackConfig &iborFallbackConfig=IborFallbackConfig::defaultConfig(), const bool buildCalibrationInfo=true, const bool handlePseudoCurrencies=true)
Constructor taking pointers and allowing for a lazy build of the market objects.
map< string, QuantLib::ext::shared_ptr< Security > > requiredSecurities_
const IborFallbackConfig iborFallbackConfig_
map< string, QuantLib::ext::shared_ptr< InflationCapFloorVolCurve > > requiredInflationCapFloorVolCurves_
QuantLib::ext::shared_ptr< TodaysMarketCalibrationInfo > calibrationInfo_
void buildNode(const std::string &configuration, Node &node) const
map< string, QuantLib::ext::shared_ptr< EquityVolCurve > > requiredEquityVolCurves_
Class for building a commodity price curve.
Wrapper class for building commodity volatility structures.
Wrapper class for building Default curves.
Wrapper class for building Equity curves.
Wrapper class for building Equity volatility structures.
Wrapper class for building FX volatility structures.
QuantLib::ext::shared_ptr< ZeroInflationIndex > parseZeroInflationIndex(const string &s, const Handle< ZeroInflationTermStructure > &h)
Convert std::string to QuantLib::ZeroInflationIndex.
QuantLib::ext::shared_ptr< IborIndex > parseIborIndex(const string &s, const Handle< YieldTermStructure > &h)
Convert std::string to QuantLib::IborIndex.
translates between QuantLib::Index::name() and ORE names
Map text representations to QuantLib/QuantExt types.
Wrapper class for building YoY Inflation CapFloor volatility structures.
Classes and functions for log message handling.
#define LOG(text)
Logging Macro (Level = Notice)
#define DLOG(text)
Logging Macro (Level = Debug)
#define ALOG(text)
Logging Macro (Level = Alert)
#define WLOG(text)
Logging Macro (Level = Warning)
#define TLOG(text)
Logging Macro (Level = Data)
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
void applyDividends(const std::set< Dividend > ÷nds)
Real sum(const Cash &c, const Cash &d)
std::vector< std::string > getCorrelationTokens(const std::string &name)
Helper function to get the two tokens in a correlation name Index2:Index1.
@ YoYInflationCapFloorVol
@ ZeroInflationCapFloorVol
std::string to_string(const LocationInfo &l)
void applyFixings(const set< Fixing > &fixings)
Utility to write a vector of fixings in the QuantLib index manager's fixing history.
Serializable Credit Default Swap.
A wrapper class for holding Bond Spread quotes.
QuantLib::ext::shared_ptr< CurveSpec > curveSpec
Error for market data or curve.
Wrapper class for building Swaption volatility structures.
vector< string > curveConfigs
string conversion utilities
An concrete implementation of the Market class that loads todays market and builds the required curve...
Wrapper class for QuantLib term structures.
Wrapper class for building yield volatility structures.