Skip to content

Commit 291e286

Browse files
author
jenkins
committed
git subrepo pull (merge) ore
subrepo: subdir: "ore" merged: "114603f2b4" upstream: origin: "git@gitlab.acadiasoft.net:qs/ore.git" branch: "master" commit: "868dbf458e" git-subrepo: version: "0.4.6" origin: "https://github.com/ingydotnet/git-subrepo" commit: "73a0129"
2 parents 0854031 + 868dbf4 commit 291e286

45 files changed

Lines changed: 468 additions & 406 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

OREData/ored/configuration/equitycurveconfig.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,5 @@ EquityCurveConfig::Type parseEquityCurveConfigType(const std::string& str) {
143143
QL_FAIL("Invalid EquityCurveConfig::Type " << str);
144144
}
145145

146-
std::ostream& operator<<(std::ostream& out, Exercise::Type t) {
147-
switch (t) {
148-
case Exercise::American:
149-
return out << "American";
150-
case Exercise::European:
151-
return out << "European";
152-
default:
153-
QL_FAIL("invalid Exercise::Type(" << int(t) << ")");
154-
}
155-
}
156-
157146
} // namespace data
158147
} // namespace ore

OREData/ored/configuration/equitycurveconfig.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ class EquityCurveConfig : public CurveConfig {
118118
};
119119

120120
std::ostream& operator<<(std::ostream& out, EquityCurveConfig::Type t);
121-
std::ostream& operator<<(std::ostream& out, QuantLib::Exercise::Type t);
122121

123122
EquityCurveConfig::Type parseEquityCurveConfigType(const std::string& str);
124123

OREData/ored/configuration/volatilityconfig.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void VolatilityConfig::fromXMLNode(XMLNode* node) {
4646
}
4747

4848
void VolatilityConfig::toXMLNode(XMLDocument& doc, XMLNode* node) const {
49-
XMLUtils::addAttribute(doc, node, "priority", to_string(priority_));
49+
XMLUtils::addAttribute(doc, node, "priority", std::to_string(priority_));
5050
if (!calendarStr_.empty())
5151
XMLUtils::addChild(doc, node, "Calendar", calendarStr_);
5252
}
@@ -126,7 +126,7 @@ void QuoteBasedVolatilityConfig::toBaseNode(XMLDocument& doc, XMLNode* node) con
126126
// Check first for premium
127127
if (quoteType_ == MarketDatum::QuoteType::PRICE) {
128128
XMLUtils::addChild(doc, node, "QuoteType", "Premium");
129-
XMLUtils::addChild(doc, node, "ExerciseType", to_string(exerciseType_));
129+
XMLUtils::addChild(doc, node, "ExerciseType", ore::data::to_string(exerciseType_));
130130
return;
131131
}
132132

