Package org.jquantlib.instruments.bonds

Examples of org.jquantlib.instruments.bonds.FloatingRateBond


                     new UnitedStates(UnitedStates.Market.NYSE),
                     BusinessDayConvention.Unadjusted,
                     BusinessDayConvention.Unadjusted,
                     DateGeneration.Rule.Backward, true);
       
         final FloatingRateBond floatingRateBond = new FloatingRateBond(
                     settlementDays,
                     faceAmount,
                     floatingBondSchedule,
                     libor3m,
                     new Actual360(),
                     BusinessDayConvention.ModifiedFollowing,
                     2,                    
                     new Array(1).fill(1.0)//Gearings                    
                     new Array(1).fill(0.001),//Spreads
                     new Array(0),         // Caps
                     new Array(0),         // Floors
                     true,             // Fixing in arrears
                     100.0,
                     new Date(21, Month.October, 2005));
       
         floatingRateBond.setPricingEngine(bondEngine);
              
         // optionLet volatilities
         final double volatility = 0.0;
         final Handle<OptionletVolatilityStructure> vol =
               new Handle<OptionletVolatilityStructure>(
                     new ConstantOptionletVolatility(
                         settlementDays,
                         calendar,
                         BusinessDayConvention.ModifiedFollowing,
                         volatility,
                         new Actual365Fixed()));
       
         // Coupon pricers
         final IborCouponPricer pricer = new BlackIborCouponPricer(vol);
         PricerSetter.setCouponPricer(floatingRateBond.cashflows(),pricer);
       
         // Yield curve bootstrapping
         forecastingTermStructure.linkTo(depoSwapTermStructure);
         discountingTermStructure.linkTo(bondDiscountingTermStructur);
       
         // We are using the depo & swap curve to estimate the future Libor
         // rates
         liborTermStructure.linkTo(depoSwapTermStructure);
       
         /***************
         * BOND PRICING *
         ****************/
       
        QL.info("Results:");
       
         System.out.println("                 "
             + "  " "ZC"
             + "  " "Fixed"
             + "  " "Floating"
             );
               
         System.out.println( "Net present value"
               "  " + zeroCouponBond.NPV()
               "  " + fixedRateBond.NPV()
               "  " + floatingRateBond.NPV());
               
        System.out.println("Clean Price      "
            + "  " +zeroCouponBond.cleanPrice()
            + "  " +fixedRateBond.cleanPrice()
            + "  " + floatingRateBond.cleanPrice()
            );
       
        System.out.println("Dirty price      "
              + " " + zeroCouponBond.dirtyPrice()
              + " " + fixedRateBond.dirtyPrice()
              + " " + floatingRateBond.dirtyPrice()
              );
       
        System.out.println( "Accrued coupon  "
          + " " + zeroCouponBond.accruedAmount()
          + " " + fixedRateBond.accruedAmount()
          + " " + floatingRateBond.accruedAmount()
            );

        System.out.println( "Previous coupon "
          + " " + "N/A"  //zeroCouponBond
          + " " + fixedRateBond.previousCoupon()
          + " " + floatingRateBond.previousCoupon()
            );

        System.out.println( "Next coupon     "
          + " " + "N/A"  //zeroCouponBond
          + " " + fixedRateBond.nextCoupon()
          + " " + floatingRateBond.nextCoupon()
            );
        System.out.println( "Yield           "
          + " " + zeroCouponBond.yield(new Actual360(),Compounding.Compounded, Frequency.Annual)
          + " " + fixedRateBond.yield(new Actual360(),Compounding.Compounded, Frequency.Annual)
          + " " + floatingRateBond.yield(new Actual360(),Compounding.Compounded, Frequency.Annual)
            );

         // Other computations
        System.out.println("Sample indirect computations (for the floating rate bond): " );
        System.out.println( "Yield to Clean Price: " +
            floatingRateBond.cleanPrice(floatingRateBond.yield(new Actual360(),Compounding.Compounded,Frequency.Annual),new Actual360(),Compounding.Compounded,Frequency.Annual,settlementDate)
        );
       
        System.out.println("Clean Price to Yield: " +
         floatingRateBond.yield(floatingRateBond.cleanPrice(),new Actual360(),Compounding.Compounded,Frequency.Annual,settlementDate)
        );
       
         /* "Yield to Price"
           "Price to Yield"
         */
 
