Build QuantLib/QuantExt instrument, link pricing engine.
33 {
34
35
37 additionalData_[
"isdaBaseProduct"] = string(settlement_ ==
"Cash" ?
"NDF" :
"Forward");
40
47
48
49
50
53
56
58 } else {
61 "Settlement currency must be either " << boughtCcy.code() << " or " << soldCcy.code() << ".");
62 }
63
65
66
67
68 if (settlement_ == "Physical") {
71 } else {
72
75 }
76
78
79
82 Natural conventionalLag = 0;
83 Calendar conventionalCalendar = NullCalendar();
84 BusinessDayConvention conventionalBdc = Unadjusted;
85 if (!
fxIndex_.empty() && settlement_ ==
"Cash") {
86 std::tie(conventionalLag, conventionalCalendar, conventionalBdc) =
88 }
91 paymentLag = conventionalLag;
92 else
94 Period payLag = boost::apply_visitor(PaymentLagPeriod(), paymentLag);
96 BusinessDayConvention payConvention =
99 } else {
101 QL_REQUIRE(
payDate >=
maturityDate,
"FX Forward settlement date should equal or exceed the maturity date.");
102 }
103
106 QuantLib::ext::shared_ptr<QuantExt::FxIndex>
fxIndex;
107
109 if (settlement_ == "Cash") {
110
111
112
114 Currency nonPayCcy =
payCcy == boughtCcy ? soldCcy : boughtCcy;
116 engineFactory->configuration(MarketContext::pricing));
117
118
119
123 }
124 } else {
126 "FX settlement index must be specified for non-deliverable forward if value date ("
128 }
129 }
130 if (fixingDate != Date()) {
133 else
135 }
136
137 QL_REQUIRE(
tradeActions().empty(),
"TradeActions not supported for FxForward");
138
139 DLOG(
"Build FxForward with maturity date " << QuantLib::io::iso_date(
maturityDate) <<
" and pay date "
140 << QuantLib::io::iso_date(
payDate));
141
142
143 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder(tradeType_);
144 QL_REQUIRE(builder, "No builder found for " << tradeType_);
145 QuantLib::ext::shared_ptr<FxForwardEngineBuilderBase> fxBuilder =
146 QuantLib::ext::dynamic_pointer_cast<FxForwardEngineBuilderBase>(builder);
147
148 string tmp = fxBuilder->engineParameter("includeSettlementDateFlows", {}, false, "");
150
151 QuantLib::ext::shared_ptr<QuantLib::Instrument>
instrument =
152 QuantLib::ext::make_shared<QuantExt::FxForward>(boughtAmount_, boughtCcy, soldAmount_, soldCcy,
maturityDate,
false,
154 includeSettlementDateFlows_);
155 instrument_.reset(
new VanillaInstrument(instrument));
156
157
158 instrument_->qlInstrument()->setPricingEngine(fxBuilder->engine(boughtCcy, soldCcy));
160
161
162 legs_ = {{QuantLib::ext::make_shared<SimpleCashFlow>(boughtAmount_,
payDate)},
163 {QuantLib::ext::make_shared<SimpleCashFlow>(soldAmount_,
payDate)}};
166}
bool includeSettlementDateFlows_
void addFixingDate(const QuantLib::Date &fixingDate, const std::string &indexName, const QuantLib::Date &payDate=Date::maxDate(), const bool alwaysAddIfPaysOnSettlement=false, const bool mandatoryFixing=true)
TradeActions & tradeActions()
Set the trade actions.
std::vector< bool > legPayers_
std::vector< string > legCurrencies_
std::vector< QuantLib::Leg > legs_
void setSensitivityTemplate(const EngineBuilder &builder)
RequiredFixings requiredFixings_
const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument() const
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
std::map< std::string, boost::any > additionalData_
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
bool parseBool(const string &s)
Convert text to bool.
PaymentLag parsePaymentLag(const string &s)
Convert text to PaymentLag.
#define DLOG(text)
Logging Macro (Level = Debug)
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
std::tuple< Natural, Calendar, BusinessDayConvention > getFxIndexConventions(const string &index)
boost::variant< QuantLib::Period, QuantLib::Natural > PaymentLag
QuantLib::ext::shared_ptr< QuantExt::FxIndex > buildFxIndex(const string &fxIndex, const string &domestic, const string &foreign, const QuantLib::ext::shared_ptr< Market > &market, const string &configuration, bool useXbsCurves)