Valuating a swap with a manually set first fixing on the floating leg

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

Valuating a swap with a manually set first fixing on the floating leg

Henner Heck

Hello all,

i have been successfully using QuantLib 1.0.1 with the SWIG-interface out  
of Java to
implement the valuation of a Vanilla-Swap. It is naturally quite similar  
to the
swapvaluation example delivered with QuantLib.

Another swap i want to valuate now is slightly different to the vanilla  
swap.
The first period of the floating leg is a short stub whose fixing is not  
derived
 from the forecasting term structure but is set manually to e.g. 0.5%.

I tried to do this with "addFixing" to the floating leg, which seems to  
work well,
if my valuation date "today" is later than the first fixing date for the  
floating leg.
If "today" is equal to that date, the first cashflow looks as expected (it  
fits the 0.5%),
but some of the later cashflows also have different amounts, which should  
not happen.
If "today" is before the first fixing date, the manual fixing seems to  
have no effect.

Am i taking the wrong approach?
If so, what would be the right one?


Best regards,
Henner Heck

------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a
Billion" shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Valuating a swap with a manually set first fixing on the floating leg

Luigi Ballabio
Hi Henner,

On Mon, 2010-11-08 at 18:47 +0100, Henner Heck wrote:
> Another swap i want to valuate now is slightly different to the
> vanilla swap. The first period of the floating leg is a short stub
> whose fixing is not derived from the forecasting term structure but is
> set manually to e.g. 0.5%.

So it's a fixed short coupon, not a floating one, right?

> I tried to do this with "addFixing" to the floating leg, which seems
> to work well, if my valuation date "today" is later than the first
> fixing date for the floating leg.
> If "today" is equal to that date, the first cashflow looks as expected
> (it fits the 0.5%), but some of the later cashflows also have
> different amounts, which should not happen.

Hmm.  By using addFixing, you're telling the library that the Libor
fixing at that date was 0.5%.  That doesn't only affect your floating
leg, but any other swap fixing on that date (which probably explains the
different amounts; the fixing affects the swaps used for bootstrapping
the risk-free curve.)

I think the correct way would be to use the Swap class instead of the
VanillaSwap class and build the cashflows explicitly, that is,
- use FixedRateLeg and IborLeg to build the two legs;
- replace the first coupon in the floating leg with a FixedRateCoupon
with the correct dates and rate;
- pass the fixed leg and the modified floating leg to a Swap instance.

Luigi



--

Newton's Law of Gravitation:
What goes up must come down. But don't expect it to come down
where you can find it. Murphy's Law applies to Newton's.



------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Valuating a swap with a manually set first fixing on the floating leg

Henner Heck

Hello Luigi,

thank you for the advice.
Yes, the first coupon of the floating leg is fixed.
I will try what you suggested, though i do not find
FixedRateLeg or IborLeg in the Java classes built
 from the SWIG files.
I hope i will find a way to make them usable.

Best regards,
Henner Heck




Am 15.11.2010, 11:47 Uhr, schrieb Luigi Ballabio  
<[hidden email]>:

> Hi Henner,
>
> On Mon, 2010-11-08 at 18:47 +0100, Henner Heck wrote:
>> Another swap i want to valuate now is slightly different to the
>> vanilla swap. The first period of the floating leg is a short stub
>> whose fixing is not derived from the forecasting term structure but is
>> set manually to e.g. 0.5%.
>
> So it's a fixed short coupon, not a floating one, right?
>
>> I tried to do this with "addFixing" to the floating leg, which seems
>> to work well, if my valuation date "today" is later than the first
>> fixing date for the floating leg.
>> If "today" is equal to that date, the first cashflow looks as expected
>> (it fits the 0.5%), but some of the later cashflows also have
>> different amounts, which should not happen.
>
> Hmm.  By using addFixing, you're telling the library that the Libor
> fixing at that date was 0.5%.  That doesn't only affect your floating
> leg, but any other swap fixing on that date (which probably explains the
> different amounts; the fixing affects the swaps used for bootstrapping
> the risk-free curve.)
>
> I think the correct way would be to use the Swap class instead of the
> VanillaSwap class and build the cashflows explicitly, that is,
> - use FixedRateLeg and IborLeg to build the two legs;
> - replace the first coupon in the floating leg with a FixedRateCoupon
> with the correct dates and rate;
> - pass the fixed leg and the modified floating leg to a Swap instance.
>
> Luigi
>
>

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Valuating a swap with a manually set first fixing on the floating leg

