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

Discounting swap engine providing analytical deltas and gammas. More...

#include <qle/pricingengines/discountingswapenginedeltagamma.hpp>

+ Inheritance diagram for DiscountingSwapEngineDeltaGamma:
+ Collaboration diagram for DiscountingSwapEngineDeltaGamma:

Public Member Functions

 DiscountingSwapEngineDeltaGamma (const Handle< YieldTermStructure > &discountCurve=Handle< YieldTermStructure >(), const std::vector< Time > &bucketTimes=std::vector< Time >(), const bool computeDelta=false, const bool computeGamma=false, const bool computeBPS=false, const bool linearInZero=true)
 
void calculate () const override
 
Handle< YieldTermStructure > discountCurve () const
 

Private Attributes

Handle< YieldTermStructure > discountCurve_
 
const std::vector< Real > bucketTimes_
 
const bool computeDelta_
 
const bool computeGamma_
 
const bool computeBPS_
 
const bool linearInZero_
 

Detailed Description

Discounting swap engine providing analytical deltas and gammas.

The provided deltas and gammas are (continuously compounded) zero yield deltas assuming linear in zero or loglinear in discount factor interpolation on the discounting and forwarding curves with flat extrapolation of the zero rate before the first and last bucket time. The deltas are provided as additional results

deltaDiscount (vector<Real> ): Delta on discount curve, rebucketed on time grid deltaForward (vector<Real> ): Delta on forward curve, rebucketed on time grid deltaBPS (vector<vector<Real>> ): Delta of BPS (on discount curve, per leg)

The gammas, likewise,

gamma (Matrix ): Gamma matrix with blocks | dsc-dsc dsc-fwd | | dsc-fwd fwd-fwd | gammaBps (vector<Matrix> ): Gamma of BPS (on dsc, per leg)

bucketTimes (vector<Real> ): Bucketing grid for deltas and gammas

Warning:
Deltas and gammas are produced only for fixed and Ibor coupons without caps or floors, for Ibor coupons they are ignoring convexity adjustments (like in arrears adjustments). It is possible to have different Ibor coupons (with different forward curves) on a leg, but the computed deltas would be aggregated over all underlying curves then.
Warning:

Derivatives are not w.r.t. basispoints, but w.r.t. the usual unit

BPS is the value of one unit (not one basispoint actually), it has to be divided by 10000.0 to get QL's BPS

Definition at line 70 of file discountingswapenginedeltagamma.hpp.

Constructor & Destructor Documentation

◆ DiscountingSwapEngineDeltaGamma()

DiscountingSwapEngineDeltaGamma ( const Handle< YieldTermStructure > &  discountCurve = Handle<YieldTermStructure>(),
const std::vector< Time > &  bucketTimes = std::vector<Time>(),
const bool  computeDelta = false,
const bool  computeGamma = false,
const bool  computeBPS = false,
const bool  linearInZero = true 
)

Definition at line 375 of file discountingswapenginedeltagamma.cpp.

379 : discountCurve_(discountCurve), bucketTimes_(bucketTimes), computeDelta_(computeDelta),
380 computeGamma_(computeGamma), computeBPS_(computeBPS), linearInZero_(linearInZero) {
381 registerWith(discountCurve_);
382 QL_REQUIRE(!bucketTimes_.empty() || (!computeDelta && !computeGamma),
383 "bucket times are empty, although sensitivities have to be calculated");
384}

Member Function Documentation

◆ calculate()

void calculate ( ) const
override

Definition at line 386 of file discountingswapenginedeltagamma.cpp.

