Swap start date and length

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Swap start date and length

navin mehta
Given a swap object, how can I get the start date and length ? (I tried to find it in the heirarchy,and even the Swaphelper, but could not find any public method)


Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
Reply | Threaded
Open this post in threaded view
|

Re: Swap start date and length

Xavier.Abulker
Hi Navin,
For the maturitry I had the same issue last week and this is what I did:

/// I define the Swap
SimpleSwap spot5YearSwap(payFixedRate, spotDate, lenghtInYears,
            Years, calendar, roll, nominal, fixedLegFrequency, fixedRate,
            fixedLegIsAdjusted, fixedLegDayCounter, floatingLegFrequency,
            euriborIndex, fixingDays, spread,
            discountingTermStructure); // using the discounting curve


std::cout <<  " The swap maturity is: "
<<DateFormatter::toString(spot5YearSwap.maturity())<< std::endl;

Now for the start date I don't know either.
It looks it's missing in the list of the class inspectors.
You should create your own method to access this argument of the SimpleSwap
class and propose it to Quantlib.

I hope it helps a little bit.
Xavier


                                                                                                                     
                    navin mehta                                                                                      
                    <[hidden email]>                To:     [hidden email]              
                    Sent by:                               cc:                                                      
                    [hidden email]       Subject:     [Quantlib-users] Swap start date and length  
                    eforge.net                                                                                      
                                                                                                                     
                                                                                                                     
                    09/09/2003 00:49                                                                                
                                                                                                                     
                                                                                                                     




Given a swap object, how can I get the start date and length ? (I tried to
find it in the heirarchy,and even the Swaphelper, but could not find any
public method)


Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software








*************************************************************************
Ce message et toutes les pieces jointes (ci-apres le "message") sont
confidentiels et etablis a l'intention exclusive de ses destinataires.
Toute utilisation ou diffusion non autorisee est interdite.
Tout message electronique est susceptible d'alteration.
La Fimat et ses filiales declinent toute responsabilite au
titre de ce message s'il a ete altere, deforme ou falsifie.
                    ********
This message and any attachments (the "message") are confidential and
intended solely for the addressees.
Any unauthorised use or dissemination is prohibited.
E-mails are susceptible to alteration.
Neither Fimat nor any of its subsidiaries or affiliates shall
be liable for the message if altered, changed or falsified.
*************************************************************************



Reply | Threaded
Open this post in threaded view
|

Re: Swap start date and length

Luigi Ballabio-2
In reply to this post by navin mehta
At 03:49 PM 9/8/03 -0700, navin mehta wrote:
>Given a swap object, how can I get the start date and length ? (I tried to
>find it in the heirarchy,and even the Swaphelper, but could not find any
>public method)

Navin,
         I'm afraid this has been overlooked. You'll need either to change
the source files, or rely on some arcane incantation as the one I'm writing
below.
Would you mind filing this into the Feature Request page on Sourceforge
(http://sourceforge.net/tracker/?group_id=12740&atid=362740) so that we
don't forget to include a solution in next release?

Thanks,
         Luigi

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

#include <ql/Instruments/swap.hpp>
#include <ql/CashFlows/coupon.hpp>

namespace QuantLib {

     namespace Instruments {

         /* This class below inherits from Swap in order to gain access
            to its protected members.
            Don't try this kind of hacks at home.

            Oh, and did I mention this isn't tested?
         */
         class SwapInspector : public Swap {
           private:
             // we don't really want to instantiate this
             SwapInspector()
             : Swap(std::vector<Handle<CashFlow> >(),
                    std::vector<Handle<CashFlow> >(),
                    RelinkableHandle<TermStructure>()) {}
           public:
             // return the start date of the first coupon
             static Date startDate(const Swap& swap) {
                 // get the first cash flow
                 Handle<CashFlow> firstCF = swap.firstLeg_.front();
                 try {
                     // is this a coupon?
                     Handle<CashFlows::Coupon> coupon = firstCF;
                     // ok, return its start date
                     return coupon.accrualStartDate();
                 } catch (Error&) {
                     // it was not a coupon. We'll doctor the
                     // error message to make it more readable.
                     throw Error("The swap coupons did not provide "
                                 "enough information");
                 }
             }
             // return the end date of the last coupon
             static Date endDate(const Swap& swap) {
                 Handle<CashFlow> lastCF = swap.firstLeg_.back();
                 try {
                     Handle<CashFlows::Coupon> coupon = lastCF;
                     return coupon.accrualEndDate();
                 } catch (Error&) {
                     throw Error("The swap coupons did not provide "
                                 "enough information");
                 }
             }
         };

     }

}