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 ------------------------------------------------------------------------------ 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 QL_Swap_Stripped_20130618.zip (58K) Download Attachment |
I have the same issue with qlbucketanalysis().
I have built a yield curve using rateHelpers and qlPiecewiseYieldCurve(). How do I create a link between the simpleQuote objects that are shifted in qlbucketanalysis() and my yield curve object? In other words, how does the yield curve know it has been perturbed by qlbucketanalysis()? Right now I get 0 delta, just like Hyung-Seok. Intuitively I think I should construct each rateHelper using a simplequote as a parameter, but that is not supported. I have tried using triggers to force a link between the rateHelpers and simpleQuotes, but that does not work either. Can someone give some direction or post an example? Thank You, Carl Schmidt |
Using a SimpleQuote as a parameter of RateHelper is definitely supported. I've done that and it works for me.
If I am not mistaken, qlBucketAnalysis wants as its first argument the SimpleQuote to be perturbed, and as second argument an instrument whose NPV depends on that. For example it may be a VanillaSwap priced on a DiscountingSwapEngine based on your yield curve. I don't think you can pass the yield curve itself as the second argument, if that's what you tried to do. The yield curve "knows" it has been perturbed because qlBucketAnalysis actually changes the value of the SimpleQuote, and then restores the original value when it's over. Indeed, if you are running your spreadsheet on a multicore computer (which you most likely are unless your PC is several years old), Excel may evaluate multiple cells at once and since the change to the SimpleQuote is NOT local to qlBucketAnalysis, it may alter the result of other function calls running in parallel with it. At the moment I haven't a simple example that I can post, but if you need it, I may try to build one. Gerardo Ballabio Risk Management Banca Profilo S.p.A. Via Cerva 28 - 20122 Milano Tel. +39 02 58408.463 www.bancaprofilo.it -----Messaggio originale----- Da: Carl [mailto:[hidden email]] Inviato: martedì 22 aprile 2014 14.13 A: [hidden email] Oggetto: Re: [Quantlib-users] qlBucketAnalysis always returns 0 for delta and gamma I have the same issue with qlbucketanalysis(). I have built a yield curve using rateHelpers and qlPiecewiseYieldCurve(). How do I create a link between the simpleQuote objects that are shifted in qlbucketanalysis() and my yield curve object? In other words, how does the yield curve know it has been perturbed by qlbucketanalysis()? Right now I get 0 delta, just like Hyung-Seok. Intuitively I think I should construct each rateHelper using a simplequote as a parameter, but that is not supported. I have tried using triggers to force a link between the rateHelpers and simpleQuotes, but that does not work either. Can someone give some direction or post an example? Thank You, Carl Schmidt -- View this message in context: http://quantlib.10058.n7.nabble.com/qlBucketAnalysis-always-returns-0-for-delta-and-gamma-tp14382p15178.html Sent from the quantlib-users mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Start Your Social Network Today - Download eXo Platform Build your Enterprise Intranet with eXo Platform Software Java Based Open Source Intranet - Social, Extensible, Cloud Ready Get Started Now And Turn Your Intranet Into A Collaboration Platform http://p.sf.net/sfu/ExoPlatform _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head></head> <body> <div style="font-family:Calibri;font-size:10px"> Banca Profilo S.p.A. Via Cerva, 28 - 20122 Milano - Tel. 02 58408.1, Fax 02 5831 6057 Capitale Sociale Euro 136.794.106,00 i.v. Iscrizione al Registro Imprese di Milano, C.F. e P.IVA 09108700155 - [hidden email] Iscritta all’Albo delle Banche e dei Gruppi bancari Aderente al Fondo Interbancario di Tutela dei depositi Aderente al Conciliatore Bancario Finanziario e all’Arbitro Bancario Finanziario Appartenente al Gruppo bancario Banca Profilo e soggetta all’attività di direzione e coordinamento di Arepo BP S.p.A. DISCLAIMER: The information transmitted may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. </div> </body> </html> ------------------------------------------------------------------------------ Start Your Social Network Today - Download eXo Platform Build your Enterprise Intranet with eXo Platform Software Java Based Open Source Intranet - Social, Extensible, Cloud Ready Get Started Now And Turn Your Intranet Into A Collaboration Platform http://p.sf.net/sfu/ExoPlatform _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
I might be able to help next week. I've prepared such an example for one of my students´ thesis, slightly modifying one of the standalone example that I will contribute back on git On Apr 22, 2014 3:43 PM, "Ballabio Gerardo" <[hidden email]> wrote:
Using a SimpleQuote as a parameter of RateHelper is definitely supported. I've done that and it works for me. ------------------------------------------------------------------------------ Start Your Social Network Today - Download eXo Platform Build your Enterprise Intranet with eXo Platform Software Java Based Open Source Intranet - Social, Extensible, Cloud Ready Get Started Now And Turn Your Intranet Into A Collaboration Platform http://p.sf.net/sfu/ExoPlatform _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Thank you, but Gerardo's email was enough for me to figure it out. I didn't know I could pass a simpleQuote to a rateHelper, which then provided the link between the sensitivity function and the curve. I am calculating reasonable results now, although I have had to set the "quantities" parameter in qlbucketanalysis() to 1/10000 (not sure why, but it works for all of my swaps). Thank you.On Tue, Apr 22, 2014 at 2:55 PM, Ferdinando M. Ametrano <[hidden email]> wrote:
------------------------------------------------------------------------------ Start Your Social Network Today - Download eXo Platform Build your Enterprise Intranet with eXo Platform Software Java Based Open Source Intranet - Social, Extensible, Cloud Ready Get Started Now And Turn Your Intranet Into A Collaboration Platform http://p.sf.net/sfu/ExoPlatform _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
1/10000 is one basis point, that’s the unit against which sensitivities are ordinarily calculated. Gerardo Gerardo Ballabio Risk Management Banca Profilo S.p.A.
Via Cerva 28 - 20122 Milano
Tel. +39 02 58408.463 Da: Carl S. [mailto:[hidden email]]
Thank you, but Gerardo's email was enough for me to figure it out. I didn't know I could pass a simpleQuote to a rateHelper, which then provided the link between the sensitivity function and the curve. I am
calculating reasonable results now, although I have had to set the "quantities" parameter in qlbucketanalysis() to 1/10000 (not sure why, but it works for all of my swaps). Thank you. On Tue, Apr 22, 2014 at 2:55 PM, Ferdinando M. Ametrano <[hidden email]> wrote: I might be able to help next week. I've prepared such an example for one of my students´ thesis, slightly modifying one of the standalone example that I will contribute back on git On Apr 22, 2014 3:43 PM, "Ballabio Gerardo" <[hidden email]> wrote: Using a SimpleQuote as a parameter of RateHelper is definitely supported. I've done that and it works for me.
------------------------------------------------------------------------------ Start Your Social Network Today - Download eXo Platform Build your Enterprise Intranet with eXo Platform Software Java Based Open Source Intranet - Social, Extensible, Cloud Ready Get Started Now And Turn Your Intranet Into A Collaboration Platform http://p.sf.net/sfu/ExoPlatform _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Sensitivities are finite difference derivatives, the shift used is an input, the default input is 0.0001. On Apr 23, 2014 8:58 AM, "Ballabio Gerardo" <[hidden email]> wrote:
------------------------------------------------------------------------------ Start Your Social Network Today - Download eXo Platform Build your Enterprise Intranet with eXo Platform Software Java Based Open Source Intranet - Social, Extensible, Cloud Ready Get Started Now And Turn Your Intranet Into A Collaboration Platform http://p.sf.net/sfu/ExoPlatform _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by Hyung-Seok Hahm
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:
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 ------------------------------------------------------------------------------ Time is money. Stop wasting it! Get your web API in 5 minutes. www.restlet.com/download http://p.sf.net/sfu/restlet _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users qlBucketAnalysis_resolved.xlsm (81K) Download Attachment |
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 |
Free forum by Nabble | Edit this page |