Login  Register

Irritated about dates in DiscountingSwapEngine

Posted by Henner Heck on Jan 24, 2011; 5:03pm
URL: http://quantlib.414.s1.nabble.com/Irritated-about-dates-in-DiscountingSwapEngine-tp12035.html



Hello all,

first of i would like to thank the people responsible,
especially Luigi and Ferdinando, for the forum last
week in London. I enjoyed it.

Now my question about swap evaluation:

QuantLib version: 1.0.1

In "QuantLib::DiscountingSwapEngine" the settlement and evaluation dates are determined as follows:

------------------------------------------------------------------------------------
Date refDate = (*discountCurve_)->referenceDate();

Date settlementDate = settlementDate_;
  if (settlementDate_==Date()) {
settlementDate = refDate;
} else {
QL_REQUIRE(settlementDate>=refDate,
"settlement date (" << settlementDate << ") before "
"discount curve reference date (" << refDate << ")");
}

results_.valuationDate = npvDate_;
if (npvDate_==Date()) {
results_.valuationDate = refDate;
} else {
QL_REQUIRE(npvDate_>=refDate,
"npv date (" << npvDate_ << ") before "
"discount curve reference date (" << refDate << ")");
}

------------------------------------------------------------------------------------

Via SWIG i have one constructor available, which sets the discounting termstructure
only. So the dates npvDate_ and refDate_ are initially "Date()" at the beginning of
the above code. So they both default to "refDate" which is the reference date of the discounting curve.

I tried to get the full constructor into the SWIG code, but until now
i always had errors in the automatically created C++ wrapper code regarding the
definition of optional parameters.

Anyways, a little later  "CashFlows::npv" is called:

------------------------------------------------------------------------------------
CashFlows::npv(arguments_.legs[i],
**discountCurve_,
includeRefDateFlows,
settlementDate,
results_.valuationDate);
------------------------------------------------------------------------------------

The default settings for the dates there are as follows:

------------------------------------------------------------------------------------
if (settlementDate == Date())
settlementDate = Settings::instance().evaluationDate();

if (npvDate == Date())
npvDate = settlementDate;

Real totalNPV = 0.0;
for (Size i=0; i<leg.size(); ++i) {
if (!leg[i]->hasOccurred(settlementDate,
includeSettlementDateFlows))
totalNPV += leg[i]->amount() *
discountCurve.discount(leg[i]->date());
}

return totalNPV/discountCurve.discount(npvDate);
------------------------------------------------------------------------------------

So every time i run a swap evaluation using the DiscountingSwapEngine,
the Settings::evaluationDate is totally ignored, since all dates are set to the
reference date of the discounting curve.
That leads to really unwanted behavior, if the the curve's reference date is earlier
than the Settings::evaluationDate and there are cashflows in between.
Now even the cashflows placed before Settings::evaluationDate a included into
the NPV.

So why is the default date in DiscountingSwapEngine
(*discountCurve_)->referenceDate();
and not
Settings::instance().evaluationDate(); ?

If this is not an error, i would appreciate any help getting the full constructor of
DiscountingSwapEngine (discountCurve, includeSettlementDateFlows, settlementDate, npvDate)
to work in SWIG or to evaluate a VanillaSwap without using DiscountingSwapEngine.

Best regards,
Henner Heck




------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev