QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
nonstandardswaption.cpp
Go to the documentation of this file.
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>
22#include <utility>
23
24namespace QuantLib {
25
27 : Option(ext::shared_ptr<Payoff>(),
28 const_cast<Swaption &>(fromSwaption).exercise()),
29 swap_(ext::make_shared<NonstandardSwap>(
30 *fromSwaption.underlying())),
31 settlementType_(fromSwaption.settlementType()),
32 settlementMethod_(fromSwaption.settlementMethod()) {
33
35 // When we ask for the NPV of an expired swaption, the
36 // swap is not recalculated and thus wouldn't forward
37 // later notifications according to the default behavior of
38 // LazyObject instances. This means that even if the
39 // evaluation date changes so that the swaption is no longer
40 // expired, the instrument wouldn't be notified and thus it
41 // wouldn't recalculate. To avoid this, we override the
42 // default behavior of the underlying swap.
43 swap_->alwaysForwardNotifications();
44 }
45
46 NonstandardSwaption::NonstandardSwaption(ext::shared_ptr<NonstandardSwap> swap,
47 const ext::shared_ptr<Exercise>& exercise,
48 Settlement::Type delivery,
49 Settlement::Method settlementMethod)
50 : Option(ext::shared_ptr<Payoff>(), exercise), swap_(std::move(swap)),
51 settlementType_(delivery), settlementMethod_(settlementMethod) {
53 swap_->alwaysForwardNotifications();
54 }
55
57
58 return detail::simple_event(exercise_->dates().back()).hasOccurred();
59 }
60
61 void
63
64 swap_->setupArguments(args);
65
66 auto* arguments = dynamic_cast<NonstandardSwaption::arguments*>(args);
67
68 QL_REQUIRE(arguments != nullptr, "argument types do not match");
69
74 }
75
77
79 QL_REQUIRE(swap, "underlying non standard swap not set");
80 QL_REQUIRE(exercise, "exercise not set");
83 }
84
85 std::vector<ext::shared_ptr<BlackCalibrationHelper>>
87 const ext::shared_ptr<SwapIndex>& standardSwapBase,
88 const ext::shared_ptr<SwaptionVolatilityStructure>& swaptionVolatility,
89 const BasketGeneratingEngine::CalibrationBasketType basketType) const {
90
91 ext::shared_ptr<BasketGeneratingEngine> engine =
92 ext::dynamic_pointer_cast<BasketGeneratingEngine>(engine_);
93 QL_REQUIRE(engine, "engine is not a basket generating engine");
94 engine_->reset();
95 setupArguments(engine_->getArguments());
96 engine_->getArguments()->validate();
97 return engine->calibrationBasket(exercise_, standardSwapBase,
98 swaptionVolatility, basketType);
99 }
100}
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
ext::shared_ptr< PricingEngine > engine_
Definition: instrument.hpp:110
Arguments for nonstandard swaption calculation
ext::shared_ptr< NonstandardSwap > swap
base class for nonstandard swaption engines
ext::shared_ptr< NonstandardSwap > swap_
void setupArguments(PricingEngine::arguments *) const override
bool isExpired() const override
returns whether the instrument might have value greater than zero.
NonstandardSwaption(const Swaption &fromSwaption)
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
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
Swaption class
Definition: swaption.hpp:88
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Option exercise classes and payoff function.
Definition: any.hpp:35
void swap(Array &v, Array &w) noexcept
Definition: array.hpp:903
STL namespace.
nonstandard swap option class
static void checkTypeAndMethodConsistency(Settlement::Type, Settlement::Method)
check consistency of settlement type and method
Definition: swaption.cpp:201