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

#include <qle/pricingengines/discountingswapenginedeltagamma.hpp>

+ Inheritance diagram for NpvDeltaGammaCalculator:
+ Collaboration diagram for NpvDeltaGammaCalculator:

Public Member Functions

 NpvDeltaGammaCalculator (Handle< YieldTermStructure > discountCurve, const Real payer, Real &npv, Real &bps, const bool computeDelta, const bool computeGamma, const bool computeBPS, std::map< Date, Real > &deltaDiscount, std::map< Date, Real > &deltaForward, std::map< Date, Real > &deltaBPS, std::map< Date, Real > &gammaDiscount, std::map< std::pair< Date, Date >, Real > &gammaForward, std::map< std::pair< Date, Date >, Real > &gammaDscFwd, std::map< Date, Real > &gammaBPS, Real &fxLinkedForeignNpv, const bool excludeSimpleCashFlowsFromSensis, Real &simpleCashFlowNpv)
 
void visit (CashFlow &c) override
 
void visit (SimpleCashFlow &c) override
 
void visit (FixedRateCoupon &c) override
 
void visit (IborCoupon &c) override
 
void visit (FloatingRateFXLinkedNotionalCoupon &c) override
 
void visit (FXLinkedCashFlow &c) override
 
void visit (QuantExt::OvernightIndexedCoupon &c) override
 

Private Member Functions

void processIborCoupon (FloatingRateCoupon &c)
 

Private Attributes

Handle< YieldTermStructure > discountCurve_
 
const Real payer_
 
Real & npv_
 
Real & bps_
 
const bool computeDelta_
 
const bool computeGamma_
 
const bool computeBPS_
 
std::map< Date, Real > & deltaDiscount_
 
std::map< Date, Real > & deltaForward_
 
std::map< Date, Real > & deltaBPS_
 
std::map< Date, Real > & gammaDiscount_
 
std::map< std::pair< Date, Date >, Real > & gammaForward_
 
std::map< std::pair< Date, Date >, Real > & gammaDscFwd_
 
std::map< Date, Real > & gammaBPS_
 
Real & fxLinkedForeignNpv_
 
const bool excludeSimpleCashFlowsFromSensis_
 
Real & simpleCashFlowNpv_
 

Detailed Description

Definition at line 87 of file discountingswapenginedeltagamma.hpp.

Constructor & Destructor Documentation

◆ NpvDeltaGammaCalculator()

NpvDeltaGammaCalculator ( Handle< YieldTermStructure >  discountCurve,
const Real  payer,
Real &  npv,
Real &  bps,
const bool  computeDelta,
const bool  computeGamma,
const bool  computeBPS,
std::map< Date, Real > &  deltaDiscount,
std::map< Date, Real > &  deltaForward,
std::map< Date, Real > &  deltaBPS,
std::map< Date, Real > &  gammaDiscount,
std::map< std::pair< Date, Date >, Real > &  gammaForward,
std::map< std::pair< Date, Date >, Real > &  gammaDscFwd,
std::map< Date, Real > &  gammaBPS,
Real &  fxLinkedForeignNpv,
const bool  excludeSimpleCashFlowsFromSensis,
Real &  simpleCashFlowNpv 
)

Definition at line 36 of file discountingswapenginedeltagamma.cpp.

45 : discountCurve_(discountCurve), payer_(payer), npv_(npv), bps_(bps), computeDelta_(computeDelta),
46 computeGamma_(computeGamma), computeBPS_(computeBPS), deltaDiscount_(deltaDiscount), deltaForward_(deltaForward),
47 deltaBPS_(deltaBPS), gammaDiscount_(gammaDiscount), gammaForward_(gammaForward), gammaDscFwd_(gammaDscFwd),
48 gammaBPS_(gammaBPS), fxLinkedForeignNpv_(fxLinkedForeignNpv),
49 excludeSimpleCashFlowsFromSensis_(excludeSimpleCashFlowsFromSensis), simpleCashFlowNpv_(simpleCashFlowNpv) {}
std::map< std::pair< Date, Date >, Real > & gammaDscFwd_
std::map< std::pair< Date, Date >, Real > & gammaForward_

Member Function Documentation

◆ visit() [1/7]

void visit ( CashFlow &  c)
override

Definition at line 51 of file discountingswapenginedeltagamma.cpp.

51 {
52 Real dsc = discountCurve_->discount(c.date());
53 Real a = payer_ * c.amount() * dsc;
54 npv_ += a;
55 Real t = discountCurve_->timeFromReference(c.date());
56 if (computeDelta_) {
57 getMapEntry(deltaDiscount_, c.date()) += -t * a;
58 }
59 if (computeGamma_) {
60 getMapEntry(gammaDiscount_, c.date()) += t * t * a;
61 }
62}
Real & getMapEntry(std::map< Key, Real > &map, const Key &key)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ visit() [2/7]

void visit ( SimpleCashFlow &  c)
override