OREData/ored/portfolio/barrieroption.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ void BarrierOption::build(const QuantLib::ext::shared_ptr<EngineFactory>& engine
7373
Real rebate = barrier_.rebate() / tradeMultiplier();
7474
QL_REQUIRE(rebate >= 0, "rebate must be non-negative");
7575

76+
77+
// set the maturity
78+
maturity_ = std::max(option_.premiumData().latestPremiumDate(), payDate);
79+
7680
// fx base
7781
// Payoff
7882
Option::Type type = parseOptionType(option_.callPut());
@@ -164,12 +168,8 @@ void BarrierOption::build(const QuantLib::ext::shared_ptr<EngineFactory>& engine
164168

165169
// Add additional premium payments
166170
Real bsInd = (positionType == QuantLib::Position::Long ? 1.0 : -1.0);
167-
Date lastPremiumDate =
168-
addPremiums(additionalInstruments, additionalMultipliers, bsInd * tradeMultiplier(), option_.premiumData(),
169-
-bsInd, tradeCurrency(), engineFactory, engineFactory->configuration(MarketContext::pricing));
170-
171-
// set the maturity
172-
maturity_ = std::max(lastPremiumDate, payDate);
171+
addPremiums(additionalInstruments, additionalMultipliers, bsInd * tradeMultiplier(), option_.premiumData(), -bsInd,
172+
tradeCurrency(), engineFactory, engineFactory->configuration(MarketContext::pricing));
173173
}
174174

175175

@@ -217,19 +217,22 @@ void FxOptionWithBarrier::build(const QuantLib::ext::shared_ptr<ore::data::Engin
217217
additionalData_["isdaSubProduct"] = string("Barrier");
218218
additionalData_["isdaTransaction"] = string("");
219219

220-
spotQuote_ = ef->market()->fxSpot(boughtCurrency_ + soldCurrency_);
221-
fxIndex_ = ef->market()->fxIndex(indexFixingName(), ef->configuration(MarketContext::pricing)).currentLink();
220+
additionalData_["boughAmount"] = boughtAmount_;
221+
additionalData_["boughtCurrency"] = boughtCurrency_;
222+
additionalData_["soldAmount"] = soldAmount_;
223+
additionalData_["soldCurrency"] = soldCurrency_;
222224

223-
BarrierOption::build(ef);
224-
225225
npvCurrency_ = soldCurrency_; // sold is the domestic
226226
notional_ = soldAmount_;
227227
notionalCurrency_ = soldCurrency_; // sold is the domestic
228228

229-
additionalData_["boughAmount"] = boughtAmount_;
230-
additionalData_["boughtCurrency"] = boughtCurrency_;
231-
additionalData_["soldAmount"] = soldAmount_;
232-
additionalData_["soldCurrency"] = soldCurrency_;
229+
QuantLib::Date expiryDate = parseDate(option().exerciseDates().front());
230+
maturity_ = std::max(option().premiumData().latestPremiumDate(), expiryDate);
231+
232+
spotQuote_ = ef->market()->fxSpot(boughtCurrency_ + soldCurrency_);
233+
fxIndex_ = ef->market()->fxIndex(indexFixingName(), ef->configuration(MarketContext::pricing)).currentLink();
234+
235+
BarrierOption::build(ef);
233236
}
234237

235238
void FxOptionWithBarrier::additionalFromXml(XMLNode* node) {
@@ -257,9 +260,12 @@ void EquityOptionWithBarrier::build(const QuantLib::ext::shared_ptr<ore::data::E
257260
additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
258261
additionalData_["isdaTransaction"] = string("");
259262

260-
eqIndex_ = ef->market()->equityCurve(equityName()).currentLink();
263+
additionalData_["quantity"] = quantity_;
264+
additionalData_["strike"] = tradeStrike_.value();
265+
additionalData_["strikeCurrency"] = tradeStrike_.currency();
261266

262-
BarrierOption::build(ef);
267+
QuantLib::Date expiryDate = parseDate(option().exerciseDates().front());
268+
maturity_ = std::max(option().premiumData().latestPremiumDate(), expiryDate);
263269

264270
if (tradeStrike_.currency().empty())
265271
tradeStrike_.setCurrency(currencyStr_);
@@ -271,9 +277,9 @@ void EquityOptionWithBarrier::build(const QuantLib::ext::shared_ptr<ore::data::E
271277
notional_ = tradeStrike_.value() * quantity_;
272278
notionalCurrency_ = parseCurrencyWithMinors(tradeStrike_.currency()).code();
273279

274-
additionalData_["quantity"] = quantity_;
275-
additionalData_["strike"] = tradeStrike_.value();
276-
additionalData_["strikeCurrency"] = tradeStrike_.currency();
280+
eqIndex_ = ef->market()->equityCurve(equityName()).currentLink();
281+
282+
BarrierOption::build(ef);
277283
}
278284

279285
void EquityOptionWithBarrier::additionalFromXml(XMLNode* node) {

OREData/ored/portfolio/bondoption.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,17 @@ void BondOption::build(const QuantLib::ext::shared_ptr<EngineFactory>& engineFac
6565

6666
// FIXME this won't work for zero bonds (but their implementation is incomplete anyhow, see bond.cpp)
6767
underlying_ = QuantLib::ext::make_shared<ore::data::Bond>(Envelope(), bondData_);
68+
6869
underlying_->build(engineFactory);
70+
71+
legs_ = underlying_->legs();
72+
legCurrencies_ = underlying_->legCurrencies();
73+
legPayers_ = std::vector<bool>(legs_.size(), false); // always receive (long option view)
74+
npvCurrency_ = underlying_->bondData().currency();
75+
notional_ = underlying_->notional() * bondData_.bondNotional();
76+
notionalCurrency_ = underlying_->bondData().currency();
77+
maturity_ = std::max(optionData_.premiumData().latestPremiumDate(), underlying_->maturity());
78+
6979
auto qlBondInstr = QuantLib::ext::dynamic_pointer_cast<QuantLib::Bond>(underlying_->instrument()->qlInstrument());
7080
QL_REQUIRE(qlBondInstr, "BondOption::build(): could not cast to QuantLib::Bond");
7181
for (auto const p : underlying_->legPayers()) {
@@ -126,20 +136,12 @@ void BondOption::build(const QuantLib::ext::shared_ptr<EngineFactory>& engineFac
126136

127137
std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
128138
std::vector<Real> additionalMultipliers;
129-
Date lastPremiumDate = addPremiums(additionalInstruments, additionalMultipliers, multiplier,
130-
optionData_.premiumData(), multiplier > 0.0 ? -1.0 : 1.0, currency,
131-
engineFactory, bondOptionBuilder->configuration(MarketContext::pricing));
139+
addPremiums(additionalInstruments, additionalMultipliers, multiplier, optionData_.premiumData(),
140+
multiplier > 0.0 ? -1.0 : 1.0, currency, engineFactory,
141+
bondOptionBuilder->configuration(MarketContext::pricing));
132142

133143
instrument_.reset(new VanillaInstrument(bondoption, multiplier, additionalInstruments, additionalMultipliers));
134-
135-
legs_ = underlying_->legs();
136-
legCurrencies_ = underlying_->legCurrencies();
137-
legPayers_ = std::vector<bool>(legs_.size(), false); // always receive (long option view)
138-
npvCurrency_ = underlying_->bondData().currency();
139-
maturity_ = std::max(lastPremiumDate, underlying_->maturity());
140-
notional_ = underlying_->notional() * bondData_.bondNotional();
141-
notionalCurrency_ = underlying_->bondData().currency();
142-
144+
143145
// the required fixings are (at most) those of the underlying
144146
requiredFixings_ = underlying_->requiredFixings();
145147
}

OREData/ored/portfolio/bondtotalreturnswap.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ void BondTRS::build(const QuantLib::ext::shared_ptr<EngineFactory>& engineFactor
7676
"if funding leg ccy (" << fundingLegData_.currency() << ") != bond ccy (" << bondData_.currency()
7777
<< "), a fx index must be given");
7878

79+
npvCurrency_ = fundingLegData_.currency();
80+
notionalCurrency_ = bondData_.currency();
81+
7982
// build return leg valuation and payment schedule
8083
DLOG("build valuation and payment dates vectors");
8184

@@ -194,12 +197,9 @@ void BondTRS::build(const QuantLib::ext::shared_ptr<EngineFactory>& engineFactor
194197
bondTRS->setPricingEngine(trsBondBuilder->engine(fundingLegData_.currency()));
195198
setSensitivityTemplate(*trsBondBuilder);
196199
instrument_.reset(new VanillaInstrument(bondTRS));
197-
198-
npvCurrency_ = fundingLegData_.currency();
199200
// maturity_ = std::max(valuationDates.back(), paymentDates.back());
200201
maturity_ = bondIndex->bond()->maturityDate();
201202
notional_ = bondIndex->bond()->notional() * bondData_.bondNotional();
202-
notionalCurrency_ = bondData_.currency();
203203

204204
// cashflows will be generated as additional results in the pricing engine
205205

OREData/ored/portfolio/cliquetoption.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ void CliquetOption::build(const QuantLib::ext::shared_ptr<EngineFactory>& engine
113113
}
114114

115115
additionalData_["notional"] = cliquetNotional_;
116-
additionalData_["currency"] = currency_;
117116
}
118117

119118
void CliquetOption::fromXML(XMLNode* node) {

OREData/ored/portfolio/commodityapo.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ void CommodityAveragePriceOption::build(const QuantLib::ext::shared_ptr<EngineFa
7878
QL_REQUIRE(spread_ < strike_ || QuantLib::close_enough(spread_, strike_),
7979
"Spread (" << spread_ << ") should be less than strike (" << strike_ << ").");
8080

81+
additionalData_["quantity"] = quantity_;
82+
additionalData_["strike"] = strike_;
83+
additionalData_["strikeCurrency"] = currency_;
84+
85+
// Notional = effective_quantity * effective_strike = (G x Q) x ((K - s) / G) = Q x (K - s)
86+
notional_ = quantity_ * (strike_ - spread_);
87+
notionalCurrency_ = npvCurrency_ = currency_;
88+
8189
// Allow exercise dates not to be specified for an APO. In this case, the exercise date is deduced below when
8290
// building the APO or a standard option.
8391
Date exDate;
@@ -95,12 +103,7 @@ void CommodityAveragePriceOption::build(const QuantLib::ext::shared_ptr<EngineFa
95103
// can then use a standard commodity option pricer below.
96104
Leg leg = buildLeg(engineFactory, configuration);
97105

98-
// Notional = effective_quantity * effective_strike = (G x Q) x ((K - s) / G) = Q x (K - s)
99-
notional_ = quantity_ * (strike_ - spread_);
100-
notionalCurrency_ = currency_;
101-
102106
// Based on allAveraging_ flag, set up a standard or averaging commodity option
103-
npvCurrency_ = currency_;
104107
if (allAveraging_) {
105108
buildStandardOption(engineFactory, leg, exDate);
106109
} else {
@@ -111,10 +114,6 @@ void CommodityAveragePriceOption::build(const QuantLib::ext::shared_ptr<EngineFa
111114
legs_.push_back(leg);
112115
legPayers_.push_back(false);
113116
legCurrencies_.push_back(currency_);
114-
115-
additionalData_["quantity"] = quantity_;
116-
additionalData_["strike"] = strike_;
117-
additionalData_["strikeCurrency"] = currency_;
118117
}
119118

120119
std::map<AssetClass, std::set<std::string>> CommodityAveragePriceOption::underlyingIndices(
@@ -312,6 +311,10 @@ void CommodityAveragePriceOption::buildApo(const QuantLib::ext::shared_ptr<Engin
312311
QL_REQUIRE(leg.size() == 1, "Single flow expected but found " << leg.size());
313312
auto apoFlow = QuantLib::ext::dynamic_pointer_cast<CommodityIndexedAverageCashFlow>(leg[0]);
314313
QL_REQUIRE(apoFlow, "Expected a cashflow of type CommodityIndexedAverageCashFlow");
314+
315+
// Populate relevant Trade members
316+
maturity_ = std::max(optionData_.premiumData().latestPremiumDate(), apoFlow->date());
317+
315318
Date lastApoFixingDate = apoFlow->indices().rbegin()->first;
316319

317320
// If exercise date is given use it. If not given, take the cashflow's last pricing date.
@@ -399,15 +402,12 @@ void CommodityAveragePriceOption::buildApo(const QuantLib::ext::shared_ptr<Engin
399402
// Take care of fees
400403
vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
401404
vector<Real> additionalMultipliers;
402-
Date lastPremiumDate = addPremiums(additionalInstruments, additionalMultipliers, multiplier,
403-
optionData_.premiumData(), positionType == Position::Long ? -1.0 : 1.0, ccy,
404-
engineFactory, engineBuilder->configuration(MarketContext::pricing));
405+
addPremiums(additionalInstruments, additionalMultipliers, multiplier, optionData_.premiumData(),
406+
positionType == Position::Long ? -1.0 : 1.0, ccy, engineFactory,
407+
engineBuilder->configuration(MarketContext::pricing));
405408

406409
// Populate instrument wrapper
407410
instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(apo, multiplier, additionalInstruments, additionalMultipliers);
408-
409-
// Populate relevant Trade members
410-
maturity_ = std::max(lastPremiumDate, apoFlow->date());
411411
}
412412

413413
} // namespace data

OREData/ored/portfolio/commodityforward.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,24 @@ void CommodityForward::build(const QuantLib::ext::shared_ptr<EngineFactory>& eng
7676
// Create the underlying commodity index for the forward
7777
const QuantLib::ext::shared_ptr<Market>& market = engineFactory->market();
7878
QuantLib::ext::shared_ptr<QuantExt::FxIndex> fxIndex = nullptr;
79-
auto index = *market->commodityIndex(commodityName_, engineFactory->configuration(MarketContext::pricing));
79+
80+
npvCurrency_ = fixingDate_ == Date() ? currency_ : payCcy_;
81+
82+
// notional_ = strike_ * quantity_;
83+
notional_ = strike_ * quantity_;
84+
notionalCurrency_ = currency_;
85+
86+
additionalData_["quantity"] = quantity_;
87+
additionalData_["strike"] = strike_;
88+
additionalData_["strikeCurrency"] = currency_;
89+
if (fixingDate_ != Date()) {
90+
additionalData_["settlementCurrency"] = payCcy_;
91+
additionalData_["fixingDate"] = fixingDate_;
92+
additionalData_["fxIndex"] = fxIndex;
93+
}
94+
8095
maturity_ = parseDate(maturityDate_);
96+
auto index = *market->commodityIndex(commodityName_, engineFactory->configuration(MarketContext::pricing));
8197
bool isFutureAccordingToConventions = InstrumentConventions::instance().conventions()->has(commodityName_, Convention::Type::CommodityFuture);
8298

8399
// adjust the maturity date if not a valid fixing date for the index
@@ -104,7 +120,7 @@ void CommodityForward::build(const QuantLib::ext::shared_ptr<EngineFactory>& eng
104120
Date paymentDate = paymentDate_;
105121
bool physicallySettled = true;
106122
if (physicallySettled_ && !(*physicallySettled_)) {
107-
// If cash settled and given a payment date that is not greater than the maturity date, set it equal to the
123+
// If cash settled and given a payment date that is not greater than the maturity date, set it equal to the
108124
// maturity date and log a warning to continue processing.
109125
physicallySettled = false;
110126
if (paymentDate_ != Date() && paymentDate_ < maturity_) {
@@ -152,20 +168,6 @@ void CommodityForward::build(const QuantLib::ext::shared_ptr<EngineFactory>& eng
152168

153169
// set up other Trade details
154170
instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(commodityForward);
155-
npvCurrency_ = fixingDate_==Date() ? currency_ : payCcy_;
156-
157-
// notional_ = strike_ * quantity_;
158-
notional_ = strike_ * quantity_;
159-
notionalCurrency_ = currency_;
160-
161-
additionalData_["quantity"] = quantity_;
162-
additionalData_["strike"] = strike_;
163-
additionalData_["strikeCurrency"] = currency_;
164-
if(fixingDate_ != Date()) {
165-
additionalData_["settlementCurrency"] = payCcy_;
166-
additionalData_["fixingDate"] = fixingDate_;
167-
additionalData_["fxIndex"] = fxIndex;
168-
}
169171
}
170172

171173
Real CommodityForward::notional() const { return notional_; }

OREData/ored/portfolio/commodityoption.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,20 @@ void CommodityOption::build(const QuantLib::ext::shared_ptr<EngineFactory>& engi
5757
// skip the transaction level mapping for now
5858
additionalData_["isdaTransaction"] = std::string("");
5959

60+
additionalData_["quantity"] = quantity_;
61+
additionalData_["strike"] = strike_.value();
62+
additionalData_["strikeCurrency"] = currency_;
63+
6064
// Checks
6165
QL_REQUIRE((strike_.value() > 0) || close_enough(strike_.value(),0.0), "Commodity option requires a non-negative strike");
6266
if (close_enough(strike_.value(), 0.0)) {
6367
strike_.setValue(0.0);
6468
}
6569

70+
// This is called in VanillaOptionTrade::build(), but we want to call it first here,
71+
// in case the build fails before it reaches VanillaOptionTrade::build()
72+
VanillaOptionTrade::setNotionalAndCurrencies();
73+
6674
// Populate the index_ in case the option is automatic exercise.
6775
// Intentionally use null calendar because we will ask for index value on the expiry date without adjustment.
6876
const QuantLib::ext::shared_ptr<Market>& market = engineFactory->market();
@@ -105,10 +113,6 @@ void CommodityOption::build(const QuantLib::ext::shared_ptr<EngineFactory>& engi
105113
<< " and strike " << strike_.value() << " is "
106114
<< market->commodityVolatility(assetName_)->blackVol(expiryDate_, strike_.value()));
107115
}
108-
109-
additionalData_["quantity"] = quantity_;
110-
additionalData_["strike"] = strike_.value();
111-
additionalData_["strikeCurrency"] = currency_;
112116
}
113117

114118
std::map<AssetClass, std::set<std::string>>

0 commit comments

Comments
 (0)