Package org.jquantlib.indexes

Examples of org.jquantlib.indexes.IborIndex


    super(rate);
    this.periodToStart = periodToStart;
   
    QL.validateExperimentalMode();

    iborIndex = new IborIndex(
        "no-fix",// never take fixing into account
        i.tenor(), i.fixingDays(), new Currency(), i.fixingCalendar(),
        i.businessDayConvention(), i.endOfMonth(), i.dayCounter(),
        this.termStructureHandle);
View Full Code Here


    super(rate);
    this.periodToStart = periodToStart;
   
    QL.validateExperimentalMode();

    iborIndex = new IborIndex(
        "no-fix",// never take fixing into account
        i.tenor(), i.fixingDays(), new Currency(), i.fixingCalendar(),
        i.businessDayConvention(), i.endOfMonth(), i.dayCounter(),
        this.termStructureHandle);
View Full Code Here

                      "\n    expected rate:  ", expectedRate));
            }
        }

        // check swaps
        final IborIndex euribor6m = new Euribor6M(curveHandle);
        for (int i=0; i<vars.swaps; i++) {
            final Period tenor = new Period(swapData[i].n, swapData[i].units);

            final VanillaSwap swap = new MakeVanillaSwap(tenor, euribor6m, 0.0)
                .withEffectiveDate(vars.settlement)
                .withFixedLegDayCount(vars.fixedLegDayCounter)
                .withFixedLegTenor(new Period(vars.fixedLegFrequency))
                .withFixedLegConvention(vars.fixedLegConvention)
                .withFixedLegTerminationDateConvention(vars.fixedLegConvention)
                .value();

            /*@Rate*/ final double expectedRate  = swapData[i].rate/100;
            /*@Rate*/ final double estimatedRate = swap.fairRate();
            /*@Spread*/ final double error = Math.abs(expectedRate-estimatedRate);
            if (error > tolerance) {
              throw new RuntimeException(
              String.format("%d %s %s %f %s %f %s %f %s %f",
                      swapData[i].n, " year(s) swap:\n",
                      "\n estimated rate: ", estimatedRate,
                      "\n expected rate:  ", expectedRate,
                      "\n error:          ", error,
                      "\n tolerance:      ", tolerance));
            }
        }

        // check bonds
        vars.termStructure = new PiecewiseYieldCurve<T,I,B>(
                  classT, classI, classB,
                  vars.settlement, vars.bondHelpers,
                  new Actual360(),
                  new Handle/*<Quote>*/[0],
                  new Date[0],
                  1.0e-12,
                  interpolator);
       
        curveHandle.linkTo(vars.termStructure);

        for (int i=0; i<vars.bonds; i++) {
            final Date maturity = vars.calendar.advance(vars.today, bondData[i].n, bondData[i].units);
            final Date issue = vars.calendar.advance(maturity, -bondData[i].length, TimeUnit.Years);
            /*@Rate*/ final double[] coupons = new double[1];
            coupons[0] = bondData[i].coupon/100.0;

            final FixedRateBond bond = new FixedRateBond(vars.bondSettlementDays, 100.0,
                               vars.schedules[i], coupons,
                               vars.bondDayCounter, vars.bondConvention,
                               vars.bondRedemption, issue);

            final PricingEngine bondEngine = new DiscountingBondEngine(curveHandle);
            bond.setPricingEngine(bondEngine);

            /*@Real*/ final double expectedPrice = bondData[i].price, estimatedPrice = bond.cleanPrice();
            /*@Real*/ final double error = Math.abs(expectedPrice-estimatedPrice);
            if (error > tolerance) {
              throw new RuntimeException(
                  String.format("#%d %s %s %f %s %f %s %f",
                  i+1, " bond failure:",
                            "\n  estimated price: ", estimatedPrice,
                            "\n  expected price:  ", expectedPrice,
                            "\n  error:           ", error));
            }
        }

        // check FRA
        vars.termStructure = new PiecewiseYieldCurve<T,I,B>(
                      classT, classI, classB,
                      vars.settlement, vars.fraHelpers,
                                    new Actual360(),
                  new Handle/*<Quote>*/[0],
                  new Date[0],
                                    1.0e-12,
                                    interpolator);
        curveHandle.linkTo(vars.termStructure);

        final IborIndex euribor3m = new Euribor3M(curveHandle);
        for (int i=0; i<vars.fras; i++) {
            final Date start = vars.calendar.advance(vars.settlement,
                                           fraData[i].n,
                                           fraData[i].units,
                                           euribor3m.businessDayConvention(),
                                           euribor3m.endOfMonth());
            final Date end = vars.calendar.advance(start, 3, TimeUnit.Months,
                                             euribor3m.businessDayConvention(),
                                             euribor3m.endOfMonth());

            final ForwardRateAgreement fra = new ForwardRateAgreement(start, end, Position.Long,
                                      fraData[i].rate/100, 100.0,
                                      euribor3m, curveHandle);
            /*@Rate*/ final double expectedRate  = fraData[i].rate/100;
View Full Code Here


        final Handle<YieldTermStructure> riskFreeCurve = new Handle<YieldTermStructure>(new FlatForward(vars.settlement, 0.04, new Actual360()));

        final BMAIndex bmaIndex = new BMAIndex();
        final IborIndex liborIndex = new USDLibor(new Period(3, TimeUnit.Months), riskFreeCurve);
        for (int i=0; i<vars.bmas; ++i) {
            final Handle<Quote> f = new Handle<Quote>(vars.fractions[i]);
            vars.bmaHelpers[i] = // boost::shared_ptr<RateHelper>(
                      new BMASwapRateHelper(f, new Period(bmaData[i].n, bmaData[i].units),
                                            vars.settlementDays,
                                            vars.calendar,
                                            new Period(vars.bmaFrequency),
                                            vars.bmaConvention,
                                            vars.bmaDayCounter,
                                            bmaIndex,
                                            liborIndex);
        }

        final Weekday w = vars.today.weekday();
        final Date lastWednesday = (w.ordinal() >= 4) ? vars.today.sub(w.ordinal() - 4) : vars.today.add(4 - w.ordinal() - 7);
        final Date lastFixing = bmaIndex.fixingCalendar().adjust(lastWednesday);
        bmaIndex.addFixing(lastFixing, 0.03);

        vars.termStructure = new PiecewiseYieldCurve<T,I,B>(
                      classT, classI, classB,
                      vars.settlement, vars.bmaHelpers,
                                    new Actual360(),
                                    new Handle/*<Quote>*/[0],
                                    new Date[0],
                                    1.0e-12,
                                    interpolator);

        final RelinkableHandle<YieldTermStructure> curveHandle = new RelinkableHandle<YieldTermStructure>();
        curveHandle.linkTo(vars.termStructure);

        // check BMA swaps
        final BMAIndex bma = new BMAIndex(curveHandle);
        final IborIndex libor3m = new USDLibor(new Period(3, TimeUnit.Months), riskFreeCurve);
        for (int i=0; i<vars.bmas; i++) {
            final Period tenor = new Period(bmaData[i].n, bmaData[i].units);

            final Schedule bmaSchedule = new MakeSchedule(vars.settlement,
                                                  vars.settlement.add(tenor),
                                                  new Period(vars.bmaFrequency),
                                                  bma.fixingCalendar(),
                                                  vars.bmaConvention)
                                    .backwards()
                                    .schedule();
            final Schedule liborSchedule = new MakeSchedule(vars.settlement,
                                                      vars.settlement.add(tenor),
                                                      libor3m.tenor(),
                                                      libor3m.fixingCalendar(),
                                                      libor3m.businessDayConvention())
                                      .endOfMonth(libor3m.endOfMonth())
                                      .backwards()
                                      .schedule();


            final BMASwap swap = new BMASwap(BMASwap.Type.Payer, 100.0,
                               liborSchedule, 0.75, 0.0,
                               libor3m, libor3m.dayCounter(),
                               bmaSchedule, bma, vars.bmaDayCounter);
            swap.setPricingEngine(new DiscountingSwapEngine(libor3m.termStructure()));

            /*@Real*/ final double expectedFraction = bmaData[i].rate/100;
            /*@Real*/ final double estimatedFraction = swap.fairLiborFraction();
            /*@Real*/ final double error = Math.abs(expectedFraction-estimatedFraction);
            if (error > tolerance) {
View Full Code Here

      QL.info("Testing use of today's LIBOR fixings in swap curve...");

      final CommonVars vars = new CommonVars();

      final RateHelper[] swapHelpers = new RateHelper[vars.swaps];
      final IborIndex euribor6m = new Euribor6M();

      for (int i=0; i<vars.swaps; i++) {
          final Handle<Quote> r = new Handle<Quote>(vars.rates[i+vars.deposits]);
          swapHelpers[i] = new SwapRateHelper(
                         r, new Period(swapData[i].n, swapData[i].units),
                             vars.calendar,
                             vars.fixedLegFrequency, vars.fixedLegConvention,
                             vars.fixedLegDayCounter, euribor6m);
      }

      vars.termStructure = new PiecewiseYieldCurve(
                  Discount.class, LogLinear.class, IterativeBootstrap.class,
                  vars.settlement,
                  swapHelpers,
                          new Actual360());

      final Handle<YieldTermStructure> curveHandle = new Handle<YieldTermStructure>(vars.termStructure);

      final IborIndex index = new Euribor6M(curveHandle);
      for (int i=0; i<vars.swaps; i++) {
          final Period tenor = new Period(swapData[i].n, swapData[i].units);

          final VanillaSwap swap = new MakeVanillaSwap(tenor, index, 0.0)
              .withEffectiveDate(vars.settlement)
              .withFixedLegDayCount(vars.fixedLegDayCounter)
              .withFixedLegTenor(new Period(vars.fixedLegFrequency))
              .withFixedLegConvention(vars.fixedLegConvention)
              .withFixedLegTerminationDateConvention(vars.fixedLegConvention)
                  .value();

          /*@Rate*/ final double expectedRate  = swapData[i].rate/100;
          /*@Rate*/ final double estimatedRate = swap.fairRate();
          /*@Real*/ final double tolerance = 1.0e-9;
          if (Math.abs(expectedRate-estimatedRate) > tolerance) {
            throw new RuntimeException(
                String.format("%s %d %s %s %f %s %s %f",
                  "before LIBOR fixing:\n",
                          swapData[i].n, " year(s) swap:\n",
                          "    estimated rate: ", estimatedRate, "\n",
                          "    expected rate:  ", expectedRate));
          }
      }

      final Flag f = new Flag();
      vars.termStructure.addObserver(f);
      f.lower();

      index.addFixing(vars.today, 0.0425);

      if (!f.isUp())
          throw new RuntimeException("Observer was not notified of rate fixing");

      for (int i=0; i<vars.swaps; i++) {
View Full Code Here

      }

      // rate helpers
      vars.instruments = new RateHelper[vars.swaps];

      final IborIndex index = new JPYLibor(new Period(6, TimeUnit.Months));
      for (int i=0; i<vars.swaps; i++) {
          final Handle<Quote> r = new Handle<Quote>(vars.rates[i]);
          vars.instruments[i] = new SwapRateHelper(
                        r, new Period(swapData[i].n, swapData[i].units),
                        vars.calendar,                         // TODO: code review on this line!!!!
                        vars.fixedLegFrequency, vars.fixedLegConvention,
                                  vars.fixedLegDayCounter, index);
      }
     
      vars.termStructure = new PiecewiseYieldCurve(
                      Discount.class, LogLinear.class, IterativeBootstrap.class,
                                      vars.settlement, vars.instruments,
                                      new Actual360(),
                    new Handle/*<Quote>*/[0],
                    new Date[0],
                                      1.0e-12);

        final RelinkableHandle<YieldTermStructure> curveHandle = new RelinkableHandle<YieldTermStructure>();
      curveHandle.linkTo(vars.termStructure);

      // check swaps
      final IborIndex jpylibor6m = new JPYLibor(new Period(6, TimeUnit.Months), curveHandle);
      for (int i=0; i<vars.swaps; i++) {
          final Period tenor = new Period(swapData[i].n, swapData[i].units);

          final VanillaSwap swap = new MakeVanillaSwap(tenor, jpylibor6m, 0.0)
              .withEffectiveDate(vars.settlement)
View Full Code Here

            fraHelpers  = new RateHelper[fras];
            bondHelpers = new RateHelper[bonds];
            schedules   = new Schedule[bonds];
            bmaHelpers  = new RateHelper[bmas];
           
            final IborIndex euribor6m = new Euribor(new Period(6, TimeUnit.Months), new Handle<YieldTermStructure>());
            for (int i=0; i<deposits; i++) {
                final Handle<Quote> r = new Handle<Quote>(rates[i]);
                instruments[i] = new
                    DepositRateHelper(r, new Period(depositData[i].n,depositData[i].units),
                                      euribor6m.fixingDays(), calendar,
                                      euribor6m.businessDayConvention(),
                                      euribor6m.endOfMonth(),
                                      euribor6m.dayCounter());
            }

            for (int i=0; i<swaps; i++) {
                final Handle<Quote> r = new Handle<Quote>(rates[i+deposits]);
                instruments[i+deposits] = new
View Full Code Here

      final int settlementDays = 1;

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

    final IborIndex index = new USDLibor(new Period(6,TimeUnit.Months), riskFreeRate);
      final int fixingDays = 1;

      final double tolerance = 1.0e-6;

      final IborCouponPricer pricer = new BlackIborCouponPricer(new Handle<OptionletVolatilityStructure>());
View Full Code Here

          + "\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 };
View Full Code Here

     * @see org.jquantlib.termstructures.yield.RelativeDateRateHelper#initializeDates()
     */
    @Override
    protected void initializeDates() {
        // dummy ibor index with curve/swap arguments
        final IborIndex clonedIborIndex = iborIndex.clone(this.termStructureHandle).currentLink();

        // do not pass the spread here, as it might be a Quote i.e. it can dynamically change
        this.swap = new MakeVanillaSwap(tenor, clonedIborIndex, 0.0, fwdStart)
        .withFixedLegDayCount(fixedDayCount)
        .withFixedLegTenor(new Period(fixedFrequency))
View Full Code Here

TOP

Related Classes of org.jquantlib.indexes.IborIndex

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.