Package org.jquantlib.daycounters

Examples of org.jquantlib.daycounters.Actual360$Impl


  public CHFLibor(final Period tenor,
      final Handle<YieldTermStructure> h) {
    super("CHFLibor", tenor, 2,
        new CHFCurrency(),
        new Switzerland(),
        new Actual360(), h);
  }
View Full Code Here


                new JointCalendar(new UnitedKingdom(Market.Exchange),
                          new Target(),
                          JointCalendarRule.JoinBusinessDays),
                eurliborConvention(tenor),
                eurliborEOM(tenor),
                new Actual360(),
                h);
        QL.require(tenor().units() != TimeUnit.Days , "for daily tenors dedicated DailyTenor constructor must be used");
       
        this.target = new Target();
    }
View Full Code Here

                settlementDays, // settlement days
                new EURCurrency(),
                new Target(),
                euriborConvention(new Period(1,TimeUnit.Days)),
                euriborEOM(new Period(1,TimeUnit.Days)),
                new Actual360(),
                h);
      }
View Full Code Here

            /*@Real*/ final double tolerance) {
     
        vars.termStructure = new PiecewiseYieldCurve<T,I,B>(
                    classT, classI, classB,
                    vars.settlement, vars.instruments,
                    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 deposits
        for (int i=0; i<vars.deposits; i++) {
            final Euribor index = new Euribor(new Period(depositData[i].n, depositData[i].units), curveHandle);
            /*@Rate*/ final double expectedRate  = depositData[i].rate/100;
            /*@Rate*/ final double estimatedRate = index.fixing(vars.today);
            if (Math.abs(expectedRate-estimatedRate) > tolerance) {
              throw new RuntimeException(
                  String.format("%d %s %s %s %f %s %f",
                      depositData[i].n,
                      depositData[i].units == TimeUnit.Weeks ? "week(s)" : "month(s)",
                      " deposit:",
                      "\n    estimated rate: ", estimatedRate,
                      "\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);
View Full Code Here

        vars.today = vars.calendar.adjust(Date.todaysDate());
        new Settings().setEvaluationDate(vars.today);
        vars.settlement = vars.calendar.advance(vars.today, vars.settlementDays, TimeUnit.Days);


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

View Full Code Here

      vars.termStructure = new PiecewiseYieldCurve(
                      Discount.class, LogLinear.class, IterativeBootstrap.class,
                      vars.settlementDays,
                      vars.calendar,
                          vars.instruments,
                          new Actual360());
      final Flag f = new Flag();
      vars.termStructure.addObserver(f);

      for (int i=0; i<vars.deposits+vars.swaps; i++) {
          /*@Time*/ final double testTime = new Actual360().yearFraction(vars.settlement, vars.instruments[i].latestDate());
          /*@DiscountFactor*/ final double discount = vars.termStructure.discount(testTime);
          f.lower();
          vars.rates[i].setValue(vars.rates[i].value()*1.01);
          if (!f.isUp())
              throw new RuntimeException("Observer was not notified of underlying rate change");
View Full Code Here

      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++) {
View Full Code Here

      }
     
      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>();
View Full Code Here

                new HaugMertonData( Option.Type.Call, 120.00, 100.00, 0.00, 0.08, 0.25, 0.25,10.00.750.67, 1e-2) ,
                new HaugMertonData( Option.Type.Call, 120.00, 100.00, 0.00, 0.08, 0.50, 0.25,10.00.752.23, 1e-2// Haug 2.17
        };

        final Date today = new Settings().evaluationDate();
        final DayCounter dc = new Actual360();

        final SimpleQuote           spot  = new SimpleQuote(0.0);
        final SimpleQuote           qRate = new SimpleQuote(0.0);
        final YieldTermStructure    qTS   = Utilities.flatRate(today, qRate, dc);
        final SimpleQuote           rRate = new SimpleQuote(0.0);
View Full Code Here

        final double vols[] = { 0.11 };
        final double jInt[] = { 1.0, 5.0 };
        final double mLJ[] = { -0.20, 0.0, 0.20 };
        final double jV[] = { 0.01, 0.25 };

        final DayCounter dc = new Actual360();
        new Settings().setEvaluationDate(Date.todaysDate());
        final Date today = new Settings().evaluationDate();

        final SimpleQuote           spot  = new SimpleQuote(0.0);
        final SimpleQuote           qRate = new SimpleQuote(0.0);
        final YieldTermStructure    qTS   = Utilities.flatRate(qRate, dc);
        final SimpleQuote           rRate = new SimpleQuote(0.0);
        final YieldTermStructure    rTS   = Utilities.flatRate(rRate, dc);
        final SimpleQuote           vol   = new SimpleQuote(0.0);
        final BlackVolTermStructure volTS = Utilities.flatVol(vol, dc);

        final SimpleQuote jumpIntensity = new SimpleQuote(0.0);
        final SimpleQuote meanLogJump   = new SimpleQuote(0.0);
        final SimpleQuote jumpVol       = new SimpleQuote(0.0);

        final Merton76Process stochProcess = new Merton76Process(
                new Handle<Quote>(spot),
                new Handle<YieldTermStructure>(qTS),
                new Handle<YieldTermStructure>(rTS),
                new Handle<BlackVolTermStructure>(volTS),
                new Handle<Quote>(jumpIntensity),
                new Handle<Quote>(meanLogJump),
                new Handle<Quote>(jumpVol));

        // The jumpdiffusionengine greeks are very sensitive to the convergence level.
        // A tolerance of 1.0e-08 is usually sufficient to get reasonable results
        final PricingEngine engine = new JumpDiffusionEngine(stochProcess, 1e-08);

        for (final Type type : types) {
            for (final double strike : strikes) {
                for (final double element : jInt) {
                    jumpIntensity.setValue(element);
                    for (final double element2 : mLJ) {
                        meanLogJump.setValue(element2);
                        for (final double element3 : jV) {
                            jumpVol.setValue(element3);
                            for (final double residualTime : residualTimes) {
                                final Date exDate = today.add((int) (residualTime * 360 + 0.5));
                                final Exercise exercise = new EuropeanExercise(exDate);

                                for (int kk = 0; kk < 1; kk++) {
                                    StrikedTypePayoff payoff = null;
                                    // option to check
                                    if (kk == 0) {
                                        payoff = new PlainVanillaPayoff(type, strike);
                                    } else if (kk == 1) {
                                        payoff = new CashOrNothingPayoff(type, strike, 100.0);
                                    } else if (kk == 2) {
                                        payoff = new AssetOrNothingPayoff(type, strike);
                                    } else if (kk == 3) {
                                        payoff = new GapPayoff(type, strike, 100.0);
                                    }
                                    final EuropeanOption option = new EuropeanOption(payoff, exercise);
                                    option.setPricingEngine(engine);

                                    for (final double u : underlyings) {
                                        for (final double q : qRates) {
                                            for (final double r : rRates) {
                                                for (final double v : vols) {
                                                    spot.setValue(u);
                                                    qRate.setValue(q);
                                                    rRate.setValue(r);
                                                    vol.setValue(v);

                                                    final double value = option.NPV();
                                                    calculated.put("delta", option.delta());
                                                    calculated.put("gamma", option.gamma());
                                                    calculated.put("theta", option.theta());
                                                    calculated.put("rho", option.rho());
                                                    calculated.put("divRho", option.dividendRho());
                                                    calculated.put("vega", option.vega());

                                                    if (value > spot.value() * 1.0e-5) {
                                                        // perturb spot and get delta and gamma
                                                        final double du = u * 1.0e-5;
                                                        spot.setValue(u + du);
                                                        double value_p = option.NPV();
                                                        final double delta_p = option.delta();
                                                        spot.setValue(u - du);
                                                        double value_m = option.NPV();
                                                        final double delta_m = option.delta();
                                                        spot.setValue(u);
                                                        expected.put("delta", (value_p - value_m) / (2 * du));
                                                        expected.put("gamma", (delta_p - delta_m) / (2 * du));

                                                        // perturb rates and get rho and dividend rho
                                                        final double dr = 1.0e-5;
                                                        rRate.setValue(r + dr);
                                                        value_p = option.NPV();
                                                        rRate.setValue(r - dr);
                                                        value_m = option.NPV();
                                                        rRate.setValue(r);
                                                        expected.put("rho", (value_p - value_m) / (2 * dr));

                                                        final double dq = 1.0e-5;
                                                        qRate.setValue(q + dq);
                                                        value_p = option.NPV();
                                                        qRate.setValue(q - dq);
                                                        value_m = option.NPV();
                                                        qRate.setValue(q);
                                                        expected.put("divRho", (value_p - value_m) / (2 * dq));

                                                        // perturb volatility and get vega
                                                        final double dv = v * 1.0e-4;
                                                        vol.setValue(v + dv);
                                                        value_p = option.NPV();
                                                        vol.setValue(v - dv);
                                                        value_m = option.NPV();
                                                        vol.setValue(v);
                                                        expected.put("vega", (value_p - value_m) / (2 * dv));

                                                        final Date yesterday = today.sub(1);
                                                        final Date tomorrow = today.add(1);
                                                        final double dT = dc.yearFraction(yesterday, tomorrow);
                                                        new Settings().setEvaluationDate(yesterday);
                                                        value_m = option.NPV();
                                                        new Settings().setEvaluationDate(tomorrow);
                                                        value_p = option.NPV();
                                                        new Settings().setEvaluationDate(today);
View Full Code Here

TOP

Related Classes of org.jquantlib.daycounters.Actual360$Impl

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.