Definition at line 64 of file discountingswapenginedeltagamma.cpp.

64 {
66 // even when excluding the cf from the sensis we want to colect their npv contribution, but in a separate field
67 Real dsc = discountCurve_->discount(c.date());
68 Real a = payer_ * c.amount() * dsc;
70 return;
71 }
72 visit(static_cast<CashFlow&>(c));
73}
+ Here is the call graph for this function:

◆ visit() [3/7]

void visit ( FixedRateCoupon &  c)
override

Definition at line 75 of file discountingswapenginedeltagamma.cpp.

75 {
76 Real dsc = discountCurve_->discount(c.date());
77 Real a = payer_ * c.amount() * dsc;
78 npv_ += a;
79 Real t = discountCurve_->timeFromReference(c.date());
80 if (computeDelta_) {
81 getMapEntry(deltaDiscount_, c.date()) += -t * a;
82 }
83 if (computeGamma_) {
84 getMapEntry(gammaDiscount_, c.date()) += t * t * a;
85 }
86 if (computeBPS_) {
87 Real tau = c.accrualPeriod();
88 bps_ += payer_ * c.nominal() * tau * dsc;
89 if (computeDelta_) {
90 getMapEntry(deltaBPS_, c.date()) += -t * payer_ * c.nominal() * tau * dsc;
91 }
92 if (computeGamma_) {
93 getMapEntry(gammaBPS_, c.date()) += t * t * payer_ * c.nominal() * tau * dsc;
94 }
95 }
96}
+ Here is the call graph for this function:

◆ visit() [4/7]

void visit ( IborCoupon &  c)
override

Definition at line 163 of file discountingswapenginedeltagamma.cpp.

+ Here is the call graph for this function:

◆ visit() [5/7]

void visit ( FloatingRateFXLinkedNotionalCoupon c)
override

Definition at line 165 of file discountingswapenginedeltagamma.cpp.

165 {
166 // only add to the foreign npv (and hence effectively to the fx spot delta) if the fx rate is not yet fixed
167
168 if (c.fxFixingDate() > discountCurve_->referenceDate() ||
169 (c.fxFixingDate() == discountCurve_->referenceDate() &&
170 c.fxIndex()->pastFixing(c.fxFixingDate()) == Null<Real>())) {
171 Real tmp = c.fxIndex()->forecastFixing(0.0);
172 fxLinkedForeignNpv_ += payer_ * c.amount() * discountCurve_->discount(c.date()) / tmp;
173 }
175}
+ Here is the call graph for this function:

◆ visit() [6/7]

void visit ( FXLinkedCashFlow c)
override

Definition at line 177 of file discountingswapenginedeltagamma.cpp.

177 {
178 Real dsc = discountCurve_->discount(c.date());
179 Real a = payer_ * c.amount() * dsc;
180 npv_ += a;
181 Real t = discountCurve_->timeFromReference(c.date());
182 if (computeDelta_) {
183 getMapEntry(deltaDiscount_, c.date()) += -t * a;
184 }
185 if (computeGamma_) {
186 getMapEntry(gammaDiscount_, c.date()) += t * t * a;
187 }
188 // only add to the foreign npv (and hence effectively to the fx spot delta) if the fx rate is not yet fixed
189 if (c.fxFixingDate() > discountCurve_->referenceDate() ||
190 (c.fxFixingDate() == discountCurve_->referenceDate() &&
191 c.fxIndex()->pastFixing(c.fxFixingDate()) == Null<Real>())) {
192 Real tmp = c.fxIndex()->forecastFixing(0.0);
193 Real b = a / tmp;
195 }
196}
+ Here is the call graph for this function:

◆ visit() [7/7]

void visit ( QuantExt::OvernightIndexedCoupon c)
override

Definition at line 198 of file discountingswapenginedeltagamma.cpp.

199{
201}
+ Here is the call graph for this function:

◆ processIborCoupon()

void processIborCoupon ( FloatingRateCoupon c)
private

Definition at line 98 of file discountingswapenginedeltagamma.cpp.

