Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
multilegoption.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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
20
21#include <ql/cashflows/floatingratecoupon.hpp>
22
23namespace QuantExt {
24
25MultiLegOption::MultiLegOption(const std::vector<Leg>& legs, const std::vector<bool>& payer,
26 const std::vector<Currency>& currency, const QuantLib::ext::shared_ptr<Exercise>& exercise,
27 const Settlement::Type settlementType, Settlement::Method settlementMethod)
28 : legs_(legs), payer_(payer), currency_(currency), exercise_(exercise), settlementType_(settlementType),
29 settlementMethod_(settlementMethod) {
30
31 QL_REQUIRE(legs_.size() > 0, "MultiLegOption: No legs are given");
32 QL_REQUIRE(payer_.size() == legs_.size(),
33 "MultiLegOption: payer size (" << payer.size() << ") does not match legs size (" << legs_.size() << ")");
34 QL_REQUIRE(currency_.size() == legs_.size(), "MultiLegOption: currency size (" << currency_.size()
35 << ") does not match legs size ("
36 << legs_.size() << ")");
37 // find maturity date
38
39 maturity_ = Date::minDate();
40 for (auto const& l : legs_) {
41 if (!l.empty())
42 maturity_ = std::max(maturity_, l.back()->date());
43 }
44
45 // register with underlying cashflows
46
47 for (auto const& l : legs_) {
48 for (auto const& c : l) {
49 registerWith(c);
50 if (auto lazy = QuantLib::ext::dynamic_pointer_cast<LazyObject>(c))
51 lazy->alwaysForwardNotifications();
52 }
53 }
54
55} // MultiLegOption
56
58 for (auto& l : legs_) {
59 for (auto& c : l) {
60 if (auto lazy = QuantLib::ext::dynamic_pointer_cast<LazyObject>(c))
61 lazy->deepUpdate();
62 }
63 }
64 update();
65}
66
68 Date today = Settings::instance().evaluationDate();
69 if (exercise_ == nullptr || exercise_->dates().empty()) {
70 return today >= maturityDate();
71 } else {
72 // only the option itself is represented, not something we exercised into
73 return today >= exercise_->dates().back();
74 }
75}
76
78 calculate();
79 QL_REQUIRE(underlyingNpv_ != Null<Real>(), "MultiLegOption: underlying npv not available");
80 return underlyingNpv_;
81}
82
83void MultiLegOption::setupArguments(PricingEngine::arguments* args) const {
84 MultiLegOption::arguments* tmp = dynamic_cast<MultiLegOption::arguments*>(args);
85 QL_REQUIRE(tmp != nullptr, "MultiLegOption: wrong pricing engine argument type");
86 tmp->legs = legs_;
87 tmp->payer = payer_;
88 tmp->currency = currency_;
89 tmp->exercise = exercise_;
92}
93
94void MultiLegOption::fetchResults(const PricingEngine::results* r) const {
95 Instrument::fetchResults(r);
96 const MultiLegOption::results* results = dynamic_cast<const MultiLegOption::results*>(r);
97 if (results) {
99 } else {
100 underlyingNpv_ = Null<Real>();
101 }
102}
103
105 Instrument::results::reset();
106 underlyingNpv = Null<Real>();
107}
108
109} // namespace QuantExt
QuantLib::ext::shared_ptr< Exercise > exercise
std::vector< Currency > currency
const Settlement::Method settlementMethod_
void setupArguments(PricingEngine::arguments *) const override
MultiLegOption(const std::vector< Leg > &legs, const std::vector< bool > &payer, const std::vector< Currency > &currency, const QuantLib::ext::shared_ptr< Exercise > &exercise=QuantLib::ext::shared_ptr< Exercise >(), const Settlement::Type settlementType=Settlement::Physical, Settlement::Method settlementMethod=Settlement::PhysicalOTC)
exercise = nullptr means that the instrument is identical to the underlying itself (i....
bool isExpired() const override
const QuantLib::ext::shared_ptr< Exercise > exercise_
void deepUpdate() override
const Date & maturityDate() const
const Settlement::Type settlementType_
const std::vector< bool > payer_
const std::vector< Leg > legs_
void fetchResults(const PricingEngine::results *) const override
const std::vector< Currency > currency_
const std::vector< bool > & payer() const
multi leg option instrument