IborIndex and valuation of swaps

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

IborIndex and valuation of swaps

dhoorens
Hi
Is there an easy way to determine the floating rate of a swap instead of specifying an ibor Index?
I try to make my computations with NullCalendar and SimpleDayCounter and I face the problems that often my settlement is on sunday => error..


What I tried (to give as input my floating rate) is the following, but I don't know if it is
* efficient
* robust

I think my problem is in the 6 last lines of this code

boost::shared_ptr<QuantLib::VanillaSwap> toVanillaSwap( char* type,
                                                                                                                double nominal,
                                                                                                                QuantLib::Date issueDate,
                                                                                                                QuantLib::Date maturityDate,
                                                                                                                QuantLib::Calendar calendar,
                                                                                                                QuantLib::DayCounter dayCounter,
                                                                                                                double spread,
                                                                                                                double fixRate,
                                                                                                                QuantLib::Frequency fixFrequency,
                                                                                                                QuantLib::Calendar fixCalendar,
                                                                                                                QuantLib::DayCounter fixDayCounter,
                                                                                                                double fltRate,
                                                                                                                int fltIndexTenor,
                                                                                                                QuantLib::Frequency fltFrequency,
                                                                                                                QuantLib::Calendar fltCalendar,
                                                                                                                QuantLib::DayCounter fltDayCounter,
                                                                                                                QuantLib::Handle<QuantLib::YieldTermStructure> yTS){

        BusinessDayConvention fixConvention = Unadjusted;
        BusinessDayConvention fixTerminationDateConvention = Unadjusted;
        DateGeneration::Rule fixRule = DateGeneration::Backward;
        bool fixEndOfMonth = false;

        BusinessDayConvention fltConvention = Unadjusted;
        BusinessDayConvention fltTerminationDateConvention = Unadjusted;
        DateGeneration::Rule fltRule = DateGeneration::Backward;
        bool fltEndOfMonth = false;


        Schedule fixSchedule(issueDate,
                                                 maturityDate,
                                                 Period(fixFrequency),
                                                 fixCalendar,
                                                 fixConvention,
                                                 fixTerminationDateConvention,
                                                 fixRule,
                                                 fixEndOfMonth);
        Schedule fltSchedule(issueDate,
                                                 maturityDate,
                                                 Period(fltFrequency),
                                                 fltCalendar,
                                                 fltConvention,
                                                 fltTerminationDateConvention,
                                                 fltRule,
                                                 fltEndOfMonth);

        std::string familyName = "";
        Period tenor (fltIndexTenor, Months);
        int settlementDays = 0;
        Currency currency = QuantLib::EURCurrency();
        Calendar fixingCalendar = fltCalendar;
        BusinessDayConvention convention = Unadjusted;
        bool endOfMonth = false;



        boost::shared_ptr<IborIndex> iborIndex ;
        iborIndex =  boost::shared_ptr<IborIndex>(
                new IborIndex(familyName,
                                          tenor,
                                          settlementDays,
                                          currency,
                                          fixingCalendar,
                                          convention,
                                          endOfMonth,
                                          fltDayCounter,
                                          yTS));

        std::string s(type);
        s = s.substr(0,1);
        std::transform(s.begin(), s.end(), s.begin(), ::toupper);

        QuantLib::VanillaSwap::Type typ;
        if (s == "R")
                typ = QuantLib::VanillaSwap::Receiver;
        else if (s == "P")
                typ = QuantLib::VanillaSwap::Payer;
        else
                throw (std::string("unknwown type of Swap"));

        boost::shared_ptr<VanillaSwap>sw;
        sw = boost::shared_ptr<VanillaSwap>(
                new VanillaSwap(typ,
                                                nominal,
                                                fixSchedule,
                                                fixRate,
                                                fixDayCounter,
                                                fltSchedule,
                                                iborIndex,
                                                spread,
                                                fltDayCounter));



        boost::shared_ptr<YieldTermStructure> yts =yTS.currentLink();
        Date refDate = yts->referenceDate();

        Date prevFixDate = (*(CashFlows::previousCashFlow(sw->floatingLeg(), refDate)))->date();
        if(!iborIndex->isValidFixingDate(prevFixDate))
                prevFixDate = fltCalendar.adjust(prevFixDate, Preceding);
        iborIndex->addFixing(prevFixDate, fltRate, true);

        return sw;


}
Reply | Threaded
Open this post in threaded view
|

Re: IborIndex and valuation of swaps

dhoorens
Actually my question is more general
Suppose I have to price a swap at 31/12/2008
The only informations I have are the yieldCurve at 31/12/2008 and the characteristics of the swap (notional, fixrate, index followed by floating leg, maturity (frequencies of both legs are annual))

How can be the floating rate used for next coupon be determined by these informations?
My idea was "it must be an input".. but i"m not sure
Tks
David
Reply | Threaded
Open this post in threaded view
|

Re: IborIndex and valuation of swaps

Lluis Pujol Bajador
In reply to this post by dhoorens

I don't really understand the question but if you try to obtain next floating coupons in order to value a swap then:


  • You can value the Swap without knowing the next floating coupon as the floating leg will be 100% plus accrued coupon in the next payment date, you just need to discount it.
  • You could obtain the next coupon date from the Forward curve implied in the current curve. To value the swap just discount the cash flows.
Both ways should give you same result.

Anyway I don't thing you need to do anyhing like that, just use built-in Quantlib functions. just look at the swap example.


LluĂ­s


On Wed 15/07/09 09:42 , dhoorens <[hidden email]> wrote:


Actually my question is more general
Suppose I have to price a swap at 31/12/2008
The only informations I have are the yieldCurve at 31/12/2008 and the
characteristics of the swap (notional, fixrate, index followed by floating
leg, maturity (frequencies of both legs are annual))

How can be the floating rate used for next coupon be determined by these
informations?
My idea was "it must be an input".. but i"m not sure
Tks
David

--
View this message in context: http://www.nabble.com/IborIndex-and-valuation-of-swaps-tp24477501p24493303.html">http://www.nabble.com/IborIndex-and-valuation-of-swaps-tp24477501p24493303.html
Sent from the quantlib-users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge">http://p.sf.net/sfu/Challenge
_______________________________________________
QuantLib-users mailing list
<a href="javascript:top.opencompose('QuantLib-users@lists.sourceforge.net','','','1')">QuantLib-users@...
https://lists.sourceforge.net/lists/listinfo/quantlib-users


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

_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: IborIndex and valuation of swaps

Luigi Ballabio
In reply to this post by dhoorens
On Wed, 2009-07-15 at 00:42 -0700, dhoorens wrote:
> Actually my question is more general
> Suppose I have to price a swap at 31/12/2008
> The only informations I have are the yieldCurve at 31/12/2008 and the
> characteristics of the swap (notional, fixrate, index followed by floating
> leg, maturity (frequencies of both legs are annual))
>
> How can be the floating rate used for next coupon be determined by these
> informations?
> My idea was "it must be an input".. but i"m not sure

If the floating coupon already started, you're right---it's an input,
since it can't be retrieved from today's curve.  From your previous
mail, I see you already figured that it should be stored with the
Index::addFixing method. To get the correct date, I'd do something like:

boost::shared_ptr<CashFlow> currentCoupon = ...;
boost::shared_ptr<FloatingRateCoupon> flt =
    boost::dynamic_pointer_cast<FloatingRateCoupon>(currentCoupon);
iborIndex->addFixing(flt->fixingDate(), ...);

Luigi




--

A programming language is low-level when its programs require attention
to the irrelevant.
-- Alan Perlis



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users