Luigi Ballabio
On Tue, 2010-11-23 at 15:58 +0100, Henner Heck wrote:
> Yes, the first coupon of the floating leg is fixed.
> I will try what you suggested, though i do not find
> FixedRateLeg or IborLeg in the Java classes built
>  from the SWIG files.

They're functions on the C++ side, which means they're wrapped as
methods of the QuantLib class in Java.

Luigi


--

standards, n.:
The principles we use to reject other people's code.



------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Valuating a swap with a manually set first fixing on the floating leg

Henner Heck

Found them!  :)

Thanks,
Henner



Am 23.11.2010, 16:19 Uhr, schrieb Luigi Ballabio  
<[hidden email]>:

> On Tue, 2010-11-23 at 15:58 +0100, Henner Heck wrote:
>> Yes, the first coupon of the floating leg is fixed.
>> I will try what you suggested, though i do not find
>> FixedRateLeg or IborLeg in the Java classes built
>>  from the SWIG files.
>
> They're functions on the C++ side, which means they're wrapped as
> methods of the QuantLib class in Java.
>
> Luigi
>
>


--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Valuating a swap with a manually set first fixing on the floating leg

suhasg
In reply to this post by Henner Heck
I am dealing with similar issue and have tried to implement the below solution. However, the floating leg payment dates do not appear to be aligned with the first fixed rate payment. Based on the code given below, I was expecting the floating periods to be 5-july-2011 to 30-sep-2011 , 30-sep-2011 to 30-dec-2011, 30-dec-2011 to 30-mar-2012...30-sep-2020 to 31-dec-2020. if you execute the below code listing, it will appear as if QL is not taking the forced first fixed rate into consideration at all. I have probably missed something. Thanks.

==============================================
// the only header you need to use QuantLib
#include <ql/quantlib.hpp>

#ifdef BOOST_MSVC
/* Uncomment the following lines to unmask floating-point
   exceptions. Warning: unpredictable results can arise...

   See http://www.wilmott.com/messageview.cfm?catid=10&threadid=9481
   Is there anyone with a definitive word about this?
*/
// #include <float.h>
// namespace { unsigned int u = _controlfp(_EM_INEXACT, _MCW_EM); }
#endif

#include <boost/timer.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <iomanip>

using namespace QuantLib;

#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {

    Integer sessionId() { return 0; }

}
#endif


