23#include <ql/cashflows/cashflows.hpp>
25#include <boost/lexical_cast.hpp>
33std::map<AssetClass, std::set<std::string>>
35 return bond_.underlyingIndices(referenceDataManager);
38void Ascot::build(
const QuantLib::ext::shared_ptr<ore::data::EngineFactory>& engineFactory) {
39 DLOG(
"Ascot::build() called for trade " <<
id());
42 additionalData_[
"isdaAssetClass"] = string(
"Credit");
43 additionalData_[
"isdaBaseProduct"] = string(
"Exotic");
44 additionalData_[
"isdaSubProduct"] = string(
"Other");
45 additionalData_[
"isdaTransaction"] = string(
"");
50 bond_.id() = id() +
"_Bond";
51 bond_.build(engineFactory);
52 requiredFixings_.addData(
bond_.requiredFixings());
53 QuantLib::ext::shared_ptr<QuantExt::ConvertibleBond2> cb =
54 QuantLib::ext::dynamic_pointer_cast<QuantExt::ConvertibleBond2>(
bond_.instrument()->qlInstrument());
58 QL_REQUIRE(exerciseType == Exercise::American,
"expected American exercise type");
59 QL_REQUIRE(optionData_.exerciseDates().size() == 1,
60 "Ascot::build(): exactly one option date required, found " << optionData_.exerciseDates().size());
61 Date exerciseDate =
parseDate(optionData_.exerciseDates().back());
62 QuantLib::ext::shared_ptr<Exercise>
exercise = QuantLib::ext::make_shared<AmericanExercise>(exerciseDate);
68 QL_REQUIRE(fundingLegData_.isPayer() ==
false,
"expected isPayer == false for funding leg");
71 auto builder = QuantLib::ext::dynamic_pointer_cast<AscotEngineBuilder>(engineFactory->builder(
"Ascot"));
72 auto configuration = builder->configuration(MarketContext::pricing);
73 auto legBuilder = engineFactory->legBuilder(fundingLegData_.legType());
74 fundingLeg = legBuilder->buildLeg(fundingLegData_, engineFactory, requiredFixings_, configuration);
76 QL_REQUIRE(builder,
"Ascot::build(): could not cast to AscotBuilder, this is unexpected");
79 QuantLib::ext::make_shared<QuantExt::Ascot>(type,
exercise,
bond_.data().bondData().bondNotional(), cb,
fundingLeg);
80 qlAscot->setPricingEngine(builder->engine(
id(),
bond_.data().bondData().currency()));
81 setSensitivityTemplate(*builder);
83 Real multiplier = (
parsePositionType(optionData_.longShort()) == Position::Long ? 1.0 : -1.0);
87 npvCurrency_ = notionalCurrency_ =
bond_.notionalCurrency();
88 legs_ = {cb->cashflows()};
89 legCurrencies_ = {npvCurrency_};
92 notional_ =
bond_.data().bondData().bondNotional();
93 maturity_ =
bond_.maturity();
98 XMLNode* dataNode = XMLUtils::getChildNode(node,
"AscotData");
99 QL_REQUIRE(dataNode,
"AscotData node not found");
102 bondData.
fromXML(XMLUtils::getChildNode(dataNode,
"ConvertibleBondData"));
105 optionData_.fromXML(XMLUtils::getChildNode(dataNode,
"OptionData"));
107 XMLNode* tmpNode = XMLUtils::getChildNode(dataNode,
"ReferenceSwapData");
108 QL_REQUIRE(tmpNode,
"ReferenceSwapData node not found");
109 XMLNode* legNode = XMLUtils::getChildNode(tmpNode,
"LegData");
110 QL_REQUIRE(legNode,
"LegData node not found");
111 fundingLegData_.fromXML(legNode);
115 XMLNode* node = Trade::toXML(doc);
117 XMLUtils::appendNode(node, dataNode);
120 XMLUtils::appendNode(dataNode, d.
toXML(doc));
121 XMLUtils::appendNode(dataNode, optionData_.toXML(doc));
124 XMLUtils::appendNode(dataNode, fundingDataNode);
125 XMLUtils::appendNode(fundingDataNode, fundingLegData_.toXML(doc));
Ascot (or Convertible Bond Option) trade data model and serialization.
const Leg & fundingLeg() const
ext::shared_ptr< ConvertibleBond2 > bond_
ext::shared_ptr< Exercise > exercise()
std::map< AssetClass, std::set< std::string > > underlyingIndices(const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
void fromXML(ore::data::XMLNode *node) override
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
Vanilla Instrument Wrapper.
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Exercise::Type parseExerciseType(const std::string &s)
Convert text to QuantLib::Exercise::Type.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.
#define DLOG(text)
Logging Macro (Level = Debug)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.