98 {
99 Real dsc = discountCurve_->discount(c.date());
100 Real a = payer_ * c.amount() * dsc;
101 npv_ += a;
102 Date d3 = c.date();
103 Real t3 = discountCurve_->timeFromReference(d3);
104 if (computeDelta_) {
105 getMapEntry(deltaDiscount_, d3) += -t3 * a;
106 }
107 if (computeGamma_) {
108 getMapEntry(gammaDiscount_, d3) += t3 * t3 * a;
109 }
110 if (computeBPS_) {
111 Real tau = c.accrualPeriod();
112 bps_ += payer_ * tau * c.nominal() * dsc;
113 if (computeDelta_) {
114 getMapEntry(deltaBPS_, d3) += -t3 * payer_ * tau * c.nominal() * dsc;
115 }
116 if (computeGamma_) {
117 getMapEntry(gammaBPS_, d3) += t3 * t3 * payer_ * tau * c.nominal() * dsc;
118 }
119 }
120 Date fixing = c.fixingDate();
121
122 // is it actually a floating rate coupon?
123 if (fixing > discountCurve_->referenceDate() ||
124 (fixing == discountCurve_->referenceDate() && c.index()->pastFixing(fixing) == Null<Real>())) {
125 Date d1 = c.index()->valueDate(fixing);
126 Date d2;
127 if (IborCoupon::Settings::instance().usingAtParCoupons() && fixing <= c.accrualStartDate()) {
128 // par coupon approximation
129 Date nextFixingDate =
130 c.index()->fixingCalendar().advance(c.accrualEndDate(), -static_cast<Integer>(c.fixingDays()), Days);
131 d2 = c.index()->fixingCalendar().advance(nextFixingDate, c.fixingDays(), Days);
132 } else if (IborCoupon::Settings::instance().usingAtParCoupons()) {
133 // in arreas
134 d2 = c.index()->maturityDate(d1);
135 } else {
136 // use indexed coupon
137 d2 = c.index()->maturityDate(d1);
138 }
139
140 // if the coupon is degenerated we exit early
141 if (d2 <= d1)
142 return;
143
144 Real t1 = discountCurve_->timeFromReference(d1);
145 Real t2 = discountCurve_->timeFromReference(d2);
146 Real r = payer_ * dsc *
147 (c.nominal() * c.accrualPeriod() *
148 (c.gearing() / c.index()->dayCounter().yearFraction(d1, d2) - c.spread()));
149 if (computeDelta_) {
150 getMapEntry(deltaForward_, d1) += -t1 * (a + r);
151 getMapEntry(deltaForward_, d2) += t2 * (a + r);
152 }
153 if (computeGamma_) {
154 getMapEntry(gammaForward_, std::make_pair(d1, d1)) += t1 * t1 * (a + r);
155 getMapEntry(gammaForward_, std::make_pair(d2, d2)) += t2 * t2 * (a + r);
156 getMapEntry(gammaForward_, std::make_pair(d1, d2)) += -2.0 * t1 * t2 * (a + r);
157 getMapEntry(gammaDscFwd_, std::make_pair(d3, d1)) += t1 * t3 * (a + r);
158 getMapEntry(gammaDscFwd_, std::make_pair(d3, d2)) += -t2 * t3 * (a + r);
159 }
160 }
161} // process IborCoupon
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ discountCurve_

Handle<YieldTermStructure> discountCurve_
private

Definition at line 117 of file discountingswapenginedeltagamma.hpp.

◆ payer_

const Real payer_
private

Definition at line 118 of file discountingswapenginedeltagamma.hpp.

◆ npv_

Real& npv_
private

Definition at line 119 of file discountingswapenginedeltagamma.hpp.

◆ bps_

Real & bps_
private

Definition at line 119 of file discountingswapenginedeltagamma.hpp.

◆ computeDelta_

const bool computeDelta_
private

Definition at line 120 of file discountingswapenginedeltagamma.hpp.

◆ computeGamma_

const bool computeGamma_
private

Definition at line 120 of file discountingswapenginedeltagamma.hpp.

◆ computeBPS_

const bool computeBPS_
private

Definition at line 120 of file discountingswapenginedeltagamma.hpp.

◆ deltaDiscount_

std::map<Date, Real>& deltaDiscount_
private

Definition at line 121 of file discountingswapenginedeltagamma.hpp.

◆ deltaForward_

std::map<Date, Real> & deltaForward_
private

Definition at line 121 of file discountingswapenginedeltagamma.hpp.

◆ deltaBPS_

std::map<Date, Real> & deltaBPS_
private

Definition at line 121 of file discountingswapenginedeltagamma.hpp.

◆ gammaDiscount_

std::map<Date, Real> & gammaDiscount_
private

Definition at line 121 of file discountingswapenginedeltagamma.hpp.

◆ gammaForward_

std::map<std::pair<Date, Date>, Real>& gammaForward_
private

Definition at line 122 of file discountingswapenginedeltagamma.hpp.

◆ gammaDscFwd_

std::map<std::pair<Date, Date>, Real> & gammaDscFwd_
private

Definition at line 122 of file discountingswapenginedeltagamma.hpp.

◆ gammaBPS_

std::map<Date, Real>& gammaBPS_
private

Definition at line 123 of file discountingswapenginedeltagamma.hpp.

◆ fxLinkedForeignNpv_

Real& fxLinkedForeignNpv_
private

Definition at line 124 of file discountingswapenginedeltagamma.hpp.

◆ excludeSimpleCashFlowsFromSensis_

const bool excludeSimpleCashFlowsFromSensis_
private

Definition at line 125 of file discountingswapenginedeltagamma.hpp.

◆ simpleCashFlowNpv_

Real& simpleCashFlowNpv_
private

Definition at line 126 of file discountingswapenginedeltagamma.hpp.