|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | #include <ored/portfolio/builders/fxbarrieroption.hpp> |
18 | | - |
| 18 | +#include <ored/portfolio/fxkikobarrieroption.hpp> |
| 19 | +#include <ored/portfolio/genericbarrieroption.hpp> |
19 | 20 | namespace ore { |
20 | 21 | namespace data { |
| 22 | + |
| 23 | + |
| 24 | +QuantLib::ext::shared_ptr<ore::data::Trade> FxBarrierOptionScriptedEngineBuilder::build(const Trade* trade, const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory){ |
| 25 | + auto fxKiKoBarrierOption = dynamic_cast<const ore::data::FxKIKOBarrierOption*>(trade); |
| 26 | + |
| 27 | + QL_REQUIRE(fxKiKoBarrierOption != nullptr, |
| 28 | + "FxKIKOBarrierOptionScriptedEngineBuilder: internal error, could not " |
| 29 | + "cast to ore::data::FxKIKOBarrierOption. Contact dev."); |
| 30 | + std::string indexName = |
| 31 | + fxKiKoBarrierOption->fxIndex().empty() |
| 32 | + ? "GENERIC-" + fxKiKoBarrierOption->boughtCurrency() + "-" + fxKiKoBarrierOption->soldCurrency() |
| 33 | + : fxKiKoBarrierOption->fxIndex().substr(3); |
| 34 | + QuantLib::ext::shared_ptr<Underlying> underlying = QuantLib::ext::make_shared<FXUnderlying>("FX", indexName, 1.0); |
| 35 | + |
| 36 | + const auto& optionData = fxKiKoBarrierOption->option(); |
| 37 | + |
| 38 | + std::string startDate = fxKiKoBarrierOption->startDate(); |
| 39 | + std::string exerciseDate = optionData.exerciseDates().front(); |
| 40 | + |
| 41 | + ScheduleRules rule(startDate, exerciseDate, "1D", fxKiKoBarrierOption->calendar(), "Following", "Following", "Backward"); |
| 42 | + ScheduleData barrierMonitoringDates(rule); |
| 43 | + |
| 44 | + //! Empty transatlantic barrier |
| 45 | + auto transatlanticBarrier = BarrierData(); |
| 46 | + //! Observation date for schedule monitoring dates only at the end |
| 47 | + |
| 48 | + std::string domesticCurrency = fxKiKoBarrierOption->soldCurrency(); |
| 49 | + |
| 50 | + Date expiryDate = parseDate(exerciseDate); |
| 51 | + Date paymentDate = expiryDate; |
| 52 | + const QuantLib::ext::optional<OptionPaymentData>& opd = optionData.paymentData(); |
| 53 | + if (opd) { |
| 54 | + if (opd->rulesBased()) { |
| 55 | + const Calendar& cal = opd->calendar(); |
| 56 | + QL_REQUIRE(cal != Calendar(), "Need a non-empty calendar for rules based payment date."); |
| 57 | + paymentDate = cal.advance(expiryDate, opd->lag(), Days, opd->convention()); |
| 58 | + } else { |
| 59 | + const vector<Date>& dates = opd->dates(); |
| 60 | + QL_REQUIRE(dates.size() == 1, "Need exactly one payment date for cash settled European option."); |
| 61 | + paymentDate = dates[0]; |
| 62 | + } |
| 63 | + QL_REQUIRE(paymentDate >= expiryDate, "Payment date must be greater than or equal to expiry date."); |
| 64 | + } |
| 65 | + auto qty = fxKiKoBarrierOption->boughtAmount(); |
| 66 | + auto strike = fxKiKoBarrierOption->strike(); |
| 67 | + std::vector<BarrierData> barriers = fxKiKoBarrierOption->barriers(); |
| 68 | + auto barrierOption = QuantLib::ext::make_shared<GenericBarrierOption>( |
| 69 | + underlying, optionData, barriers, barrierMonitoringDates, transatlanticBarrier, domesticCurrency, |
| 70 | + to_string(paymentDate), to_string(qty), to_string(strike), "", ""); |
| 71 | + |
| 72 | + barrierOption->build(engineFactory); |
| 73 | + return barrierOption; |
| 74 | +} |
21 | 75 | } // namespace data |
22 | 76 | } // namespace ore |
0 commit comments