Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Attributes | List of all members
CmsCapHelper Class Reference

#include <qle/models/cmscaphelper.hpp>

+ Inheritance diagram for CmsCapHelper:
+ Collaboration diagram for CmsCapHelper:

Public Member Functions

 CmsCapHelper (Date asof, QuantLib::ext::shared_ptr< SwapIndex > &index1, QuantLib::ext::shared_ptr< SwapIndex > &index2, const Handle< YieldTermStructure > &yts, const Handle< Quote > &price, const Handle< Quote > &correlation, const Period &length, const Period &forwardStart, const Period &spotDays, const Period &cmsTenor, Natural fixingDays, const Calendar &calendar, const DayCounter &daycounter, const BusinessDayConvention &convention, QuantLib::ext::shared_ptr< FloatingRateCouponPricer > &pricer, QuantLib::ext::shared_ptr< QuantLib::CmsCouponPricer > &cmsPricer)
 
void performCalculations () const override
 
QuantLib::Real marketValue () const
 returns the actual price of the instrument (from volatility) More...
 
QuantLib::Real modelValue () const
 returns the price of the instrument according to the model More...
 
QuantLib::Real calibrationError () override
 returns the error resulting from the model valuation More...
 

Protected Attributes

Date asof_
 
QuantLib::ext::shared_ptr< SwapIndex > index1_
 
QuantLib::ext::shared_ptr< SwapIndex > index2_
 
Handle< YieldTermStructure > discountCurve_
 
Real marketValue_
 
Handle< Quote > correlation_
 
Period length_
 
Period forwardStart_
 
Period spotDays_
 
Period cmsTenor_
 
Natural fixingDays_
 
Calendar calendar_
 
DayCounter dayCounter_
 
BusinessDayConvention convention_
 
QuantLib::ext::shared_ptr< FloatingRateCouponPricerpricer_
 
QuantLib::ext::shared_ptr< QuantLib::CmsCouponPricer > cmsPricer_
 

Private Attributes

QuantLib::ext::shared_ptr< QuantLib::Swap > cap_
 

Detailed Description

Definition at line 37 of file cmscaphelper.hpp.

Constructor & Destructor Documentation

◆ CmsCapHelper()

CmsCapHelper ( Date  asof,
QuantLib::ext::shared_ptr< SwapIndex > &  index1,
QuantLib::ext::shared_ptr< SwapIndex > &  index2,
const Handle< YieldTermStructure > &  yts,
const Handle< Quote > &  price,
const Handle< Quote > &  correlation,
const Period &  length,
const Period &  forwardStart,
const Period &  spotDays,
const Period &  cmsTenor,
Natural  fixingDays,
const Calendar &  calendar,
const DayCounter &  daycounter,
const BusinessDayConvention &  convention,
QuantLib::ext::shared_ptr< FloatingRateCouponPricer > &  pricer,
QuantLib::ext::shared_ptr< QuantLib::CmsCouponPricer > &  cmsPricer 
)

Definition at line 39 of file cmscaphelper.hpp.

45 : asof_(asof), index1_(index1), index2_(index2), discountCurve_(yts), marketValue_(price->value()),
46 correlation_(correlation), length_(length), forwardStart_(forwardStart), spotDays_(spotDays),
47 cmsTenor_(cmsTenor), fixingDays_(fixingDays), calendar_(calendar), dayCounter_(daycounter),
48 convention_(convention), pricer_(pricer), cmsPricer_(cmsPricer) {
49
50 registerWith(correlation_);
51 }
Handle< Quote > correlation_
Handle< YieldTermStructure > discountCurve_
QuantLib::ext::shared_ptr< FloatingRateCouponPricer > pricer_
BusinessDayConvention convention_
QuantLib::ext::shared_ptr< QuantLib::CmsCouponPricer > cmsPricer_
QuantLib::ext::shared_ptr< SwapIndex > index1_
QuantLib::ext::shared_ptr< SwapIndex > index2_

Member Function Documentation

◆ performCalculations()

void performCalculations ( ) const
override

Definition at line 35 of file cmscaphelper.cpp.

