QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
floatfloatswaption.cpp
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 <http://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
24namespace 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 : Option(ext::shared_ptr<Payoff>(), exercise), swap_(std::move(swap)),
31 settlementType_(delivery), settlementMethod_(settlementMethod) {
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 swap_->alwaysForwardNotifications();
42 }
43
45 return detail::simple_event(exercise_->dates().back()).hasOccurred();
46 }
47
48 void
50
51 swap_->setupArguments(args);
52
53 auto* arguments = dynamic_cast<FloatFloatSwaption::arguments*>(args);
54
55 QL_REQUIRE(arguments != nullptr, "wrong argument type");
56
61 }
62
65 QL_REQUIRE(swap, "underlying cms swap not set");
66 QL_REQUIRE(exercise, "exercise not set");
69 }
70
71 std::vector<ext::shared_ptr<BlackCalibrationHelper>>
73 const ext::shared_ptr<SwapIndex>& standardSwapBase,
74 const ext::shared_ptr<SwaptionVolatilityStructure>& swaptionVolatility,
75 const BasketGeneratingEngine::CalibrationBasketType basketType) const {
76
77 ext::shared_ptr<BasketGeneratingEngine> engine =
78 ext::dynamic_pointer_cast<BasketGeneratingEngine>(engine_);
79 QL_REQUIRE(engine, "engine is not a basket generating engine");
80 engine_->reset();
81 setupArguments(engine_->getArguments());
82 engine_->getArguments()->validate();
83 return engine->calibrationBasket(exercise_, standardSwapBase,
84 swaptionVolatility, basketType);
85 }
86
87}
virtual bool hasOccurred(const Date &refDate=Date(), ext::optional< bool > includeRefDate=ext::nullopt) const
returns true if an event has already occurred before a date
Definition: event.cpp:28
Arguments for cms swaption calculation
ext::shared_ptr< FloatFloatSwap > swap
base class for cms swaption engines
void setupArguments(PricingEngine::arguments *) const override
bool isExpired() const override
returns whether the instrument might have value greater than zero.
std::vector< ext::shared_ptr< BlackCalibrationHelper > > calibrationBasket(const ext::shared_ptr< SwapIndex > &standardSwapBase, const ext::shared_ptr< SwaptionVolatilityStructure > &swaptionVolatility, BasketGeneratingEngine::CalibrationBasketType basketType=BasketGeneratingEngine::MaturityStrikeByDeltaGamma) const
FloatFloatSwaption(ext::shared_ptr< FloatFloatSwap > swap, const ext::shared_ptr< Exercise > &exercise, Settlement::Type delivery=Settlement::Physical, Settlement::Method settlementMethod=Settlement::PhysicalOTC)
ext::shared_ptr< FloatFloatSwap > swap_
Settlement::Method settlementMethod_
ext::shared_ptr< PricingEngine > engine_
Definition: instrument.hpp:110
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
ext::shared_ptr< Exercise > exercise
Definition: option.hpp:65
base option class
Definition: option.hpp:36
ext::shared_ptr< Exercise > exercise_
Definition: option.hpp:50
Abstract base class for option payoffs.
Definition: payoff.hpp:36
Definition: any.hpp:35
void swap(Array &v, Array &w) noexcept
Definition: array.hpp:903
STL namespace.
static void checkTypeAndMethodConsistency(Settlement::Type, Settlement::Method)
check consistency of settlement type and method
Definition: swaption.cpp:201