Re: qlBucketAnalysis always returns 0 for delta and gamma

Posted by Eric Ehlers-2 on
URL: http://quantlib.414.s1.nabble.com/qlBucketAnalysis-always-returns-0-for-delta-and-gamma-tp14382p15440.html

Many thanks for sharing your example, I added the workbook to git for  
inclusion in the upcoming release of QuantLibXL 1.4.

Kind Regards,
Eric

Quoting Hyung-Seok Hahm <[hidden email]>:

> Dear all,
>
> I guess it has been already resolved, but for those who needs a concrete
> working sample, I provide one here.
>
> So the key is that one has to use a SimpleQuote parameter in the
> qlBucketAnalysis, which has been used to build a forward curve.
>
> Thank you all for the useful comments.
>
> Best,
>
> Hyungseok
>
>
> On Wed, Jun 19, 2013 at 2:24 PM, Hyung-Seok Hahm
> <[hidden email]>wrote:
>
>> 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.
>>
>>
>>
>> --
>>
>> *Hyungseok Hahm, PhD, FRM   *
>>
>>
>>
>
>
> --
>
> *Hyungseok Hahm, PhD, FRM   *
>
> Quantitative Analyst
>
> Industrial Bank of Korea
>
> Tel      : 82-2-729-7081
>
> E-mail  : [hidden email]
>
> LinkedIn: http://kr.*linkedin*.com/pub/dir/*Hyung-seok*/*Hahm*


===================================================
Eric Ehlers
nazcatech sprl | Brussels | http://www.nazcatech.be
* Distributed computing for pricing analytics
* Use Microsoft Excel as a client to the Grid


------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users