35 {
36
37 Date startDate;
38 Date endDate;
39
40 // Compute ATM swap rates
41 Real spread, rate1, rate2;
42
43 std::vector<Real> nominals(1, 1.0);
44
45 {
46 QuantLib::ext::shared_ptr<PricingEngine> swapEngine(
47 new DiscountingSwapEngine(index1_->discountingTermStructure(), false));
48
49 Calendar calendar = index1_->fixingCalendar();
50
51 QuantLib::ext::shared_ptr<IborIndex> index = index1_->iborIndex();
52
53 // FIXME, reduce length by forward start
54 startDate = calendar.advance(calendar.advance(asof_, spotDays_), forwardStart_);
55 endDate = calendar.advance(startDate, length_ - forwardStart_, index->businessDayConvention());
56
57 Schedule cmsSchedule(startDate, endDate, cmsTenor_, calendar, index->businessDayConvention(),
58 index->businessDayConvention(), DateGeneration::Forward, false);
59
60 Leg cmsLeg = CmsLeg(cmsSchedule, index1_)
61 .withNotionals(nominals)
62 .withPaymentAdjustment(index1_->iborIndex()->businessDayConvention())
63 .withPaymentDayCounter(index1_->iborIndex()->dayCounter())
64 .withFixingDays(fixingDays_);
65 QuantLib::setCouponPricer(cmsLeg, cmsPricer_);
66
67 std::vector<Leg> cmsLegs;
68 std::vector<bool> cmsPayers;
69 cmsLegs.push_back(cmsLeg);
70 cmsPayers.push_back(true);
71 QuantLib::ext::shared_ptr<QuantLib::Swap> s = QuantLib::ext::make_shared<QuantLib::Swap>(cmsLegs, cmsPayers);
72 s->setPricingEngine(swapEngine);
73
74 rate1 = s->NPV() / (s->legBPS(0) / 1.0e-4);
75 }
76
77 QuantLib::ext::shared_ptr<PricingEngine> swapEngine(new DiscountingSwapEngine(index2_->discountingTermStructure(), false));
78
79 Calendar calendar = index2_->fixingCalendar();
80
81 QuantLib::ext::shared_ptr<IborIndex> index = index2_->iborIndex();
82 // FIXME, reduce length by forward start
83 startDate = calendar.advance(calendar.advance(asof_, spotDays_), forwardStart_);
84 endDate = calendar.advance(startDate, length_ - forwardStart_, index->businessDayConvention());
85
86 Schedule cmsSchedule(startDate, endDate, cmsTenor_, calendar, index->businessDayConvention(),
87 index->businessDayConvention(), DateGeneration::Forward, false);
88
89 Leg cmsLeg = CmsLeg(cmsSchedule, index2_)
90 .withNotionals(nominals)
91 .withPaymentAdjustment(index2_->iborIndex()->businessDayConvention())
92 .withPaymentDayCounter(index2_->iborIndex()->dayCounter())
93 .withFixingDays(fixingDays_);
94 QuantLib::setCouponPricer(cmsLeg, cmsPricer_);
95
96 std::vector<Leg> cmsLegs;
97 std::vector<bool> cmsPayers;
98 cmsLegs.push_back(cmsLeg);
99 cmsPayers.push_back(true);
100 QuantLib::ext::shared_ptr<QuantLib::Swap> s = QuantLib::ext::make_shared<QuantLib::Swap>(cmsLegs, cmsPayers);
101 s->setPricingEngine(swapEngine);
102
103 rate2 = s->NPV() / (s->legBPS(0) / 1.0e-4);
104
105 spread = rate1 - rate2;
106
107 // Construct CMS Spread CapFloor
108
109 std::vector<Leg> legs;
110 std::vector<bool> legPayers;
111
112 QuantLib::ext::shared_ptr<QuantLib::SwapSpreadIndex> spreadIndex = QuantLib::ext::make_shared<QuantLib::SwapSpreadIndex>(
113 "CMSSpread_" + index1_->familyName() + "_" + index2_->familyName(), index1_, index2_);
114
115 startDate = calendar_.advance(calendar_.advance(asof_, spotDays_), forwardStart_);
116 endDate = calendar_.advance(startDate, length_ - forwardStart_, convention_);
117
118 Schedule cmsSpreadSchedule(startDate, endDate, cmsTenor_, calendar_, convention_, convention_,
119 DateGeneration::Forward, false);
120 Leg cmsLeg1 = CmsSpreadLeg(cmsSpreadSchedule, spreadIndex)
121 .withNotionals(nominals)
122 .withSpreads(std::vector<Rate>(1, 0))
123 .withPaymentAdjustment(convention_)
124 .withPaymentDayCounter(dayCounter_)
125 .withFixingDays(fixingDays_)
126 .inArrears(true)
127 .withCaps(std::vector<Rate>(1, spread));
128
129 QuantLib::setCouponPricer(cmsLeg1, pricer_);
130
131 Leg cmsLeg1b = StrippedCappedFlooredCouponLeg(cmsLeg1);
132
133 legs.push_back(cmsLeg1b);
134 legPayers.push_back(false);
135
136 cap_ = QuantLib::ext::make_shared<QuantLib::Swap>(legs, legPayers);
137 QuantLib::ext::shared_ptr<PricingEngine> swapEngine2(new DiscountingSwapEngine(discountCurve_, false));
138 cap_->setPricingEngine(swapEngine2);
139}
QuantLib::ext::shared_ptr< QuantLib::Swap > cap_

