Package org.jquantlib.time

Examples of org.jquantlib.time.Schedule


    final Handle<YieldTermStructure> discountCurve = new Handle<YieldTermStructure>(Utilities.flatRate(today, 0.03, new Actual360()));

      // actual market values from the evaluation date

      final Frequency freq = Frequency.Semiannual;
      final Schedule sch1 = new Schedule(new Date(31, Month.October, 2004),
                    new Date(31, Month.October, 2006), new Period(freq), bondCalendar,
                    BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted, DateGeneration.Rule.Backward, false);

      final FixedRateBond bond1 = new FixedRateBond(settlementDays, faceAmount, sch1,
                          new double[] {0.025},
                          bondDayCount, BusinessDayConvention.ModifiedFollowing,
                          100.0, new Date(1, Month.November, 2004));

    final PricingEngine bondEngine = new DiscountingBondEngine(discountCurve);

      bond1.setPricingEngine(bondEngine);

      final double marketPrice1 = 99.203125;
      final double marketYield1 = 0.02925;

      final Schedule sch2 = new Schedule(new Date(15, Month.November, 2004),
          new Date(15, Month.November, 2009), new Period(freq), bondCalendar,
          BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted, DateGeneration.Rule.Backward, false);

      final FixedRateBond bond2 = new FixedRateBond(settlementDays, faceAmount, sch2,
                          new double [] {0.035},
                          bondDayCount, BusinessDayConvention.ModifiedFollowing,
                          100.0, new Date(15, Month.November, 2004));

      bond2.setPricingEngine(bondEngine);

      final double marketPrice2 = 99.6875;
      final double marketYield2 = 0.03569;

      // calculated values

      final double cachedPrice1a = 99.204505, cachedPrice2a = 99.687192;
      final double cachedPrice1b = 98.943393, cachedPrice2b = 101.986794;
      final double cachedYield1a = 0.029257,  cachedYield2a = 0.035689;
      final double cachedYield1b = 0.029045,  cachedYield2b = 0.035375;
      final double cachedYield1c = 0.030423,  cachedYield2c = 0.030432;

      // check
      final double tolerance = 1.0e-6;
      double price, yield;

      price = bond1.cleanPrice(marketYield1,
                               bondDayCount, Compounding.Compounded, freq);
      if (Math.abs(price-cachedPrice1a) > tolerance) {
        fail("failed to reproduce cached price:"
                     + "\n    calculated: " + price
                     + "\n    expected:   " + cachedPrice1a
                     + "\n    tolerance:  " + tolerance
                     + "\n    error:      " + (price-cachedPrice1a));
      }

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

      yield = bond1.yield(marketPrice1, bondDayCount, Compounding.Compounded, freq);
      if (Math.abs(yield-cachedYield1a) > tolerance) {
        fail("failed to reproduce cached compounded yield:"
                     + "\n    calculated: " + yield
                     + "\n    expected:   " + cachedYield1a
                     + "\n    tolerance:  " + tolerance
                     + "\n    error:      " + (yield-cachedYield1a));
      }

      yield = bond1.yield(marketPrice1, bondDayCount, Compounding.Continuous, freq);
      if (Math.abs(yield-cachedYield1b) > tolerance) {
        fail("failed to reproduce cached continuous yield:"
                     + "\n    calculated: " + yield
                     + "\n    expected:   " + cachedYield1b
                     + "\n    tolerance:  " + tolerance
                     + "\n    error:      " + (yield-cachedYield1b));
      }

      yield = bond1.yield(bondDayCount, Compounding.Continuous, freq);
      if (Math.abs(yield-cachedYield1c) > tolerance) {
        fail("failed to reproduce cached continuous yield:"
                     + "\n    calculated: " + yield
                     + "\n    expected:   " + cachedYield1c
                     + "\n    tolerance:  " + tolerance
                     + "\n    error:      " + (yield-cachedYield1c));
      }


      price = bond2.cleanPrice(marketYield2, bondDayCount, Compounding.Compounded, freq);
      if (Math.abs(price-cachedPrice2a) > tolerance) {
        fail("failed to reproduce cached price:"
                     + "\n    calculated: " + price
                     + "\n    expected:   " + cachedPrice2a
                     + "\n    tolerance:  " + tolerance
                     + "\n    error:      " + (price-cachedPrice2a));
      }

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

      yield = bond2.yield(marketPrice2, bondDayCount, Compounding.Compounded, freq);
      if (Math.abs(yield-cachedYield2a) > tolerance) {
        fail("failed to reproduce cached compounded yield:"
                     + "\n    calculated: " + yield
                     + "\n    expected:   " + cachedYield2a
                     + "\n    tolerance:  " + tolerance
                     + "\n    error:      " + (yield-cachedYield2a));
      }

      yield = bond2.yield(marketPrice2, bondDayCount, Compounding.Continuous, freq);
      if (Math.abs(yield-cachedYield2b) > tolerance) {
        fail("failed to reproduce cached continuous yield:"
                     + "\n    calculated: " + yield
                     + "\n    expected:   " + cachedYield2b
                     + "\n    tolerance:  " + tolerance
                     + "\n    error:      " + (yield-cachedYield2b));
      }

      yield = bond2.yield(bondDayCount, Compounding.Continuous, freq);
      if (Math.abs(yield-cachedYield2c) > tolerance) {
        fail("failed to reproduce cached continuous yield:"
                     + "\n    calculated: " + yield
                     + "\n    expected:   " + cachedYield2c
                     + "\n    tolerance:  " + tolerance
                     + "\n    error:      " + (yield-cachedYield2c));
      }

      // with explicit settlement date:

      final Schedule sch3 = new Schedule(new Date(30,Month.November,2004),
                    new Date(30,Month.November,2006), new Period(freq),
                    new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                    BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted, DateGeneration.Rule.Backward, false);

      final FixedRateBond bond3 = new FixedRateBond(settlementDays, faceAmount, sch3,
View Full Code Here


      final double tolerance = 1.0e-6;

      // plain

      final Schedule sch = new Schedule(new Date(30,Month.November,2004),
                   new Date(30,Month.November,2008), new Period(Frequency.Semiannual),
                   new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                   BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted, DateGeneration.Rule.Backward, false);

      final FixedRateBond bond1 = new FixedRateBond(settlementDays, faceAmount, sch,
                          new double [] { 0.02875 },
                          new ActualActual(ActualActual.Convention.ISMA),
                          BusinessDayConvention.ModifiedFollowing,
                          100.0, new Date(30,Month.November,2004));

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

      final double cachedPrice1 = 99.298100;

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

      // varying coupons

      final double [] couponRates = new double[] { 0.02875, 0.03, 0.03125, 0.0325 };

      final FixedRateBond bond2 = new FixedRateBond(settlementDays, faceAmount, sch,
                            couponRates,
                            new ActualActual(ActualActual.Convention.ISMA),
                            BusinessDayConvention.ModifiedFollowing,
                            100.0, new Date(30,Month.November,2004));

      bond2.setPricingEngine(bondEngine);

      final double cachedPrice2 = 100.334149;

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

      // stub date

      final Schedule sch3 = new Schedule(new Date(30,Month.November,2004),
                    new Date(30,Month.March,2009), new Period(Frequency.Semiannual),
                    new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                    BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                    DateGeneration.Rule.Backward, false,
                    new Date(), new Date(30,Month.November,2008));
View Full Code Here

      final IborCouponPricer pricer = new BlackIborCouponPricer(new Handle<OptionletVolatilityStructure>());

      // plain

      final Schedule sch = new Schedule(new Date(30,Month.November,2004),
                    new Date(30,Month.November,2008),
                    new Period(Frequency.Semiannual),
                    new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                    BusinessDayConvention.ModifiedFollowing,
                    BusinessDayConvention.ModifiedFollowing,
View Full Code Here

          // plain
          final InterestRate yield = new InterestRate(yields[bondIndex],
                             new Business252(new Brazil()),
                             Compounding.Compounded, Frequency.Annual);

          final Schedule schedule = new Schedule(new Date(1,Month.January,2007),
                            maturityDates[bondIndex], new Period(Frequency.Semiannual),
                            new Brazil(Brazil.Market.SETTLEMENT),
                            BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                            DateGeneration.Rule.Backward, false);
View Full Code Here

    final Handle<YieldTermStructure> discountCurve = new Handle<YieldTermStructure>(
        new ForwardSpreadedTermStructure(vars.riskFreeRate,
            vars.creditSpread));

    // zero-coupon
    Schedule schedule = new MakeSchedule(vars.issueDate, vars.maturityDate,
        new Period(Frequency.Once), vars.calendar,
        BusinessDayConvention.Following).backwards().schedule();

    final ConvertibleZeroCouponBond euZero = new ConvertibleZeroCouponBond(
        euExercise, vars.conversionRatio, vars.no_dividends,
        vars.no_callability, vars.creditSpread, vars.issueDate,
        vars.settlementDays, vars.dayCounter, schedule, vars.redemption);
    euZero.setPricingEngine(engine);

    final ConvertibleZeroCouponBond amZero = new ConvertibleZeroCouponBond(
        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

    final double[] coupons = { 0.05 };

    schedule = new MakeSchedule(vars.issueDate, vars.maturityDate,
        new Period(vars.frequency), vars.calendar,
        BusinessDayConvention.Following).backwards().schedule();

    final ConvertibleFixedCouponBond euFixed = new ConvertibleFixedCouponBond(
        euExercise, vars.conversionRatio, vars.no_dividends,
        vars.no_callability, vars.creditSpread, vars.issueDate,
        vars.settlementDays, coupons, vars.dayCounter, schedule,
        vars.redemption);
    euFixed.setPricingEngine(engine);

    final ConvertibleFixedCouponBond amFixed = new ConvertibleFixedCouponBond(
        amExercise, vars.conversionRatio, vars.no_dividends,
        vars.no_callability, vars.creditSpread, vars.issueDate,
        vars.settlementDays, coupons, vars.dayCounter, schedule,
        vars.redemption);
    amFixed.setPricingEngine(engine);

    final FixedRateBond fixed = new FixedRateBond(vars.settlementDays,
        vars.faceAmount, schedule, coupons, vars.dayCounter,
        BusinessDayConvention.Following, vars.redemption,
        vars.issueDate);

    fixed.setPricingEngine(bondEngine);

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

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

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

    // floating-rate

    final IborIndex index = new Euribor1Y(discountCurve);
    final int fixingDays = 2;
    final Array gearings = new Array(1).fill(1.0);
    final Array spreadsArr = new Array(0);
    final double[] spreads = { 0 };

    final ConvertibleFloatingRateBond euFloating = new ConvertibleFloatingRateBond(
        euExercise, vars.conversionRatio, vars.no_dividends,
        vars.no_callability, vars.creditSpread, vars.issueDate,
        vars.settlementDays, index, fixingDays, spreads,
        vars.dayCounter, schedule, vars.redemption);
    euFloating.setPricingEngine(engine);

    final ConvertibleFloatingRateBond amFloating = new ConvertibleFloatingRateBond(
        amExercise, vars.conversionRatio, vars.no_dividends,
        vars.no_callability, vars.creditSpread, vars.issueDate,
        vars.settlementDays, index, fixingDays, spreads,
        vars.dayCounter, schedule, vars.redemption);
    amFloating.setPricingEngine(engine);

    final IborCouponPricer pricer = new BlackIborCouponPricer(
        new Handle<OptionletVolatilityStructure>());

    final Schedule floatSchedule = new Schedule(vars.issueDate,
        vars.maturityDate, new Period(vars.frequency), vars.calendar,
        BusinessDayConvention.Following,
        BusinessDayConvention.Following, DateGeneration.Rule.Backward,
        false);

View Full Code Here

    final double conversionStrike = vars.redemption / vars.conversionRatio;
    final StrikedTypePayoff payoff = new PlainVanillaPayoff(Option.Type.Call,
        conversionStrike);

    final Schedule schedule = new MakeSchedule(vars.issueDate, vars.maturityDate,
        new Period(Frequency.Once), vars.calendar,
        BusinessDayConvention.Following).backwards().schedule();

    final ConvertibleZeroCouponBond euZero = new ConvertibleZeroCouponBond(
        euExercise, vars.conversionRatio, vars.no_dividends,
View Full Code Here

                                  BusinessDayConvention.Following);
     

      Date maturity = earliestDate.add(tenor);
      BMAIndex clonedIndex = bmaIndex.clone(termStructureHandle);
      Schedule bmaSchedule = new MakeSchedule(earliestDate,
                                          maturity,
                                          bmaPeriod,
                                          bmaIndex.fixingCalendar(),
                                          bmaConvention)
                    .backwards()
                    .schedule();
     
      Schedule liborSchedule = new MakeSchedule(earliestDate,
                                  maturity,
                                  iborIndex.tenor(),
                                  iborIndex.fixingCalendar(),
                                  iborIndex.businessDayConvention())
                    .endOfMonth(iborIndex.endOfMonth())
View Full Code Here

TOP

Related Classes of org.jquantlib.time.Schedule

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.