QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
g2swaptionengine.hpp
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) 2004 Mike Parker
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/*! \file g2swaptionengine.hpp
21 \brief Swaption pricing engine for two-factor additive Gaussian Model G2++
22*/
23
24#ifndef quantlib_pricers_G2_swaption_hpp
25#define quantlib_pricers_G2_swaption_hpp
26
30
31namespace QuantLib {
32
33 //! %Swaption priced by means of the Black formula
34 /*! \ingroup swaptionengines
35
36 \warning The engine assumes that the exercise date equals the
37 start date of the passed swap.
38 */
39 class G2SwaptionEngine : public GenericModelEngine<G2, Swaption::arguments,
40 Swaption::results> {
41 public:
42 // range is the number of standard deviations to use in the
43 // exponential term of the integral for the european swaption.
44 // intervals is the number of intervals to use in the integration.
45 G2SwaptionEngine(const ext::shared_ptr<G2>& model,
46 Real range,
47 Size intervals)
49 range_(range), intervals_(intervals) {}
50 void calculate() const override {
52 "cash-settled swaptions not priced with G2 engine");
53 QL_REQUIRE(!model_.empty(), "no model specified");
54
55 // adjust the fixed rate of the swap for the spread on the
56 // floating leg (which is not taken into account by the
57 // model)
58 auto swap = arguments_.swap;
59 swap->setPricingEngine(ext::make_shared<DiscountingSwapEngine>(model_->termStructure(), false));
60 Spread correction = swap->spread() *
61 std::fabs(swap->floatingLegBPS() / swap->fixedLegBPS());
62 Rate fixedRate = swap->fixedRate() - correction;
63
64 results_.value = model_->swaption(arguments_, fixedRate,
66 }
67
68 private:
71 };
72
73}
74
75
76#endif
Two-additive-factor gaussian model class.
Definition: g2.hpp:56
Swaption priced by means of the Black formula
void calculate() const override
G2SwaptionEngine(const ext::shared_ptr< G2 > &model, Real range, Size intervals)
Base class for some pricing engine on a particular model.
bool empty() const
checks if the contained shared pointer points to anything
Definition: handle.hpp:191
Swaption class
Definition: swaption.hpp:88
discounting swap engine
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Two-factor additive Gaussian Model G2++.
Generic option engine based on a model.
QL_REAL Real
real number
Definition: types.hpp:50
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
void swap(Array &v, Array &w) noexcept
Definition: array.hpp:903