int main(int, char* []) {

    try {

        boost::timer timer;
        std::cout << std::endl;

        /*********************
         ***  MARKET DATA  ***
         *********************/

        Calendar calendar = UnitedStates();
        Date settlementDate(5, July, 2011);
                JointCalendar usdgbpCalendar = JointCalendar(UnitedStates(), UnitedKingdom());
        settlementDate = usdgbpCalendar.adjust(settlementDate);
                usdgbpCalendar.addHoliday(Date(5,June,2012)); //Queens jubilee

        Integer fixingDays = 2;
        Date todaysDate(3, May,2013);
        Settings::instance().evaluationDate() = todaysDate;


                todaysDate = Settings::instance().evaluationDate();

        std::cout << "Today: " << todaysDate.weekday()
                  << ", " << todaysDate << std::endl;

        std::cout << "Settlement date: " << settlementDate.weekday()
                  << ", " << settlementDate << std::endl;

                //OISCurveData cd;

                //OISMktData(cd);

                //boost::shared_ptr<YieldTermStructure> oiscurve=buildOISCurve(cd);


        std::vector<QuantLib::Date> yieldMaturities;
                std::vector<QuantLib::Rate> yields ;

                yieldMaturities.push_back(calendar.advance(todaysDate, 1, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 4, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 5, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 12, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 97, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 139, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 229, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 319, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 412, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 503, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 593, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 683, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 776, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 1102, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 1466, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 1831, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 2196, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 2565, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 2929, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 3293, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 3657, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 4392, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 5484, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 7311, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 9138, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 10965, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 14619, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 18267, Days));
                yieldMaturities.push_back(calendar.advance(todaysDate, 21920, Days));


                yields.push_back(0.0015009);
                yields.push_back(0.0017504);
                yields.push_back(0.0019505);
                yields.push_back(0.0017882);
                yields.push_back(0.0027097);
                yields.push_back(0.002564);
                yields.push_back(0.0026989);
                yields.push_back(0.0028121);
                yields.push_back(0.0029331);
                yields.push_back(0.003054);
                yields.push_back(0.0031979);
                yields.push_back(0.0033695);
                yields.push_back(0.0035764);
                yields.push_back(0.0046287);
                yields.push_back(0.006471);
                yields.push_back(0.0087972);
                yields.push_back(0.0112492);
                yields.push_back(0.0136219);
                yields.push_back(0.0157672);
                yields.push_back(0.0177099);
                yields.push_back(0.0194467);
                yields.push_back(0.0224504);
                yields.push_back(0.025489);
                yields.push_back(0.028155);
                yields.push_back(0.0294443);
                yields.push_back(0.0302328);
                yields.push_back(0.0301941);
                yields.push_back(0.0294384);
                yields.push_back(0.028945);



                LogCubic mlcns = LogCubic(
                                  CubicInterpolation::Spline,
                                  true,
                                  CubicInterpolation::SecondDerivative,
                                  0,
                                  CubicInterpolation::SecondDerivative,
                                  0)  ;

                boost::shared_ptr<YieldTermStructure> depoSwapTermStructure(
        boost::shared_ptr<InterpolatedZeroCurve<LogCubic>>(
                new InterpolatedZeroCurve<LogCubic>(yieldMaturities,yields,
                                Actual360(),usdgbpCalendar, mlcns)));      

                                               
                depoSwapTermStructure->enableExtrapolation();

               
        RelinkableHandle<YieldTermStructure> discountingTermStructure;
       
        RelinkableHandle<YieldTermStructure> forecastingTermStructure;


        /*********************
        * SWAPS TO BE PRICED *
        **********************/

       
        Real nominal = 20000000.0;
        // fixed leg
                Frequency fixedLegFrequency = Quarterly;
        BusinessDayConvention fixedLegConvention = ModifiedFollowing;        
                DayCounter fixedLegDayCounter = Actual360();

        Rate fixedRate = 0.0313750;
       

        // floating leg
                BusinessDayConvention floatingLegConvention = ModifiedFollowing;
                DayCounter floatingLegDayCounter = Actual360();
        Frequency floatingLegFrequency = Quarterly;
                Handle < YieldTermStructure > ycHandle ( forecastingTermStructure );
        boost::shared_ptr<IborIndex> libor3m ( new USDLibor ( Period (3, Months ), ycHandle ));
//the first fixed rate on floating leg is 0.024075 for period 5-jul-2011 to 30-sep-2011
//and after that usual floating periods should begin
                libor3m -> addFixing(Date(1, July,2011),0.0024075);
                libor3m -> addFixing(Date(28, September,2011),0.0036856);
                libor3m -> addFixing(Date(28, December,2011),0.0057925);
                libor3m -> addFixing(Date(28,March,2012),0.0046965);
                libor3m -> addFixing(Date(27,June,2012),0.004606);
                libor3m -> addFixing(Date(26,September,2012),0.0036225);
                libor3m -> addFixing(Date(27,December,2012),0.00311);
                libor3m -> addFixing(Date(26,March,2013),0.002836);
                libor3m -> addFixing(Date(3, April,2013), 0.0028110);
               
        Spread spread = 0.0;

        Date maturity(31,December,2020);

        Schedule fixedSchedule(settlementDate, maturity,
                               Period(fixedLegFrequency),
                               usdgbpCalendar, fixedLegConvention,
                               fixedLegConvention,
                               DateGeneration::Forward, false);

                FixedRateLeg fixedLeg = FixedRateLeg(fixedSchedule)
                        .withNotionals(nominal)
                        .withCouponRates(fixedRate, fixedLegDayCounter)
            .withPaymentAdjustment(fixedLegConvention);

        Schedule floatSchedule(settlementDate, maturity,
                               Period(floatingLegFrequency),
                               usdgbpCalendar, floatingLegConvention,
                               floatingLegConvention,
                               DateGeneration::Forward, false);
                                                           
                IborLeg floatLeg = IborLeg(floatSchedule,libor3m)
                        .withNotionals(nominal)
                        .withPaymentDayCounter(floatingLegDayCounter)
            .withPaymentAdjustment(floatingLegConvention)
            .withSpreads(spread);

                //how do I replace the first floating coupon? Is the below correct way ??

                boost::shared_ptr<QuantLib::CashFlow> fixed1stPmt (new FixedRateCoupon(Date(30,September,2011),20000000,0.0024075,Actual360(),
                        Date(5,July,2011), Date(30,September,2011),Date(5,July,2011), Date(30,September,2011)));

                Leg fl = floatLeg;
                fl[0] = (fixed1stPmt);

               
               
                Swap myswap(fixedLeg, floatLeg);
               

       
        /***************
        * SWAP PRICING *
        ****************/

        // utilities for reporting
        std::vector<std::string> headers(4);
        headers[0] = "term structure";
        headers[1] = "net present value";
        headers[2] = "fair spread";
        headers[3] = "fair fixed rate";
        std::string separator = " | ";
        Size width = headers[0].size() + separator.size()
                   + headers[1].size() + separator.size()
                   + headers[2].size() + separator.size()
                   + headers[3].size() + separator.size() - 1;
        std::string rule(width, '-'), dblrule(width, '=');
        std::string tab(8, ' ');

       
        std::cout << rule << std::endl;

        Real NPV;
        Rate fairRate;
        Spread fairSpread;

        boost::shared_ptr<PricingEngine> swapEngine(
                         new DiscountingSwapEngine(discountingTermStructure));

        myswap.setPricingEngine(swapEngine);


               
                // Of course, you're not forced to really use different curves
        forecastingTermStructure.linkTo(depoSwapTermStructure);
        discountingTermStructure.linkTo(depoSwapTermStructure); //oiscurve);

                Real fixedLegNPV = myswap.legNPV(0);
                Real floatLegNPV = myswap.legNPV(1);
        NPV = fixedLegNPV + floatLegNPV;

                Real DV01 = myswap.legBPS(0);

                for(Size i=0;i<myswap.leg(1).size(); i++){
                        std :: cout << "Date :" << (myswap.leg(1))[i]->date() << "  FloatingLeg CashFlow :" << std::fixed << std::setprecision(2) << (myswap.leg(1))[i]->amount() << std :: endl ;
                }

                return 0;

    } catch (std::exception& e) {
        std::cerr << e.what() << std::endl;
        return 1;
    } catch (...) {
        std::cerr << "unknown error" << std::endl;
        return 1;
    }
}

