|
| 1 | +/* |
| 2 | + Copyright (C) 2026 Quaternion Risk Management Ltd |
| 3 | + All rights reserved. |
| 4 | +
|
| 5 | + This file is part of ORE, a free-software/open-source library |
| 6 | + for transparent pricing and risk analysis - http://opensourcerisk.org |
| 7 | +
|
| 8 | + ORE is free software: you can redistribute it and/or modify it |
| 9 | + under the terms of the Modified BSD License. You should have received a |
| 10 | + copy of the license along with this program. |
| 11 | + The license is also available online at <http://opensourcerisk.org> |
| 12 | + |
| 13 | + This program is distributed on the basis that it will form a useful |
| 14 | + contribution to risk analytics and model standardisation, but WITHOUT |
| 15 | + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | + FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. |
| 17 | + */ |
| 18 | + |
| 19 | +#include <ored/portfolio/builder/fxeuropeanbarrieroption.hpp> |
| 20 | +#include <ored/portfolio/fxeuropeanbarrieroption.hpp> |
| 21 | +#include <ored/portfolio/genericbarrieroption.hpp> |
| 22 | +#include <ored/portfolio/underlying.hpp> |
| 23 | + |
| 24 | +namespace ore { |
| 25 | +namespace data { |
| 26 | + |
| 27 | +QuantLib::ext::shared_ptr<ore::data::Trade> |
| 28 | +FxEuropeanBarrierOptionEngineBuilder::build(const Trade* trade, const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory) { |
| 29 | + |
| 30 | + auto fxEuropeanBarrierOption = dynamic_cast<const ore::data::FxEuropeanBarrierOption*>(trade); |
| 31 | + |
| 32 | + QL_REQUIRE( |
| 33 | + fxEuropeanBarrierOption != nullptr, |
| 34 | + "FxEuropeanBarrierOptionEngineBuilder: internal error, could not cast to ore::data::FxEuropeanBarrierOption. Contact dev."); |
| 35 | + |
| 36 | + auto underlying = Quantib::ext::make_shared<FXUnderlying>("FX", fxEuropeanBarrierOption->fxIndex(), 1.0); |
| 37 | + |
| 38 | + auto optionData = fxEuropeanBarrierOption->optionData(); |
| 39 | + |
| 40 | + std::string exerciseDate = optionData->exerciseDates().begin(); |
| 41 | + ScheduleDates monitoringDates("NullCalendar", "", "0D", {exerciseDate} ); |
| 42 | + ScheduleData barrierMonitoringDates(monitoringDates); |
| 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 = fxEuropeanBarrierOption->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 = fxEuropeanBarrierOption->boughtAmount(); |
| 66 | + auto strike = fxEuropeanBarrierOption->strike(); |
| 67 | + |
| 68 | + auto barrierOption = QuantLib::ext::make_shared<GenericBarrierOption>( |
| 69 | + underlying, optionData, {fxEuropeanBarrierOption->barrierData()}, barrierMonitoringDates, transatlanticBarrier, |
| 70 | + domesticCurrency, to_string(paymentDate), to_string(qty), to_string(strike), "", ""); |
| 71 | + |
| 72 | + barrierOption->build(engineFactory); |
| 73 | + return barrierOption; |
| 74 | +} |
| 75 | + |
| 76 | +} // namespace data |
| 77 | +} // namespace oreplus |
0 commit comments