/src/quantlib/ql/instruments/floatfloatswaption.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2013, 2018 Peter Caspers |
5 | | |
6 | | This file is part of QuantLib, a free-software/open-source library |
7 | | for financial quantitative analysts and developers - http://quantlib.org/ |
8 | | |
9 | | QuantLib is free software: you can redistribute it and/or modify it |
10 | | under the terms of the QuantLib license. You should have received a |
11 | | copy of the license along with this program; if not, please email |
12 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
13 | | <https://www.quantlib.org/license.shtml>. |
14 | | |
15 | | This program is distributed in the hope that it will be useful, but WITHOUT |
16 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
17 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
18 | | */ |
19 | | |
20 | | #include <ql/exercise.hpp> |
21 | | #include <ql/instruments/floatfloatswaption.hpp> |
22 | | #include <utility> |
23 | | |
24 | | namespace QuantLib { |
25 | | |
26 | | FloatFloatSwaption::FloatFloatSwaption(ext::shared_ptr<FloatFloatSwap> swap, |
27 | | const ext::shared_ptr<Exercise>& exercise, |
28 | | Settlement::Type delivery, |
29 | | Settlement::Method settlementMethod) |
30 | 0 | : Option(ext::shared_ptr<Payoff>(), exercise), swap_(std::move(swap)), |
31 | 0 | settlementType_(delivery), settlementMethod_(settlementMethod) { |
32 | 0 | registerWith(swap_); |
33 | | // When we ask for the NPV of an expired swaption, the |
34 | | // swap is not recalculated and thus wouldn't forward |
35 | | // later notifications according to the default behavior of |
36 | | // LazyObject instances. This means that even if the |
37 | | // evaluation date changes so that the swaption is no longer |
38 | | // expired, the instrument wouldn't be notified and thus it |
39 | | // wouldn't recalculate. To avoid this, we override the |
40 | | // default behavior of the underlying swap. |
41 | 0 | swap_->alwaysForwardNotifications(); |
42 | 0 | } Unexecuted instantiation: QuantLib::FloatFloatSwaption::FloatFloatSwaption(boost::shared_ptr<QuantLib::FloatFloatSwap>, boost::shared_ptr<QuantLib::Exercise> const&, QuantLib::Settlement::Type, QuantLib::Settlement::Method) Unexecuted instantiation: QuantLib::FloatFloatSwaption::FloatFloatSwaption(boost::shared_ptr<QuantLib::FloatFloatSwap>, boost::shared_ptr<QuantLib::Exercise> const&, QuantLib::Settlement::Type, QuantLib::Settlement::Method) |
43 | | |
44 | 0 | bool FloatFloatSwaption::isExpired() const { |
45 | 0 | return detail::simple_event(exercise_->dates().back()).hasOccurred(); |
46 | 0 | } |
47 | | |
48 | | void |
49 | 0 | FloatFloatSwaption::setupArguments(PricingEngine::arguments *args) const { |
50 | |
|
51 | 0 | swap_->setupArguments(args); |
52 | |
|
53 | 0 | auto* arguments = dynamic_cast<FloatFloatSwaption::arguments*>(args); |
54 | |
|
55 | 0 | QL_REQUIRE(arguments != nullptr, "wrong argument type"); |
56 | | |
57 | 0 | arguments->swap = swap_; |
58 | 0 | arguments->exercise = exercise_; |
59 | 0 | arguments->settlementType = settlementType_; |
60 | 0 | arguments->settlementMethod = settlementMethod_; |
61 | 0 | } |
62 | | |
63 | 0 | void FloatFloatSwaption::arguments::validate() const { |
64 | 0 | FloatFloatSwap::arguments::validate(); |
65 | 0 | QL_REQUIRE(swap, "underlying cms swap not set"); |
66 | 0 | QL_REQUIRE(exercise, "exercise not set"); |
67 | 0 | Settlement::checkTypeAndMethodConsistency(settlementType, |
68 | 0 | settlementMethod); |
69 | 0 | } |
70 | | |
71 | | std::vector<ext::shared_ptr<BlackCalibrationHelper>> |
72 | | FloatFloatSwaption::calibrationBasket( |
73 | | const ext::shared_ptr<SwapIndex>& standardSwapBase, |
74 | | const ext::shared_ptr<SwaptionVolatilityStructure>& swaptionVolatility, |
75 | 0 | const BasketGeneratingEngine::CalibrationBasketType basketType) const { |
76 | |
|
77 | 0 | ext::shared_ptr<BasketGeneratingEngine> engine = |
78 | 0 | ext::dynamic_pointer_cast<BasketGeneratingEngine>(engine_); |
79 | 0 | QL_REQUIRE(engine, "engine is not a basket generating engine"); |
80 | 0 | engine_->reset(); |
81 | 0 | setupArguments(engine_->getArguments()); |
82 | 0 | engine_->getArguments()->validate(); |
83 | 0 | return engine->calibrationBasket(exercise_, standardSwapBase, |
84 | 0 | swaptionVolatility, basketType); |
85 | 0 | } |
86 | | |
87 | | } |