Examples of ZeroCouponBond


Examples of org.jquantlib.instruments.ZeroCouponBond

      final double tolerance = 1.0e-6;

      // plain

      final ZeroCouponBond bond1 = new ZeroCouponBond(settlementDays,
                           new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                           faceAmount,
                           new Date(30,Month.November,2008),
                           BusinessDayConvention.ModifiedFollowing,
                           100.0, new Date(30,Month.November,2004));

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

      final double cachedPrice1 = 88.551726;

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

      final ZeroCouponBond bond2 = new ZeroCouponBond(settlementDays,
                           new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                           faceAmount,
                           new Date(30,Month.November,2007),
                           BusinessDayConvention.ModifiedFollowing,
                           100.0, new Date(30,Month.November,2004));

      bond2.setPricingEngine(bondEngine);

      final double cachedPrice2 = 91.278949;

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

      final ZeroCouponBond bond3 = new ZeroCouponBond(settlementDays,
                           new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                           faceAmount,
                           new Date(30,Month.November,2006),
                           BusinessDayConvention.ModifiedFollowing,
                           100.0, new Date(30,Month.November,2004));

      bond3.setPricingEngine(bondEngine);

      final double cachedPrice3 = 94.098006;

      price = bond3.getCleanPrice();
      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

Examples of org.jquantlib.instruments.bonds.ZeroCouponBond

       
         // Pricing engine
        final PricingEngine  bondEngine = new DiscountingBondEngine(discountingTermStructure);
       
         // Zero coupon bond
         final ZeroCouponBond zeroCouponBond = new ZeroCouponBond(
                           settlementDays,
                           new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                           faceAmount,
                           new Date(15,Month.August,2013),
                           BusinessDayConvention.Following,
                           116.92,
                           new Date(15,Month.August,2003));
       
         zeroCouponBond.setPricingEngine(bondEngine);
       
         // Fixed 4.5% US Treasury Note
         final Schedule fixedBondSchedule = new Schedule(
                     new Date(15, Month.May, 2007),
                     new Date(15,Month.May,2017),
                     new Period(Frequency.Semiannual),
                     new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                     BusinessDayConvention.Unadjusted,
                     BusinessDayConvention.Unadjusted,
                     DateGeneration.Rule.Backward, false);
       
         final FixedRateBond fixedRateBond = new FixedRateBond(
                     settlementDays,
                     faceAmount,
                     fixedBondSchedule,
                     new double[]{0.045},
                     new ActualActual(ActualActual.Convention.Bond),
                     BusinessDayConvention.ModifiedFollowing,
                     100.0,
                     new Date(15, Month.May, 2007));
       
         fixedRateBond.setPricingEngine(bondEngine);
       
         // Floating rate bond (3M USD Libor + 0.1%)
         // Should and will be priced on another curve later...
       
         final RelinkableHandle<YieldTermStructure> liborTermStructure = new RelinkableHandle<YieldTermStructure>();
         final IborIndex libor3m =  new USDLibor(new Period(3, TimeUnit.Months), liborTermStructure);
         libor3m.addFixing(new Date(17, Month.July, 2008), 0.0278625);
       
         final Schedule floatingBondSchedule = new Schedule(
                     new Date(21, Month.October, 2005),
                     new Date(21, Month.October, 2010), new Period(Frequency.Quarterly),
                     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
View Full Code Here

Examples of org.jquantlib.instruments.bonds.ZeroCouponBond

      final double tolerance = 1.0e-6;

      // plain

      final ZeroCouponBond bond1 = new ZeroCouponBond(settlementDays,
                           new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                           faceAmount,
                           new Date(30,Month.November,2008),
                           BusinessDayConvention.ModifiedFollowing,
                           100.0, new Date(30,Month.November,2004));

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

      final double cachedPrice1 = 88.551726;

      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));
      }

      final ZeroCouponBond bond2 = new ZeroCouponBond(settlementDays,
                           new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                           faceAmount,
                           new Date(30,Month.November,2007),
                           BusinessDayConvention.ModifiedFollowing,
                           100.0, new Date(30,Month.November,2004));

      bond2.setPricingEngine(bondEngine);

      final double cachedPrice2 = 91.278949;

      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));
      }

      final ZeroCouponBond bond3 = new ZeroCouponBond(settlementDays,
                           new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                           faceAmount,
                           new Date(30,Month.November,2006),
                           BusinessDayConvention.ModifiedFollowing,
                           100.0, new Date(30,Month.November,2004));

      bond3.setPricingEngine(bondEngine);

      final double cachedPrice3 = 94.098006;

      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

Examples of org.jquantlib.instruments.bonds.ZeroCouponBond

        amExercise, vars.conversionRatio, vars.no_dividends,
        vars.no_callability, vars.creditSpread, vars.issueDate,
        vars.settlementDays, vars.dayCounter, schedule, vars.redemption);
    amZero.setPricingEngine(engine);

    final ZeroCouponBond zero = new ZeroCouponBond(vars.settlementDays,
        vars.calendar, 100.0, vars.maturityDate,
        BusinessDayConvention.Following, vars.redemption,
        vars.issueDate);

    final PricingEngine bondEngine = new DiscountingBondEngine(discountCurve);
    zero.setPricingEngine(bondEngine);

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

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

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

    // coupon

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.