QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
makeswaption.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007, 2008, 2014 Ferdinando Ametrano
5 Copyright (C) 2007 Giorgio Facchinetti
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#include <ql/cashflows/cashflows.hpp>
22#include <ql/exercise.hpp>
23#include <ql/indexes/swapindex.hpp>
24#include <ql/instruments/makeswaption.hpp>
25#include <ql/instruments/makevanillaswap.hpp>
26#include <ql/pricingengines/swap/discountingswapengine.hpp>
27#include <ql/optional.hpp>
28#include <ql/settings.hpp>
29#include <utility>
30
31namespace QuantLib {
32
33 MakeSwaption::MakeSwaption(ext::shared_ptr<SwapIndex> swapIndex,
34 const Period& optionTenor,
35 Rate strike)
36 : swapIndex_(std::move(swapIndex)), delivery_(Settlement::Physical),
37 settlementMethod_(Settlement::PhysicalOTC), optionTenor_(optionTenor),
38 optionConvention_(ModifiedFollowing), fixingDate_(Null<Date>()), strike_(strike),
39 underlyingType_(Swap::Payer), nominal_(1.0) {}
40
41 MakeSwaption::MakeSwaption(ext::shared_ptr<SwapIndex> swapIndex,
42 const Date& fixingDate,
43 Rate strike)
44 : swapIndex_(std::move(swapIndex)), delivery_(Settlement::Physical),
45 settlementMethod_(Settlement::PhysicalOTC), optionConvention_(ModifiedFollowing),
46 fixingDate_(fixingDate), strike_(strike), underlyingType_(Swap::Payer) {}
47
48 MakeSwaption::operator Swaption() const {
49 ext::shared_ptr<Swaption> swaption = *this;
50 return *swaption;
51 }
52
53 MakeSwaption::operator ext::shared_ptr<Swaption>() const {
54
55 const Calendar& fixingCalendar = swapIndex_->fixingCalendar();
57 // if the evaluation date is not a business day
58 // then move to the next business day
59 refDate = fixingCalendar.adjust(refDate);
60 if (fixingDate_ == Null<Date>())
61 fixingDate_ = fixingCalendar.advance(refDate, optionTenor_,
62 optionConvention_);
63 if (exerciseDate_ == Null<Date>()) {
64 exercise_ = ext::shared_ptr<Exercise>(new
65 EuropeanExercise(fixingDate_));
66 } else {
67 QL_REQUIRE(exerciseDate_ <= fixingDate_,
68 "exercise date (" << exerciseDate_ << ") must be less "
69 "than or equal to fixing date (" << fixingDate_ << ")");
70 exercise_ = ext::shared_ptr<Exercise>(new
71 EuropeanExercise(exerciseDate_));
72 }
73
74 Rate usedStrike = strike_;
75 if (strike_ == Null<Rate>()) {
76 // ATM on curve(s) attached to index
77 QL_REQUIRE(!swapIndex_->forwardingTermStructure().empty(),
78 "null term structure set to this instance of " <<
79 swapIndex_->name());
80 ext::shared_ptr<VanillaSwap> temp =
81 swapIndex_->underlyingSwap(fixingDate_);
82 temp->setPricingEngine(
83 ext::shared_ptr<PricingEngine>(new DiscountingSwapEngine(
84 swapIndex_->exogenousDiscount()
85 ? swapIndex_->discountingTermStructure()
86 : swapIndex_->forwardingTermStructure(),
87 false)));
88 usedStrike = temp->fairRate();
89 }
90
91 BusinessDayConvention bdc = swapIndex_->fixedLegConvention();
92 underlyingSwap_ =
93 MakeVanillaSwap(swapIndex_->tenor(),
94 swapIndex_->iborIndex(), usedStrike)
95 .withEffectiveDate(swapIndex_->valueDate(fixingDate_))
96 .withFixedLegCalendar(swapIndex_->fixingCalendar())
97 .withFixedLegDayCount(swapIndex_->dayCounter())
98 .withFixedLegTenor(swapIndex_->fixedLegTenor())
101 .withType(underlyingType_)
102 .withNominal(nominal_)
103 .withIndexedCoupons(useIndexedCoupons_);
104
105 ext::shared_ptr<Swaption> swaption(new Swaption(
106 underlyingSwap_, exercise_, delivery_, settlementMethod_));
107 swaption->setPricingEngine(engine_);
108 return swaption;
109 }
110
112 delivery_ = delivery;
113 return *this;
114 }
115
117 Settlement::Method settlementMethod) {
118 settlementMethod_ = settlementMethod;
119 return *this;
120 }
121
124 optionConvention_ = bdc;
125 return *this;
126 }
127
129 exerciseDate_ = date;
130 return *this;
131 }
132
134 underlyingType_ = type;
135 return *this;
136 }
137
139 const ext::shared_ptr<PricingEngine>& engine) {
140 engine_ = engine;
141 return *this;
142 }
143
145 nominal_ = n;
146 return *this;
147 }
148
149 MakeSwaption& MakeSwaption::withIndexedCoupons(const ext::optional<bool>& b) {
151 return *this;
152 }
153
156 return *this;
157 }
158
159}
calendar class
Definition: calendar.hpp:61
Date adjust(const Date &, BusinessDayConvention convention=Following) const
Definition: calendar.cpp:84
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
Definition: calendar.cpp:130
Concrete date class.
Definition: date.hpp:125
European exercise.
Definition: exercise.hpp:96
BusinessDayConvention optionConvention_
MakeSwaption & withOptionConvention(BusinessDayConvention bdc)
MakeSwaption & withExerciseDate(const Date &)
ext::optional< bool > useIndexedCoupons_
MakeSwaption & withAtParCoupons(bool b=true)
MakeSwaption & withIndexedCoupons(const ext::optional< bool > &b=true)
MakeSwaption & withNominal(Real n)
Settlement::Type delivery_
ext::shared_ptr< PricingEngine > engine_
MakeSwaption & withSettlementMethod(Settlement::Method settlementMethod)
MakeSwaption & withPricingEngine(const ext::shared_ptr< PricingEngine > &engine)
Settlement::Method settlementMethod_
MakeSwaption & withSettlementType(Settlement::Type delivery)
MakeSwaption(ext::shared_ptr< SwapIndex > swapIndex, const Period &optionTenor, Rate strike=Null< Rate >())
MakeSwaption & withUnderlyingType(Swap::Type type)
MakeVanillaSwap & withEffectiveDate(const Date &)
MakeVanillaSwap & withFixedLegConvention(BusinessDayConvention bdc)
MakeVanillaSwap & withFixedLegTerminationDateConvention(BusinessDayConvention bdc)
MakeVanillaSwap & withFixedLegCalendar(const Calendar &cal)
MakeVanillaSwap & withIndexedCoupons(const ext::optional< bool > &b=true)
MakeVanillaSwap & withFixedLegDayCount(const DayCounter &dc)
MakeVanillaSwap & withNominal(Real n)
MakeVanillaSwap & withType(Swap::Type type)
MakeVanillaSwap & withFixedLegTenor(const Period &t)
template class providing a null value for a given type.
Definition: null.hpp:76
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
Interest rate swap.
Definition: swap.hpp:41
Swaption class
Definition: swaption.hpp:81
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
STL namespace.
settlement information
Definition: swaption.hpp:40