QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
gaussian1djamshidianswaptionengine.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) 2001, 2002, 2003 Sadruddin Rejeb
5 Copyright (C) 2013 Peter Caspers
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
23#include <utility>
24
25namespace QuantLib {
26
27 class Gaussian1dJamshidianSwaptionEngine::rStarFinder {
28 public:
29 rStarFinder(const ext::shared_ptr<Gaussian1dModel>& model,
30 Real nominal,
31 const Date& maturityDate,
32 const Date& valueDate,
33 std::vector<Date> fixedPayDates,
34 const std::vector<Real>& amounts,
35 const Size startIndex)
36 : strike_(nominal), maturityDate_(maturityDate), valueDate_(valueDate),
37 startIndex_(startIndex), times_(std::move(fixedPayDates)), amounts_(amounts),
38 model_(model) {}
39
40 Real operator()(Rate y) const {
41 Real value = strike_;
42 Size size = times_.size();
43 for (Size i = startIndex_; i < size; i++) {
44 Real dbValue = model_->zerobond(times_[i], maturityDate_, y) /
45 model_->zerobond(valueDate_, maturityDate_, y);
46 value -= amounts_[i] * dbValue;
47 }
48 return value;
49 }
50
51 private:
53 Date maturityDate_, valueDate_;
54 Size startIndex_;
55 std::vector<Date> times_;
56 const std::vector<Real> &amounts_;
57 const ext::shared_ptr<Gaussian1dModel> &model_;
58 };
59
61
63 "cash settled (ParYieldCurve) swaptions not priced with "
64 "Gaussian1dJamshidianSwaptionEngine");
65
66 QL_REQUIRE(arguments_.exercise->type() == Exercise::European,
67 "cannot use the Jamshidian decomposition "
68 "on exotic swaptions");
69
70 QL_REQUIRE(arguments_.swap->spread() == 0.0,
71 "non zero spread (" << arguments_.swap->spread()
72 << ") not allowed"); // PC
73
74 QL_REQUIRE(arguments_.nominal != Null<Real>(),
75 "non-constant nominals are not supported yet");
76
77 Date referenceDate;
78 DayCounter dayCounter;
79
80 referenceDate = model_->termStructure()->referenceDate();
81 dayCounter = model_->termStructure()->dayCounter();
82
83 std::vector<Real> amounts(arguments_.fixedCoupons);
84 amounts.back() += arguments_.nominal;
85
86 Size startIndex = std::upper_bound(arguments_.fixedResetDates.begin(),
87 arguments_.fixedResetDates.end(),
88 arguments_.exercise->date(0) - 1) -
89 arguments_.fixedResetDates.begin();
90 // only consider coupons with start date >= exercise dates
91
92 rStarFinder finder(*model_, arguments_.nominal,
93 arguments_.exercise->date(0),
94 arguments_.fixedResetDates[startIndex],
95 arguments_.fixedPayDates, amounts, startIndex);
96 Brent s1d;
97 Rate minStrike = -8.0;
98 Rate maxStrike = 8.0;
99 s1d.setMaxEvaluations(10000);
100 s1d.setLowerBound(minStrike);
101 s1d.setUpperBound(maxStrike);
102 Rate rStar = s1d.solve(finder, 1e-8, 0.00, minStrike,
103 maxStrike); // this is actually yStar
104
105 Option::Type w =
107 Size size = arguments_.fixedCoupons.size();
108
109 Real value = 0.0;
110 for (Size i = startIndex; i < size; i++) {
111 // Real fixedPayTime =
112 // dayCounter.yearFraction(referenceDate,arguments_.fixedPayDates[i]);
113 Real strike =
114 model_->zerobond(arguments_.fixedPayDates[i],
115 arguments_.exercise->date(0), rStar) /
116 model_->zerobond(arguments_.fixedResetDates[startIndex],
117 arguments_.exercise->date(0), rStar);
118 Real dboValue =
119 model_->zerobondOption(w, arguments_.exercise->date(0),
120 arguments_.fixedResetDates[startIndex],
121 arguments_.fixedPayDates[i], strike);
122 value += amounts[i] * dboValue;
123 }
124 results_.value = value;
125 }
126}
Brent 1-D solver.
Brent 1-D solver
Definition: brent.hpp:37
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
template class providing a null value for a given type.
Definition: null.hpp:76
void setMaxEvaluations(Size evaluations)
Definition: solver1d.hpp:238
void setLowerBound(Real lowerBound)
sets the lower bound for the function domain
Definition: solver1d.hpp:243
Real solve(const F &f, Real accuracy, Real guess, Real step) const
Definition: solver1d.hpp:84
void setUpperBound(Real upperBound)
sets the upper bound for the function domain
Definition: solver1d.hpp:249
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Swaption engine using Jamshidian's decomposition.
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.