QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
g2swaptionengine.hpp
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
24#ifndef quantlib_pricers_G2_swaption_hpp
25#define quantlib_pricers_G2_swaption_hpp
26
27#include <ql/pricingengines/genericmodelengine.hpp>
28#include <ql/models/shortrate/twofactormodels/g2.hpp>
29#include <ql/pricingengines/swap/discountingswapengine.hpp>
30
31namespace QuantLib {
32
34
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 {
51 QL_REQUIRE(arguments_.settlementType == Settlement::Physical,
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)
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:166
Swaption class
Definition: swaption.hpp:81
Plain-vanilla swap: fix vs ibor leg.
Definition: vanillaswap.hpp:65
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