19#include <ql/event.hpp>
20#include <ql/exercise.hpp>
21#include <ql/settings.hpp>
24using QuantLib::BusinessDayConvention;
25using QuantLib::Calendar;
27using QuantLib::EuropeanExercise;
29using QuantLib::Natural;
31using QuantLib::Option;
32using QuantLib::PlainVanillaPayoff;
33using QuantLib::CashOrNothingPayoff;
34using QuantLib::PricingEngine;
36using QuantLib::Settings;
37using QuantLib::StrikedTypePayoff;
38using QuantLib::VanillaOption;
39using QuantLib::io::iso_date;
44void check(
const Date& expiryDate,
const Date& paymentDate,
bool automaticExercise,
45 const QuantLib::ext::shared_ptr<Index>& underlying,
bool exercised, Real priceAtExercise) {
47 using QuantLib::io::iso_date;
49 QL_REQUIRE(paymentDate >= expiryDate,
"Cash settled European option payment date ("
50 << iso_date(paymentDate)
51 <<
") must be greater than or equal to the expiry date ("
52 << iso_date(expiryDate) <<
")");
54 if (automaticExercise) {
55 QL_REQUIRE(underlying,
"Cash settled European option has automatic exercise so we need a valid underlying.");
59 QL_REQUIRE(priceAtExercise != Null<Real>(),
"Cash settled European option was exercised so we need "
60 <<
"a valid exercise price.");
69 const Date& paymentDate,
bool automaticExercise,
70 const QuantLib::ext::shared_ptr<Index>& underlying,
bool exercised,
72 : VanillaOption(
QuantLib::ext::make_shared<PlainVanillaPayoff>(type, strike),
73 QuantLib::ext::make_shared<EuropeanExercise>(expiryDate)),
74 paymentDate_(paymentDate), automaticExercise_(automaticExercise), underlying_(underlying), exercised_(false),
75 priceAtExercise_(Null<Real>()) {
77 init(exercised, priceAtExercise);
79 check(exercise_->lastDate(), paymentDate_, automaticExercise_, underlying_, exercised_, priceAtExercise_);
82CashSettledEuropeanOption::CashSettledEuropeanOption(Option::Type type, Real strike,
const Date& expiryDate,
83 Natural paymentLag,
const Calendar& paymentCalendar,
84 BusinessDayConvention paymentConvention,
bool automaticExercise,
85 const QuantLib::ext::shared_ptr<Index>& underlying,
bool exercised,
87 : VanillaOption(
QuantLib::ext::make_shared<PlainVanillaPayoff>(type, strike),
88 QuantLib::ext::make_shared<EuropeanExercise>(expiryDate)),
89 automaticExercise_(automaticExercise), underlying_(underlying), exercised_(false),
90 priceAtExercise_(Null<Real>()) {
92 init(exercised, priceAtExercise);
95 paymentDate_ = paymentCalendar.advance(expiryDate, paymentLag * QuantLib::Days, paymentConvention);
97 check(exercise_->lastDate(), paymentDate_, automaticExercise_, underlying_, exercised_, priceAtExercise_);
100CashSettledEuropeanOption::CashSettledEuropeanOption(Option::Type type, Real strike, Real cashPayoff,
101 const Date& expiryDate,
const Date& paymentDate,
102 bool automaticExercise,
const QuantLib::ext::shared_ptr<Index>& underlying,
103 bool exercised, Real priceAtExercise)
104 : VanillaOption(
QuantLib::ext::make_shared<CashOrNothingPayoff>(type, strike, cashPayoff),
105 QuantLib::ext::make_shared<EuropeanExercise>(expiryDate)),
106 paymentDate_(paymentDate), automaticExercise_(automaticExercise), underlying_(underlying), exercised_(false),
107 priceAtExercise_(Null<Real>()) {
109 init(exercised, priceAtExercise);
111 check(exercise_->lastDate(), paymentDate_, automaticExercise_, underlying_, exercised_, priceAtExercise_);
114CashSettledEuropeanOption::CashSettledEuropeanOption(Option::Type type, Real strike, Real cashPayoff,
115 const Date& expiryDate, Natural paymentLag,
116 const Calendar& paymentCalendar,
117 BusinessDayConvention paymentConvention,
bool automaticExercise,
118 const QuantLib::ext::shared_ptr<Index>& underlying,
bool exercised,
119 Real priceAtExercise)
120 : VanillaOption(
QuantLib::ext::make_shared<CashOrNothingPayoff>(type, strike, cashPayoff),
121 QuantLib::ext::make_shared<EuropeanExercise>(expiryDate)),
122 automaticExercise_(automaticExercise), underlying_(underlying), exercised_(false),
123 priceAtExercise_(Null<Real>()) {
125 init(exercised, priceAtExercise);
128 paymentDate_ = paymentCalendar.advance(expiryDate, paymentLag * QuantLib::Days, paymentConvention);
130 check(exercise_->lastDate(), paymentDate_, automaticExercise_, underlying_, exercised_, priceAtExercise_);
133void CashSettledEuropeanOption::init(
bool exercised, Real priceAtExercise) {
135 exercise(priceAtExercise);
137 if (automaticExercise_ && underlying_)
138 registerWith(underlying_);
141bool CashSettledEuropeanOption::isExpired()
const {
return QuantLib::detail::simple_event(paymentDate_).hasOccurred(); }
145 VanillaOption::setupArguments(args);
161void CashSettledEuropeanOption::exercise(Real priceAtExercise) {
162 QL_REQUIRE(priceAtExercise != Null<Real>(),
"Cannot exercise with a null price.");
163 QL_REQUIRE(Settings::instance().evaluationDate() >= exercise_->lastDate(),
164 "European option cannot be "
165 <<
"exercised before expiry date. Valuation date " << iso_date(Settings::instance().evaluationDate())
166 <<
" is before expiry date " << iso_date(exercise_->lastDate()) <<
".");
168 priceAtExercise_ = priceAtExercise;
172const Date& CashSettledEuropeanOption::paymentDate()
const {
return paymentDate_; }
174bool CashSettledEuropeanOption::automaticExercise()
const {
return automaticExercise_; }
176const QuantLib::ext::shared_ptr<Index>& CashSettledEuropeanOption::underlying()
const {
return underlying_; }
178bool CashSettledEuropeanOption::exercised()
const {
return exercised_; }
180Real CashSettledEuropeanOption::priceAtExercise()
const {
return priceAtExercise_; }
182void CashSettledEuropeanOption::arguments::validate()
const {
183 QuantLib::VanillaOption::arguments::validate();
184 check(exercise->lastDate(), paymentDate, automaticExercise, underlying, exercised, priceAtExercise);
cash settled european vanilla option.
QuantLib::Real priceAtExercise
QuantLib::Date paymentDate
QuantLib::ext::shared_ptr< QuantLib::Index > underlying
CashSettledEuropeanOption(QuantLib::Option::Type type, QuantLib::Real strike, const QuantLib::Date &expiryDate, const QuantLib::Date &paymentDate, bool automaticExercise, const QuantLib::ext::shared_ptr< QuantLib::Index > &underlying=nullptr, bool exercised=false, QuantLib::Real priceAtExercise=QuantLib::Null< QuantLib::Real >())
Constructor for cash settled vanilla European option.