◆ marketValue()

QuantLib::Real marketValue ( ) const

returns the actual price of the instrument (from volatility)

Definition at line 56 of file cmscaphelper.hpp.

56{ return marketValue_; }
+ Here is the caller graph for this function:

◆ modelValue()

QuantLib::Real modelValue ( ) const

returns the price of the instrument according to the model

Definition at line 30 of file cmscaphelper.cpp.

30 {
31 calculate();
32 return cap_->NPV();
33}
+ Here is the caller graph for this function:

◆ calibrationError()

QuantLib::Real calibrationError ( )
override

returns the error resulting from the model valuation

Definition at line 62 of file cmscaphelper.hpp.

62{ return marketValue() - modelValue(); }
QuantLib::Real modelValue() const
returns the price of the instrument according to the model
QuantLib::Real marketValue() const
returns the actual price of the instrument (from volatility)
+ Here is the call graph for this function:

Member Data Documentation

◆ asof_

Date asof_
protected

Definition at line 65 of file cmscaphelper.hpp.

◆ index1_

QuantLib::ext::shared_ptr<SwapIndex> index1_
protected

Definition at line 66 of file cmscaphelper.hpp.

◆ index2_

QuantLib::ext::shared_ptr<SwapIndex> index2_
protected

Definition at line 67 of file cmscaphelper.hpp.

◆ discountCurve_

Handle<YieldTermStructure> discountCurve_
protected

Definition at line 68 of file cmscaphelper.hpp.

◆ marketValue_

Real marketValue_
protected

Definition at line 69 of file cmscaphelper.hpp.

◆ correlation_

Handle<Quote> correlation_
protected

Definition at line 70 of file cmscaphelper.hpp.

◆ length_

Period length_
protected

Definition at line 71 of file cmscaphelper.hpp.

◆ forwardStart_

Period forwardStart_
protected

Definition at line 73 of file cmscaphelper.hpp.

◆ spotDays_

Period spotDays_
protected

Definition at line 74 of file cmscaphelper.hpp.

◆ cmsTenor_

Period cmsTenor_
protected

Definition at line 75 of file cmscaphelper.hpp.

◆ fixingDays_

Natural fixingDays_
protected

Definition at line 76 of file cmscaphelper.hpp.

◆ calendar_

Calendar calendar_
protected

Definition at line 77 of file cmscaphelper.hpp.

◆ dayCounter_

DayCounter dayCounter_
protected

Definition at line 78 of file cmscaphelper.hpp.

◆ convention_

BusinessDayConvention convention_
protected

Definition at line 79 of file cmscaphelper.hpp.

◆ pricer_

QuantLib::ext::shared_ptr<FloatingRateCouponPricer> pricer_
protected

Definition at line 81 of file cmscaphelper.hpp.

◆ cmsPricer_

QuantLib::ext::shared_ptr<QuantLib::CmsCouponPricer> cmsPricer_
protected

Definition at line 82 of file cmscaphelper.hpp.

◆ cap_

QuantLib::ext::shared_ptr<QuantLib::Swap> cap_
mutableprivate

Definition at line 85 of file cmscaphelper.hpp.