Reply | Threaded
Open this post in threaded view
|

Re: Valuating a swap with a manually set first fixing on the floating leg

Luigi Ballabio
Hello,
    you're creating the floating schedule with a quarterly frequency
starting on July 5th, so the coupon dates will be on July 5th, October
5th and so on.  You're replacing the first coupon, but the second
still goes from October 5th to January 5th and thus looks for the
October 3rd fixing.  The correct way to build the leg is to pass the
stub date to the schedule, as in:

        Schedule floatSchedule(settlementDate, maturity,
                               Period(floatingLegFrequency),
                               usdgbpCalendar, floatingLegConvention,
                               floatingLegConvention,
                               DateGeneration::Forward, false,
                               Date(30,September,2011));

which will create coupons with the correct dates. At that point, the
fixing from September 28th should be picked up.

Luigi




On Mon, May 6, 2013 at 10:43 PM, suhasg
<[hidden email]> wrote:

> I am dealing with similar issue and have tried to implement the below
> solution. However, the floating leg payment dates do not appear to be
> aligned with the first fixed rate payment. Based on the code given below, I
> was expecting the floating periods to be 5-july-2011 to 30-sep-2011 ,
> 30-sep-2011 to 30-dec-2011, 30-dec-2011 to 30-mar-2012...30-sep-2020 to
> 31-dec-2020. if you execute the below code listing, it will appear as if QL
> is not taking the forced first fixed rate into consideration at all. I have
> probably missed something. Thanks.
>
> ==============================================
> // the only header you need to use QuantLib
> #include <ql/quantlib.hpp>
>
> #ifdef BOOST_MSVC
> /* Uncomment the following lines to unmask floating-point
>    exceptions. Warning: unpredictable results can arise...
>
>    See http://www.wilmott.com/messageview.cfm?catid=10&threadid=9481
>    Is there anyone with a definitive word about this?
> */
> // #include <float.h>
> // namespace { unsigned int u = _controlfp(_EM_INEXACT, _MCW_EM); }
> #endif
>
> #include <boost/timer.hpp>
> #include <boost/shared_ptr.hpp>
> #include <iostream>
> #include <iomanip>
>
> using namespace QuantLib;
>
> #if defined(QL_ENABLE_SESSIONS)
> namespace QuantLib {
>
>     Integer sessionId() { return 0; }
>
> }
> #endif
>
>
> int main(int, char* []) {
>
>     try {
>
>         boost::timer timer;
>         std::cout << std::endl;
>
>         /*********************
>          ***  MARKET DATA  ***
>          *********************/
>
>         Calendar calendar = UnitedStates();
>         Date settlementDate(5, July, 2011);
>                 JointCalendar usdgbpCalendar = JointCalendar(UnitedStates(),
> UnitedKingdom());
>         settlementDate = usdgbpCalendar.adjust(settlementDate);
>                 usdgbpCalendar.addHoliday(Date(5,June,2012)); //Queens jubilee
>
>         Integer fixingDays = 2;
>         Date todaysDate(3, May,2013);
>         Settings::instance().evaluationDate() = todaysDate;
>
>
>                 todaysDate = Settings::instance().evaluationDate();
>
>         std::cout << "Today: " << todaysDate.weekday()
>                   << ", " << todaysDate << std::endl;
>
>         std::cout << "Settlement date: " << settlementDate.weekday()
>                   << ", " << settlementDate << std::endl;
>
>                 //OISCurveData cd;
>
>                 //OISMktData(cd);
>
>                 //boost::shared_ptr<YieldTermStructure> oiscurve=buildOISCurve(cd);
>
>
>         std::vector<QuantLib::Date> yieldMaturities;
>                 std::vector<QuantLib::Rate> yields ;
>
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 1, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 4, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 5, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 12, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 97, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 139, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 229, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 319, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 412, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 503, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 593, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 683, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 776, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 1102, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 1466, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 1831, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 2196, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 2565, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 2929, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 3293, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 3657, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 4392, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 5484, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 7311, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 9138, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 10965, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 14619, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 18267, Days));
>                 yieldMaturities.push_back(calendar.advance(todaysDate, 21920, Days));
>
>
>                 yields.push_back(0.0015009);
>                 yields.push_back(0.0017504);
>                 yields.push_back(0.0019505);
>                 yields.push_back(0.0017882);
>                 yields.push_back(0.0027097);
>                 yields.push_back(0.002564);
>                 yields.push_back(0.0026989);
>                 yields.push_back(0.0028121);
>                 yields.push_back(0.0029331);
>                 yields.push_back(0.003054);
>                 yields.push_back(0.0031979);
>                 yields.push_back(0.0033695);
>                 yields.push_back(0.0035764);
>                 yields.push_back(0.0046287);
>                 yields.push_back(0.006471);
>                 yields.push_back(0.0087972);
>                 yields.push_back(0.0112492);
>                 yields.push_back(0.0136219);
>                 yields.push_back(0.0157672);
>                 yields.push_back(0.0177099);
>                 yields.push_back(0.0194467);
>                 yields.push_back(0.0224504);
>                 yields.push_back(0.025489);
>                 yields.push_back(0.028155);
>                 yields.push_back(0.0294443);
>                 yields.push_back(0.0302328);
>                 yields.push_back(0.0301941);
>                 yields.push_back(0.0294384);
>                 yields.push_back(0.028945);
>
>
>
>                 LogCubic mlcns = LogCubic(
>                                   CubicInterpolation::Spline,
>                                   true,
>                                   CubicInterpolation::SecondDerivative,
>                                   0,
>                                   CubicInterpolation::SecondDerivative,
>                                   0)  ;
>
>                 boost::shared_ptr<YieldTermStructure> depoSwapTermStructure(
>         boost::shared_ptr<InterpolatedZeroCurve&lt;LogCubic>>(
>                 new InterpolatedZeroCurve<LogCubic>(yieldMaturities,yields,
>                                 Actual360(),usdgbpCalendar, mlcns)));
>
>
>                 depoSwapTermStructure->enableExtrapolation();
>
>
>         RelinkableHandle<YieldTermStructure> discountingTermStructure;
>
>         RelinkableHandle<YieldTermStructure> forecastingTermStructure;
>
>
>         /*********************
>         * SWAPS TO BE PRICED *
>         **********************/
>
>
>         Real nominal = 20000000.0;
>         // fixed leg
>                 Frequency fixedLegFrequency = Quarterly;
>         BusinessDayConvention fixedLegConvention = ModifiedFollowing;
>                 DayCounter fixedLegDayCounter = Actual360();
>
>         Rate fixedRate = 0.0313750;
>
>
>         // floating leg
>                 BusinessDayConvention floatingLegConvention = ModifiedFollowing;
>                 DayCounter floatingLegDayCounter = Actual360();
>         Frequency floatingLegFrequency = Quarterly;
>                 Handle < YieldTermStructure > ycHandle ( forecastingTermStructure );
>         boost::shared_ptr<IborIndex> libor3m ( new USDLibor ( Period (3,
> Months ), ycHandle ));
> //the first fixed rate on floating leg is 0.024075 for period 5-jul-2011 to
> 30-sep-2011
> //and after that usual floating periods should begin
>                 libor3m -> addFixing(Date(1, July,2011),0.0024075);
>                 libor3m -> addFixing(Date(28, September,2011),0.0036856);
>                 libor3m -> addFixing(Date(28, December,2011),0.0057925);
>                 libor3m -> addFixing(Date(28,March,2012),0.0046965);
>                 libor3m -> addFixing(Date(27,June,2012),0.004606);
>                 libor3m -> addFixing(Date(26,September,2012),0.0036225);
>                 libor3m -> addFixing(Date(27,December,2012),0.00311);
>                 libor3m -> addFixing(Date(26,March,2013),0.002836);
>                 libor3m -> addFixing(Date(3, April,2013), 0.0028110);
>
>         Spread spread = 0.0;
>
>                         Date maturity(31,December,2020);
>
>         Schedule fixedSchedule(settlementDate, maturity,
>                                Period(fixedLegFrequency),
>                                usdgbpCalendar, fixedLegConvention,
>                                fixedLegConvention,
>                                DateGeneration::Forward, false);
>
>                 FixedRateLeg fixedLeg = FixedRateLeg(fixedSchedule)
>                         .withNotionals(nominal)
>                         .withCouponRates(fixedRate, fixedLegDayCounter)
>             .withPaymentAdjustment(fixedLegConvention);
>
>         Schedule floatSchedule(settlementDate, maturity,
>                                Period(floatingLegFrequency),
>                                usdgbpCalendar, floatingLegConvention,
>                                floatingLegConvention,
>                                DateGeneration::Forward, false);
>
>                 IborLeg floatLeg = IborLeg(floatSchedule,libor3m)
>                         .withNotionals(nominal)
>                         .withPaymentDayCounter(floatingLegDayCounter)
>             .withPaymentAdjustment(floatingLegConvention)
>             .withSpreads(spread);
>
>                 //how do I replace the first floating coupon? Is the below correct way ??
>
>                 boost::shared_ptr<QuantLib::CashFlow> fixed1stPmt (new
> FixedRateCoupon(Date(30,September,2011),20000000,0.0024075,Actual360(),
>                         Date(5,July,2011), Date(30,September,2011),Date(5,July,2011),
> Date(30,September,2011)));
>
>                 Leg fl = floatLeg;
>                 fl[0] = (fixed1stPmt);
>
>
>
>                 Swap myswap(fixedLeg, floatLeg);
>
>
>
>         /***************
>         * SWAP PRICING *
>         ****************/
>
>         // utilities for reporting
>         std::vector<std::string> headers(4);
>         headers[0] = "term structure";
>         headers[1] = "net present value";
>         headers[2] = "fair spread";
>         headers[3] = "fair fixed rate";
>         std::string separator = " | ";
>         Size width = headers[0].size() + separator.size()
>                    + headers[1].size() + separator.size()
>                    + headers[2].size() + separator.size()
>                    + headers[3].size() + separator.size() - 1;
>         std::string rule(width, '-'), dblrule(width, '=');
>         std::string tab(8, ' ');
>
>
>         std::cout << rule << std::endl;
>
>         Real NPV;
>         Rate fairRate;
>         Spread fairSpread;
>
>         boost::shared_ptr<PricingEngine> swapEngine(
>                          new
> DiscountingSwapEngine(discountingTermStructure));
>
>         myswap.setPricingEngine(swapEngine);
>
>
>
>                 // Of course, you're not forced to really use different curves
>         forecastingTermStructure.linkTo(depoSwapTermStructure);
>         discountingTermStructure.linkTo(depoSwapTermStructure); //oiscurve);
>
>                 Real fixedLegNPV = myswap.legNPV(0);
>                 Real floatLegNPV = myswap.legNPV(1);
>         NPV = fixedLegNPV + floatLegNPV;
>
>                 Real DV01 = myswap.legBPS(0);
>
>                 for(Size i=0;i<myswap.leg(1).size(); i++){
>                         std :: cout &lt;&lt; &quot;Date :&quot; &lt;&lt;
> (myswap.leg(1))[i]->date() << "  FloatingLeg CashFlow :" << std::fixed <<
> std::setprecision(2) << (myswap.leg(1))[i]->amount() << std :: endl ;
>                 }
>
>                 return 0;
>
>     } catch (std::exception& e) {
>         std::cerr << e.what() << std::endl;
>         return 1;
>     } catch (...) {
>         std::cerr << "unknown error" << std::endl;
>         return 1;
>     }
> }
>
>
>
>
>
> --
> View this message in context: http://quantlib.10058.n7.nabble.com/Valuating-a-swap-with-a-manually-set-first-fixing-on-the-floating-leg-tp5452p14247.html
> Sent from the quantlib-users mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and
> their applications. This 200-page book is written by three acclaimed
> leaders in the field. The early access version is available now.
> Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users