Examples of SimpleQuote


Examples of org.jquantlib.quotes.SimpleQuote

          final Date dated = today;
          final Date issue = dated;
          final Date maturity = calendar.advance(issue, length, TimeUnit.Years);

          final SimpleQuote rate = new SimpleQuote(0.0);
          final Handle<YieldTermStructure> discountCurve = new Handle<YieldTermStructure>(Utilities.flatRate(today, rate, bondDayCount));

          final Schedule sch = new Schedule(
                  dated, maturity,
              new Period(frequency), calendar,
              accrualConvention, accrualConvention,
              Rule.Backward, false);

          final FixedRateBond bond = new FixedRateBond(
                  settlementDays, faceAmount, sch,
              new double[] { coupon },
              bondDayCount, paymentConvention,
              redemption, issue);

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

          for (final double yield : yields) {

            rate.setValue(yield);

            final double price = bond.cleanPrice(yield, bondDayCount, Compounding.Continuous, frequency);
            final double calculatedPrice = bond.getCleanPrice();

            if (Math.abs(price-calculatedPrice) > tolerance) {
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

        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);
        final YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
        final SimpleQuote           vol   = new SimpleQuote(0.0);
        final BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

        for (int i=0; i<values.length-1; i++) {

            QL.debug(values[i].toString());

            final StrikedTypePayoff payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
            final Date exDate = today.add( timeToDays(values[i].t) );
            final Exercise exercise = new EuropeanExercise(exDate);

            spot.setValue(values[i].s);
            qRate.setValue(values[i].q);
            rRate.setValue(values[i].r);
            vol.setValue(values[i].v);


            final BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(
                    new Handle<Quote>(spot),
                    new Handle<YieldTermStructure>(qTS),
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote


        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);
        final YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
        final SimpleQuote           vol   = new SimpleQuote(0.0);
        final BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);


        StrikedTypePayoff payoff;
        Date exDate;
        Exercise exercise;
        double calculated;
        double error;

        int i = -1;

        // testing delta 1
        i++;
        payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
        exDate = today.add(timeToDays(values[i].t));
        exercise = new EuropeanExercise(exDate);
        spot.setValue(values[i].s);
        qRate.setValue(values[i].q);
        rRate.setValue(values[i].r);
        vol.setValue(values[i].v);

        final BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(
                new Handle<Quote>(spot),
                new Handle<YieldTermStructure>(qTS),
                new Handle<YieldTermStructure>(rTS),
                new Handle<BlackVolTermStructure>(volTS));
        final PricingEngine engine = new AnalyticEuropeanEngine(stochProcess);

        VanillaOption option = new EuropeanOption(payoff, exercise);
        option.setPricingEngine(engine);

        calculated = option.delta();
        error = Math.abs(calculated - values[i].result);

        if (error > tolerance) {
            REPORT_FAILURE("delta", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
                    values[i].result, calculated, error, tolerance);
        }

        //testing delta 2
        i++;
        payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
        exDate = today.add(timeToDays(values[i].t));
        exercise = new EuropeanExercise(exDate);
        spot.setValue(values[i].s);
        qRate.setValue(values[i].q);
        rRate.setValue(values[i].r);
        vol.setValue(values[i].v);

        option = new EuropeanOption(payoff, exercise);
        option.setPricingEngine(engine);

        calculated = option.delta();
        error = Math.abs(calculated - values[i].result);
        if(error>tolerance) {
            REPORT_FAILURE("delta", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
                    values[i].result, calculated, error, tolerance);
        }

        //testing elasticity
        i++;
        payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
        exDate = today.add(timeToDays(values[i].t));
        exercise = new EuropeanExercise(exDate);
        spot.setValue(values[i].s);
        qRate.setValue(values[i].q);
        rRate.setValue(values[i].r);
        vol.setValue(values[i].v);

        option = new EuropeanOption(payoff, exercise);
        option.setPricingEngine(engine);

        calculated = option.elasticity();
        error = Math.abs(Math.abs(calculated - values[i].result));
        if(error>tolerance) {
            REPORT_FAILURE("elasticity", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
                    values[i].result, calculated, error, tolerance);
        }

        // testing gamma 1
        i++;
        payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
        exDate = today.add(timeToDays(values[i].t));
        exercise = new EuropeanExercise(exDate);
        spot.setValue(values[i].s);
        qRate.setValue(values[i].q);
        rRate.setValue(values[i].r);
        vol.setValue(values[i].v);

        option = new EuropeanOption(payoff, exercise);
        option.setPricingEngine(engine);

        calculated = option.gamma();
        error = Math.abs(Math.abs(calculated - values[i].result));
        if(error>tolerance) {
            REPORT_FAILURE("gamma", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
                    values[i].result, calculated, error, tolerance);
        }

        // testing gamma 2
        i++;
        payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
        exDate = today.add(timeToDays(values[i].t));
        exercise = new EuropeanExercise(exDate);
        spot.setValue(values[i].s);
        qRate.setValue(values[i].q);
        rRate.setValue(values[i].r);
        vol.setValue(values[i].v);

        option = new EuropeanOption(payoff, exercise);
        option.setPricingEngine(engine);

        calculated = option.gamma();
        error = Math.abs(Math.abs(calculated - values[i].result));
        if(error>tolerance) {
            REPORT_FAILURE("gamma", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
                    values[i].result, calculated, error, tolerance);
        }

        //testing vega 1
        i++;
        payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
        exDate = today.add(timeToDays(values[i].t));
        exercise = new EuropeanExercise(exDate);
        spot.setValue(values[i].s);
        qRate.setValue(values[i].q);
        rRate.setValue(values[i].r);
        vol.setValue(values[i].v);

        option = new EuropeanOption(payoff, exercise);
        option.setPricingEngine(engine);

        calculated = option.vega();
        error = Math.abs(Math.abs(calculated - values[i].result));
        if(error>tolerance) {
            REPORT_FAILURE("vega", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
                    values[i].result, calculated, error, tolerance);
        }

        //testing vega 2
        i++;
        payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
        exDate = today.add(timeToDays(values[i].t));
        exercise = new EuropeanExercise(exDate);
        spot.setValue(values[i].s);
        qRate.setValue(values[i].q);
        rRate.setValue(values[i].r);
        vol.setValue(values[i].v);

        option = new EuropeanOption(payoff, exercise);
        option.setPricingEngine(engine);

        calculated = option.vega();
        error = Math.abs(Math.abs(calculated - values[i].result));
        if(error>tolerance) {
            REPORT_FAILURE("vega", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
                    values[i].result, calculated, error, tolerance);
        }

        //testing theta
        i++;
        payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
        exDate = today.add(timeToDays(values[i].t));
        exercise = new EuropeanExercise(exDate);
        spot.setValue(values[i].s);
        qRate.setValue(values[i].q);
        rRate.setValue(values[i].r);
        vol.setValue(values[i].v);

        option = new EuropeanOption(payoff, exercise);
        option.setPricingEngine(engine);

        calculated = option.theta();
        error = Math.abs(Math.abs(calculated - values[i].result));
        if(error>tolerance) {
            REPORT_FAILURE("theta", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
                    values[i].result, calculated, error, tolerance);
        }


        //testing theta per day
        i++;
        payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
        exDate = today.add(timeToDays(values[i].t));
        exercise = new EuropeanExercise(exDate);
        spot.setValue(values[i].s);
        qRate.setValue(values[i].q);
        rRate.setValue(values[i].r);
        vol.setValue(values[i].v);

        option = new EuropeanOption(payoff, exercise);
        option.setPricingEngine(engine);

        calculated = option.thetaPerDay();
        error = Math.abs(Math.abs(calculated - values[i].result));
        if(error>tolerance) {
            REPORT_FAILURE("theta per day", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
                    values[i].result, calculated, error, tolerance);
        }


        //testing rho
        i++;
        payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
        exDate = today.add(timeToDays(values[i].t));
        exercise = new EuropeanExercise(exDate);
        spot.setValue(values[i].s);
        qRate.setValue(values[i].q);
        rRate.setValue(values[i].r);
        vol.setValue(values[i].v);

        option = new EuropeanOption(payoff, exercise);
        option.setPricingEngine(engine);

        calculated = option.rho();
        error = Math.abs(Math.abs(calculated - values[i].result));
        if(error>tolerance) {
            REPORT_FAILURE("rho", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
                    values[i].result, calculated, error, tolerance);
        }

        //testing dividend rho
        i++;
        payoff = new PlainVanillaPayoff(values[i].type, values[i].strike);
        exDate = today.add(timeToDays(values[i].t));
        exercise = new EuropeanExercise(exDate);
        spot.setValue(values[i].s);
        qRate.setValue(values[i].q);
        rRate.setValue(values[i].r);
        vol.setValue(values[i].v);

        option = new EuropeanOption(payoff, exercise);
        option.setPricingEngine(engine);

        calculated = option.dividendRho();
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

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

        for (final Type type : types) {
            for (final double strike : strikes) {
                for (final double residualTime : residualTimes) {

                    final Date exDate = today.add( timeToDays(residualTime) ); //TODO: code review
                    final Exercise exercise = new EuropeanExercise(exDate);

                    for (int kk=0; kk<4; kk++) {
                        StrikedTypePayoff payoff = null;
                        // option to check
                        if (kk==0) {
                            payoff = new PlainVanillaPayoff(type, strike);
                        } else if (kk==1) {
                            //FIXME check constructor
                            payoff = new CashOrNothingPayoff(type, strike, 100);
                        } else if (kk==2) {
                            payoff = new AssetOrNothingPayoff(type, strike);
                        } else if (kk==3) {
                            payoff = new GapPayoff(type, strike, 100);
                        }

                        final BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(
                                new Handle<Quote>(spot),
                                new Handle<YieldTermStructure>(qTS),
                                new Handle<YieldTermStructure>(rTS),
                                new Handle<BlackVolTermStructure>(volTS));
                        final PricingEngine engine = new AnalyticEuropeanEngine(stochProcess);

                        if (payoff==null)
                            throw new IllegalArgumentException();

                        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) {
                                        //something wrong here for vanilla payoff?
                                        spot.setValue(u);
                                        qRate.setValue(q);
                                        rRate.setValue(r);
                                        vol.setValue(v);

                                        final double value = option.NPV();
                                        final double delta = option.delta();
                                        final double gamma = option.gamma();
                                        final double theta = option.theta();
                                        final double rho   = option.rho();
                                        final double drho  = option.dividendRho();
                                        final double vega  = option.vega();

                                        calculated.put("delta",  delta);
                                        calculated.put("gamma",  gamma);
                                        calculated.put("theta",  theta);
                                        calculated.put("rho",    rho);
                                        calculated.put("divRho", drho);
                                        calculated.put("vega",   vega);

                                        if (value > spot.value()*1.0e-5) {
                                            // perturb spot and get delta and gamma
                                            final double du = u*1.0e-4;
                                            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 = r*1.0e-4;
                                            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 = q*1.0e-4;
                                            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));

                                            // perturb date and get theta
                                            final Date yesterday = today.sub(1);
                                            final Date tomorrow  = today.add(1);
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

        final double vols[] = { 0.01, 0.20, 0.30, 0.70, 0.90 };

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

        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);
        final YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
        final SimpleQuote           vol   = new SimpleQuote(0.0);
        final BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

        for (final Type type : types) {
            for (final double strike2 : strikes) {
                for (final int length : lengths) {
                    // option to check
                    final Date exDate = today.add( length );
                    final Exercise exercise = new EuropeanExercise(exDate);
                    final StrikedTypePayoff payoff = new PlainVanillaPayoff(type, strike2);
                    final VanillaOption option = makeOption(payoff, exercise, spot, qTS, rTS, volTS, EngineType.Analytic, 0, 0);

                    final GeneralizedBlackScholesProcess process = makeProcess(spot, qTS, rTS,volTS);

                    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();
                                    double implVol = 0.0; // just to remove a warning...
                                    if (value != 0.0) {
                                        // shift guess somehow
                                        vol.setValue(v*0.5);
                                        if (Math.abs(value-option.NPV()) <= 1.0e-12) {
                                            // flat price vs vol --- pointless (and
                                            // numerically unstable) to solve
                                            continue;
                                        }

                                        implVol = option.impliedVolatility(value, process, tolerance, maxEvaluations);

                                        if (Math.abs(implVol-v) > tolerance) {
                                            // the difference might not matter
                                            vol.setValue(implVol);
                                            final double value2 = option.NPV();
                                            final double error = Utilities.relativeError(value,value2,u);
                                            if (error > tolerance) {
                                                fail(
                                                        type + " option :\n"
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

        final double tolerance = 1.0e-6;

        final Date today = new Settings().evaluationDate();

        final DayCounter dc = new Actual360();
        final SimpleQuote           spot  = new SimpleQuote(100.0);
        final Quote                 u     = spot;
        final SimpleQuote           qRate = new SimpleQuote(0.05);
        final YieldTermStructure    qTS   = Utilities.flatRate(today, qRate, dc);
        final SimpleQuote           rRate = new SimpleQuote(0.003);
        final YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
        final SimpleQuote           vol   = new SimpleQuote(0.20);
        final BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

        final Date exerciseDate = today.add(Period.ONE_YEAR_FORWARD);
        final Exercise exercise = new EuropeanExercise(exerciseDate);
        final StrikedTypePayoff payoff = new PlainVanillaPayoff(Option.Type.Call, 100);

        final BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(
                new Handle<Quote>(u),
                new Handle<YieldTermStructure>(qTS),
                new Handle<YieldTermStructure>(rTS),
                new Handle<BlackVolTermStructure>(volTS));
        final PricingEngine engine = new AnalyticEuropeanEngine(stochProcess);

        final EuropeanOption option1 = new EuropeanOption(payoff, exercise);
        final EuropeanOption option2 = new EuropeanOption(payoff, exercise);
        option1.setPricingEngine(engine);
        option2.setPricingEngine(engine);

        // test
        final double refValue = option2.NPV();

        final Flag f = new Flag();
        option2.addObserver(f);

        option1.impliedVolatility(refValue*1.5, stochProcess, tolerance, maxEvaluations);

        if (f.isUp()) {
            fail("implied volatility calculation triggered a change in another instrument");
        }

        option2.recalculate();
        if (Math.abs(option2.NPV() - refValue) >= 1.0e-8) {
            fail("implied volatility calculation changed the value "
                    + "of another instrument: \n"
                    + "previous value: " + refValue + "\n"
                    + "current value:  " + option2.NPV());
        }

        vol.setValue(vol.value()*1.5);

        if (!f.isUp()) {
            fail("volatility change not notified");
        }

View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

        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);
        final YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
        final SimpleQuote           vol   = new SimpleQuote(0.0);
        final BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

        for (final Type type : types) {
            for (final double strike3 : strikes) {
                for (final int length2 : lengths) {

                    final Date exDate = today.add(timeToDays(length2));
                    final Exercise exercise = new EuropeanExercise(exDate);

                    final StrikedTypePayoff payoff = new PlainVanillaPayoff(type, strike3);

                    // reference option
                    final VanillaOption refOption = makeOption(payoff, exercise, spot, qTS, rTS, volTS, EngineType.Analytic, 0, 0);
                    // option to check
                    final VanillaOption option = makeOption(payoff, exercise, spot, qTS, rTS, volTS, engine, binomialSteps, samples);

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

                                    expected.clear();
                                    calculated.clear();

                                    final double refNPV = refOption.NPV();
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

        initializeDates();

    }

    public FraRateHelper(final double rate, final int monthsToStart, final IborIndex i) {
        this (new Handle <Quote> (new SimpleQuote (rate)), monthsToStart, i);
        QL.validateExperimentalMode();
    }
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

            final double conv) {
        super(price);
        QL.validateExperimentalMode();

        QL.require(new IMM().isIMMdate(immDate, false) , "not a valid IMM date"); // QA:[RG]::verified // TODO: message
        convAdj = new Handle<Quote>(new SimpleQuote(conv));
        earliestDate = immDate;
        latestDate = calendar.advance(
                immDate,
                new Period(nMonths, TimeUnit.Months),
                convention,
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

            final double conv) {
        super(price);
        QL.validateExperimentalMode();

        QL.require(new IMM().isIMMdate(immDate, false) , "not a valid IMM date"); // QA:[RG]::verified // TODO: message
        convAdj = new Handle<Quote>(new SimpleQuote(conv));
        earliestDate = immDate;
        final Calendar cal = i.fixingCalendar();
        latestDate = cal.advance(immDate, i.tenor(), i.businessDayConvention());
        yearFraction = i.dayCounter().yearFraction(earliestDate, latestDate);
    }
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.