Dear QuantLib users,
I'm trying to figure out how to use qlBucketAnalysis. It seems that there is not so much working samples and literature on the function even in Workbooks.
After digging in the source codes and spending a couple of days, I'm asking for help.
For some reasons, qlBucketAnalysis always returns 0 as delta and gamma values. When qlBucketAnalysis is called, it eventually gets to sensitivityanalysis.cpp. In there,
pair<Real, Real>
bucketAnalysis(Handle<SimpleQuote> quote,
const vector<shared_ptr<Instrument> >& instruments,
const vector<Real>& quantities,
Real shift,
SensitivityAnalysis type,
Real referenceNpv)
{
QL_REQUIRE(shift!=0.0, "zero shift not allowed");
pair<Real, Real> result(0.0, 0.0);
if (instruments.empty()) return result;
if (referenceNpv==Null<Real>())
referenceNpv = aggregateNPV(instruments, quantities);
if (!quote->isValid()) return result;
Real quoteValue = quote->value();
try {
quote->setValue(quoteValue+shift);
Real npv = aggregateNPV(instruments, quantities);
switch (type) {
case OneSide:
result.first = (npv-referenceNpv)/shift;
result.second = Null<Real>();
break;
case Centered:
{
quote->setValue(quoteValue-shift);
Real npv2 = aggregateNPV(instruments, quantities);
result.first = (npv-npv2)/(2.0*shift);
result.second = (npv-2.0*referenceNpv+npv2)/(shift*shift);
}
break;
default:
QL_FAIL("unknown SensitivityAnalysis (" <<
Integer(type) << ")");
}
quote->setValue(quoteValue);
} catch (...) {
quote->setValue(quoteValue);
throw;
}
return result;
}
So the story goes that delta is being calculated based on the difference between npv2 and npv. I guess that after the shifted quote value is set, quantlib newly calculates npv2. The problem is that no matter what shifted values are set, the same value as in npv is returned for npv2.
I think I must have misused the function. Would appreciate for any tips.
The attached is the xlsm file with vbas and quantlib functions.
Thanks in advance.
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users