672 {
673 static long id = 0;
674 ConvertibleBondData
data(BondData(securityId, 1.0));
675 data.populateFromBondReferenceData(referenceData);
676 ConvertibleBond bond(Envelope(), data);
677 bond.id() = "ConvertibleBondBuilder_" + securityId + "_" + std::to_string(id++);
678 bond.build(engineFactory);
679
680 QL_REQUIRE(bond.instrument(), "ConvertibleBondBuilder: constructed bond is null, this is unexpected");
681 auto qlBond = QuantLib::ext::dynamic_pointer_cast<QuantLib::Bond>(bond.instrument()->qlInstrument());
682
683 QL_REQUIRE(
684 bond.instrument() && bond.instrument()->qlInstrument(),
685 "ConvertibleBondBuilder: constructed bond trade does not provide a valid ql instrument, this is unexpected "
686 "(either the instrument wrapper or the ql instrument is null)");
687
688 BondBuilder::Result res;
689 res.bond = qlBond;
690 res.hasCreditRisk =
data.bondData().hasCreditRisk() && !
data.bondData().creditCurveId().empty();
691 res.currency =
data.bondData().currency();
692 res.creditCurveId =
data.bondData().creditCurveId();
693 res.securityId =
data.bondData().securityId();
694 res.creditGroup =
data.bondData().creditGroup();
695 res.priceQuoteMethod =
data.bondData().priceQuoteMethod();
696 res.priceQuoteBaseValue =
data.bondData().priceQuoteBaseValue();
697
698 auto builders = engineFactory->modelBuilders();
699 auto b = std::find_if(builders.begin(), builders.end(),
700 [&bond](const std::pair<const std::string&, const QuantLib::ext::shared_ptr<ModelBuilder>>& p) {
701 return bond.id() == p.first;
702 });
703 QL_REQUIRE(b != builders.end(), "ConvertibleBondBuilder: could not get model builder for bond '"
704 << bond.id() << "' from engine factory - this is an internal error.");
705 res.modelBuilder = b->second;
706
707 return res;
708}