Skip to content

Commit fd8b957

Browse files
committed
QPR-11988 use delegated builder for script
1 parent fd5235c commit fd8b957

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

OREData/ored/portfolio/fxeuropeanbarrieroption.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
1717
*/
1818

19-
#include <boost/make_shared.hpp>
19+
#include <ored/portfolio/builders/fxeuropeanbarrieroption.hpp>
2020
#include <ored/portfolio/builders/fxdigitaloption.hpp>
2121
#include <ored/portfolio/builders/fxoption.hpp>
2222
#include <ored/portfolio/enginefactory.hpp>
@@ -63,6 +63,23 @@ void FxEuropeanBarrierOption::build(const QuantLib::ext::shared_ptr<EngineFactor
6363
Real rebate = barrier_.rebate();
6464
QL_REQUIRE(rebate >= 0, "Rebate must be non-negative");
6565

66+
auto fxEuropeanBarrierOptionBuilder =
67+
QuantLib::ext::dynamic_pointer_cast<FxEuropeanBarrierOptionEngineBuilder>(engineFactory->builder(tradeType_));
68+
if (fxEuropeanBarrierOptionBuilder) {
69+
// We have a delegating builder for this trade
70+
auto delegatingBuilderTrade_ = fxEuropeanBarrierOptionBuilder->build(this, engineFactory);
71+
instrument_ = delegatingBuilderTrade_->instrument();
72+
maturity_ = delegatingBuilderTrade_->maturity();
73+
npvCurrency_ = delegatingBuilderTrade_->npvCurrency();
74+
additionalData_ = delegatingBuilderTrade_->additionalData();
75+
requiredFixings_ = delegatingBuilderTrade_->requiredFixings();
76+
setSensitivityTemplate(delegatingBuilderTrade_->sensitivityTemplate());
77+
addProductModelEngine(delegatingBuilderTrade_->productModelEngine());
78+
79+
// notional and notional currency are defined in overriden methods!
80+
81+
return;
82+
}
6683
// Replicate the payoff of European Barrier Option (with strike K and barrier B) using combinations of options
6784

6885
// Call
@@ -418,5 +435,14 @@ XMLNode* FxEuropeanBarrierOption::toXML(XMLDocument& doc) const {
418435
Real FxEuropeanBarrierOption::strike() const {
419436
return soldAmount_ / boughtAmount_;
420437
}
438+
439+
QuantLib::Real FxEuropeanBarrierOption::notional() const {
440+
return delegatingBuilderTrade_ != nullptr ? delegatingBuilderTrade_->notional() : Trade::notional();
441+
}
442+
443+
string FxEuropeanBarrierOption::notionalCurrency() const {
444+
return delegatingBuilderTrade_ != nullptr ? delegatingBuilderTrade_->notionalCurrency() : Trade::notionalCurrency();
445+
}
446+
421447
} // namespace data
422448
} // namespace ore

OREData/ored/portfolio/fxeuropeanbarrieroption.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class FxEuropeanBarrierOption : public FxSingleAssetDerivative {
5252

5353
//! Build QuantLib/QuantExt instrument, link pricing engine
5454
void build(const QuantLib::ext::shared_ptr<EngineFactory>&) override;
55+
QuantLib::Real notional() const override;
56+
string notionalCurrency() const override;
5557

5658
//! \name Inspectors
5759
//@{
@@ -78,6 +80,7 @@ class FxEuropeanBarrierOption : public FxSingleAssetDerivative {
7880
double soldAmount_;
7981
//! If the option has automatic exercise (i.e. cash settled after maturity), need an FX index for settlement.
8082
std::string fxIndex_;
83+
QuantLib::ext::shared_ptr<Trade> delegatingBuilderTrade_;
8184
};
8285
} // namespace data
8386
} // namespace oreplus

0 commit comments

Comments
 (0)