@@ -68,10 +68,18 @@ CommodityOptionStrip::CommodityOptionStrip(const Envelope& envelope, const LegDa
6868 const BarrierData& callBarrierData, const BarrierData& putBarrierData,
6969 const string& fxIndex, const bool isDigital, Real payoffPerUnit)
7070 : Trade(" CommodityOptionStrip" , envelope), legData_(legData), callPositions_(callPositions),
71- callStrikes_ (callStrikes), putPositions_(putPositions), putStrikes_(putStrikes), premium_(premium),
72- premiumCurrency_(premiumCurrency), premiumPayDate_(premiumPayDate), style_(style), settlement_(settlement),
71+ callStrikes_ (callStrikes), putPositions_(putPositions), putStrikes_(putStrikes),
72+ style_(style),
73+ settlement_(settlement),
7374 callBarrierData_(callBarrierData), putBarrierData_(putBarrierData), fxIndex_(fxIndex), isDigital_(isDigital),
74- unaryPayoff_(payoffPerUnit) {}
75+ unaryPayoff_(payoffPerUnit) {
76+ if (!QuantLib::close_enough (premium, 0.0 )) {
77+ QL_REQUIRE (premiumPayDate != Date (), " The premium is non-zero so its payment date needs to be provided" );
78+ QL_REQUIRE (!premiumCurrency.empty (), " The premium is non-zero so its currency needs to be provided" );
79+ premiumData_ = PremiumData (premium, premiumCurrency, premiumPayDate);
80+ }
81+ }
82+
7583
7684void CommodityOptionStrip::build (const boost::shared_ptr<EngineFactory>& engineFactory) {
7785
@@ -164,11 +172,7 @@ void CommodityOptionStrip::fromXML(XMLNode* node) {
164172 putBarrierData_.fromXML (n2);
165173 }
166174 }
167-
168- premium_ = XMLUtils::getChildValueAsDouble (stripNode, " PremiumAmount" , false );
169- premiumCurrency_ = XMLUtils::getChildValue (stripNode, " PremiumCurrency" , false );
170- premiumPayDate_ = parseDate (XMLUtils::getChildValue (stripNode, " PremiumPayDate" , false ));
171-
175+ premiumData_.fromXML (stripNode);
172176 style_ = " " ;
173177 if (XMLNode* n = XMLUtils::getChildNode (stripNode, " Style" ))
174178 style_ = XMLUtils::getNodeValue (n);
@@ -217,12 +221,8 @@ XMLNode* CommodityOptionStrip::toXML(XMLDocument& doc) {
217221 }
218222
219223 // These are all optional, really they should be grouped here
220-
221- if (premiumCurrency_ != " " && premiumPayDate_ != Date ()) {
222- XMLUtils::addChild (doc, stripNode, " PremiumAmount" , premium_);
223- XMLUtils::addChild (doc, stripNode, " PremiumCurrency" , premiumCurrency_);
224- XMLUtils::addChild (doc, stripNode, " PremiumPayDate" , to_string (premiumPayDate_));
225- }
224+ if (!premiumData_.premiumData ().empty ())
225+ XMLUtils::appendNode (stripNode, premiumData_.toXML (doc));
226226
227227 if (!style_.empty ())
228228 XMLUtils::addChild (doc, stripNode, " Style" , style_);
@@ -338,14 +338,11 @@ void CommodityOptionStrip::buildAPOs(const Leg& leg, const boost::shared_ptr<Eng
338338 additionalMultipliers.pop_back ();
339339
340340 // Possibly add a premium to the additional instruments and multipliers
341- // We expect here that the fee alrea minimal
342- // dy has the correct sign
343- if (!close (0.0 , premium_)) {
344- maturity_ = std::max (maturity_, addPremiums (additionalInstruments, additionalMultipliers, qlInstMult,
345- PremiumData (premium_, premiumCurrency_, premiumPayDate_), 1.0 ,
346- parseCurrency (legData_.currency ()), engineFactory, " " ));
347- }
341+ // We expect here that the fee already has the correct sign
348342
343+ maturity_ = std::max (maturity_, addPremiums (additionalInstruments, additionalMultipliers, qlInstMult, premiumData_,
344+ 1.0 , parseCurrency (legData_.currency ()), engineFactory, " " ));
345+
349346 // Create the Trade's instrument wrapper
350347 instrument_ =
351348 boost::make_shared<VanillaInstrument>(qlInst, qlInstMult, additionalInstruments, additionalMultipliers);
@@ -459,13 +456,10 @@ void CommodityOptionStrip::buildStandardOptions(const Leg& leg, const boost::sha
459456
460457 // Possibly add a premium to the additional instruments and multipliers
461458 // We expect here that the fee already has the correct sign
462- if (!close (0.0 , premium_)) {
463- maturity_ = std::max (maturity_, addPremiums (additionalInstruments, additionalMultipliers, qlInstMult,
464- PremiumData (premium_, premiumCurrency_, premiumPayDate_), 1.0 ,
465- parseCurrency (legData_.currency ()), engineFactory, " " ));
466- DLOG (" Option premium added for commodity option strip " << id ());
467- }
468-
459+ maturity_ = std::max (maturity_, addPremiums (additionalInstruments, additionalMultipliers, qlInstMult, premiumData_,
460+ 1.0 , parseCurrency (legData_.currency ()), engineFactory, " " ));
461+ DLOG (" Option premium added for commodity option strip " << id ());
462+
469463 // Create the Trade's instrument wrapper
470464 instrument_ =
471465 boost::make_shared<VanillaInstrument>(qlInst, qlInstMult, additionalInstruments, additionalMultipliers);
@@ -499,11 +493,6 @@ void CommodityOptionStrip::check(Size numberPeriods) const {
499493 << " ) should be 1 or equal to "
500494 << " the number of periods in the strip (" << numberPeriods << " )" );
501495 }
502-
503- if (!close (0.0 , premium_)) {
504- QL_REQUIRE (!premiumCurrency_.empty (), " The premium is non-zero so its currency needs to be provided" );
505- QL_REQUIRE (premiumPayDate_ != Date (), " The premium is non-zero so its payment date needs to be provided" );
506- }
507496}
508497
509498} // namespace data
0 commit comments