1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2011, 2012 Andre Miemiec
5 Copyright (C) 2012 Samuel Tebege
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file haganirregularswaptionengine.hpp
22 \brief engine for pricing irregular swaptions via super-replication
23*/
24
25#ifndef quantlib_hagan_irregular_swaption_engine_hpp
26#define quantlib_hagan_irregular_swaption_engine_hpp
27
28#include <ql/experimental/swaptions/irregularswaption.hpp>
29#include <ql/termstructures/yieldtermstructure.hpp>
30#include <ql/termstructures/volatility/swaption/swaptionvolstructure.hpp>
31#include <ql/math/optimization/costfunction.hpp>
32#include <ql/instruments/makevanillaswap.hpp>
33
34namespace QuantLib {
35
36 //! Pricing engine for irregular swaptions
37 /*! References:
38
39 1. P.S. Hagan: "Methodology for Callable Swaps and Bermudan
40 'Exercise into Swaptions'"
41 2. P.J. Hunt, J.E. Kennedy: "Implied interest rate pricing
42 models", Finance Stochast. 2, 275-293 (1998)
43
44 \warning Currently a spread is not handled correctly; it
45 should be a minor exercise to account for this
46 feature as well;
47 */
48 class HaganIrregularSwaptionEngine
49 : public GenericEngine<IrregularSwaption::arguments,
50 IrregularSwaption::results> {
51 public:
52 //@{
53 explicit HaganIrregularSwaptionEngine(
54 Handle<SwaptionVolatilityStructure>,
55 Handle<YieldTermStructure> termStructure = Handle<YieldTermStructure>());
56 //@}
57 void calculate() const override;
58
59 // helper class
60 class Basket {
61 public:
62 Basket(ext::shared_ptr<IrregularSwap> swap,
63 Handle<YieldTermStructure> termStructure,
64 Handle<SwaptionVolatilityStructure> volatilityStructure);
65 Array compute(Rate lambda = 0.0) const;
66 Real operator()(Rate x) const;
67 ext::shared_ptr<VanillaSwap> component(Size i) const;
68 Array weights() const { return compute(lambda: lambda_); };
69 Real& lambda() const { return lambda_; };
70 // NOLINTNEXTLINE(cppcoreguidelines-noexcept-swap,performance-noexcept-swap)
71 ext::shared_ptr<IrregularSwap> swap() const { return swap_; };
72 private:
73 ext::shared_ptr<IrregularSwap> swap_;
74 Handle<YieldTermStructure> termStructure_;
75 Handle<SwaptionVolatilityStructure> volatilityStructure_;
76
77 Real targetNPV_ = 0.0;
78
79 ext::shared_ptr<PricingEngine> engine_;
80
81 std::vector<Real> fairRates_;
82 std::vector<Real> annuities_;
83 std::vector<Date> expiries_;
84
85 mutable Real lambda_ = 0.0;
86 };
87
88 Real HKPrice(Basket& basket,ext::shared_ptr<Exercise>& exercise) const;
89 Real LGMPrice(Basket& basket,ext::shared_ptr<Exercise>& exercise) const;
90
91 private:
92 Handle<YieldTermStructure> termStructure_;
93 Handle<SwaptionVolatilityStructure> volatilityStructure_;
94 class rStarFinder;
95 };
96
97}
98
99#endif
100

source code of quantlib/ql/experimental/swaptions/haganirregularswaptionengine.hpp