View Full Code Here


                    new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                    BusinessDayConvention.ModifiedFollowing,
                    BusinessDayConvention.ModifiedFollowing,
                    DateGeneration.Rule.Backward, false);

      final FloatingRateBond bond1 = new FloatingRateBond(settlementDays, vars.faceAmount, sch,
                             index, new ActualActual(ActualActual.Convention.ISMA),
                             BusinessDayConvention.ModifiedFollowing, fixingDays,
                             new Array(0), new Array(0),
                             new Array(0), new Array(0),
                             false,
                             100.0, new Date(30,Month.November,2004));

      final PricingEngine bondEngine = new DiscountingBondEngine(riskFreeRate);
      bond1.setPricingEngine(bondEngine);

      PricerSetter.setCouponPricer(bond1.cashflows(),pricer);

      final boolean indexedCoupon = new Settings().isUseIndexedCoupon();
     
      final double cachedPrice1 = indexedCoupon ? 99.874645 : 99.874646;

      double price = bond1.cleanPrice();
      if (Math.abs(price-cachedPrice1) > tolerance) {
          fail("failed to reproduce cached price:\n"
                     + "    calculated: " + price + "\n"
                     + "    expected:   " + cachedPrice1 + "\n"
                     + "    error:      " + (price-cachedPrice1));
      }

      // different risk-free and discount curve

      final FloatingRateBond bond2 = new FloatingRateBond(settlementDays, vars.faceAmount, sch,
                             index, new ActualActual(ActualActual.Convention.ISMA),
                             BusinessDayConvention.ModifiedFollowing, fixingDays,
                             new Array(0), new Array(0),
                             new Array(0), new Array(0),
                             false,
                             100.0, new Date(30,Month.November,2004));

      final PricingEngine bondEngine2 = new DiscountingBondEngine(discountCurve);
      bond2.setPricingEngine(bondEngine2);

      PricerSetter.setCouponPricer(bond2.cashflows(),pricer);

        final double cachedPrice2 = indexedCoupon ? 97.955904 : 97.955904; // yes, they are the same, according to QuantLib/C++

      price = bond2.cleanPrice();
      if (Math.abs(price-cachedPrice2) > tolerance) {
          fail("failed to reproduce cached price:\n"
                     + "    calculated: " + price + "\n"
                     + "    expected:   " + cachedPrice2 + "\n"
                     + "    error:      " + (price-cachedPrice2));
      }

      // varying spread
      final double [] spreads = new double[] { 0.001, 0.0012, 0.0014, 0.0016 };

      final FloatingRateBond bond3 = new FloatingRateBond(settlementDays, vars.faceAmount, sch,
                             index, new ActualActual(ActualActual.Convention.ISMA),
                             BusinessDayConvention.ModifiedFollowing, fixingDays,
                             new Array(0), new Array(spreads),
                             new Array(0), new Array(0),
                             false,
                             100.0, new Date(30,Month.November,2004));

      bond3.setPricingEngine(bondEngine2);

      PricerSetter.setCouponPricer(bond3.cashflows(),pricer);

        final double cachedPrice3 = indexedCoupon ? 98.495458 : 98.495459;
       
      price = bond3.cleanPrice();
      if (Math.abs(price-cachedPrice3) > tolerance) {
          fail("failed to reproduce cached price:\n"
                     + "    calculated: " + price + "\n"
                     + "    expected:   " + cachedPrice3 + "\n"
                     + "    error:      " + (price-cachedPrice3));
View Full Code Here

        vars.maturityDate, new Period(vars.frequency), vars.calendar,
        BusinessDayConvention.Following,
        BusinessDayConvention.Following, DateGeneration.Rule.Backward,
        false);

    final FloatingRateBond floating = new FloatingRateBond(vars.settlementDays,
        vars.faceAmount, floatSchedule, index, vars.dayCounter,
        BusinessDayConvention.Following, fixingDays, gearings,
        spreadsArr, new Array(0), new Array(0), false, vars.redemption,
        vars.issueDate);

    floating.setPricingEngine(bondEngine);
    PricerSetter.setCouponPricer(floating.cashflows(), pricer);

    tolerance = 2.0e-2 * (vars.faceAmount / 100.0);

    error = Math.abs(euFloating.NPV() - floating.settlementValue());
    if (error > tolerance) {
      fail("failed to reproduce floating-rate bond price:"
          + "\n    calculated: " + euFloating.NPV()
          + "\n    expected:   " + floating.settlementValue()
          + "\n    error:      " + error);
    }

    error = Math.abs(amFloating.NPV() - floating.settlementValue());
    if (error > tolerance) {
      fail("failed to reproduce floating-rate bond price:"
          + "\n    calculated: " + amFloating.NPV()
          + "\n    expected:   " + floating.settlementValue()
          + "\n    error:      " + error);
    }
  }
View Full Code Here

TOP

Related Classes of org.jquantlib.instruments.bonds.FloatingRateBond

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.