386 {
387 QL_REQUIRE(!discountCurve_.empty(), "discounting term structure handle is empty");
388
389 // compute npv and raw deltas
390
391 results_.value = 0.0;
392 results_.errorEstimate = Null<Real>();
393 results_.legNPV.resize(arguments_.legs.size());
394 if (computeBPS_)
395 results_.legBPS.resize(arguments_.legs.size());
396
397 std::map<Date, Real> deltaDiscountRaw, deltaForwardRaw, gammaDiscountRaw;
398 std::map<std::pair<Date, Date>, Real> gammaForwardRaw, gammaDscFwdRaw;
399
400 std::vector<std::vector<Real>> deltaBPS;
401 std::vector<Matrix> gammaBPS;
402
403 Real empty = 0.0;
404
405 for (Size j = 0; j < arguments_.legs.size(); ++j) {
406 Real npv = 0.0, bps = 0.0;
407 std::map<Date, Real> deltaBPSRaw, gammaBPSRaw; // these results are per leg
408 detail::NpvDeltaGammaCalculator calc(discountCurve_, arguments_.payer[j], npv, bps, computeDelta_,
409 computeGamma_, computeBPS_, deltaDiscountRaw, deltaForwardRaw, deltaBPSRaw,
410 gammaDiscountRaw, gammaForwardRaw, gammaDscFwdRaw, gammaBPSRaw, empty,
411 false, empty);
412 Leg& leg = arguments_.legs[j];
413 for (Size i = 0; i < leg.size(); ++i) {
414 CashFlow& cf = *leg[i];
415 if (cf.date() <= discountCurve_->referenceDate()) {
416 continue;
417 }
418 cf.accept(calc);
419 }
420 results_.legNPV[j] = npv;
421 results_.value += npv;
422 if (computeBPS_) {
423 std::map<std::pair<Date, Date>, Real> empty;
424 results_.legBPS[j] += bps;
425 // bps delta and gamma are per leg, i.e. we have to compute delta and gamma already here,
426 // the result vectors are then set below where the rest of the delta / gamma computation is done
427 std::vector<Real> tmp = detail::rebucketDeltas(bucketTimes_, deltaBPSRaw, discountCurve_->referenceDate(),
428 discountCurve_->dayCounter(), linearInZero_);
429 deltaBPS.push_back(tmp);
430 Matrix tmp2 =
431 detail::rebucketGammas(bucketTimes_, gammaBPSRaw, empty, empty, false, discountCurve_->referenceDate(),
432 discountCurve_->dayCounter(), linearInZero_);
433 gammaBPS.push_back(tmp2);
434 }
435 }
436
437 // convert raw deltas to given bucketing structure
438
439 results_.additionalResults["bucketTimes"] = bucketTimes_;
440
441 if (computeDelta_) {
442 std::vector<Real> deltaDiscount =
443 detail::rebucketDeltas(bucketTimes_, deltaDiscountRaw, discountCurve_->referenceDate(),
444 discountCurve_->dayCounter(), linearInZero_);
445 std::vector<Real> deltaForward =
446 detail::rebucketDeltas(bucketTimes_, deltaForwardRaw, discountCurve_->referenceDate(),
447 discountCurve_->dayCounter(), linearInZero_);
448
449 results_.additionalResults["deltaDiscount"] = deltaDiscount;
450 results_.additionalResults["deltaForward"] = deltaForward;
451 if (computeBPS_) {
452 results_.additionalResults["deltaBPS"] = deltaBPS;
453 }
454 }
455
456 // convert raw gammas to given bucketing structure
457
458 if (computeGamma_) {
459 Matrix gamma =
460 detail::rebucketGammas(bucketTimes_, gammaDiscountRaw, gammaForwardRaw, gammaDscFwdRaw, true,
461 discountCurve_->referenceDate(), discountCurve_->dayCounter(), linearInZero_);
462 results_.additionalResults["gamma"] = gamma;
463 if (computeBPS_) {
464 results_.additionalResults["gammaBPS"] = gammaBPS;
465 }
466 }
467
468} // calculate()
const Instrument::results * results_
Definition: cdsoption.cpp:81
Matrix rebucketGammas(const std::vector< Time > &gammaTimes, const std::map< Date, Real > &gammaDscRaw, std::map< std::pair< Date, Date >, Real > &gammaForward, std::map< std::pair< Date, Date >, Real > &gammaDscFwd, const bool forceFullMatrix, const Date &referenceDate, const DayCounter &dc, const bool linearInZero)
std::vector< Real > rebucketDeltas(const std::vector< Time > &deltaTimes, const std::map< Date, Real > &deltaRaw, const Date &referenceDate, const DayCounter &dc, const bool linearInZero)
Swap::arguments * arguments_
+ Here is the call graph for this function:

◆ discountCurve()

Handle< YieldTermStructure > discountCurve ( ) const

Definition at line 77 of file discountingswapenginedeltagamma.hpp.

77{ return discountCurve_; }

Member Data Documentation

◆ discountCurve_

Handle<YieldTermStructure> discountCurve_
private

Definition at line 80 of file discountingswapenginedeltagamma.hpp.

◆ bucketTimes_

const std::vector<Real> bucketTimes_
private

Definition at line 81 of file discountingswapenginedeltagamma.hpp.

◆ computeDelta_

const bool computeDelta_
private

Definition at line 82 of file discountingswapenginedeltagamma.hpp.

◆ computeGamma_

const bool computeGamma_
private

Definition at line 82 of file discountingswapenginedeltagamma.hpp.

◆ computeBPS_

const bool computeBPS_
private

Definition at line 82 of file discountingswapenginedeltagamma.hpp.

◆ linearInZero_

const bool linearInZero_
private

Definition at line 82 of file discountingswapenginedeltagamma.hpp.