Examples of EuropeanOption


Examples of org.jquantlib.instruments.EuropeanOption

                    new Handle<YieldTermStructure>(rTS),
                    new Handle<BlackVolTermStructure>(volTS));

            final PricingEngine engine = new AnalyticEuropeanEngine(stochProcess);

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

            final double calculated = option.NPV();
            final double error = Math.abs(calculated-values[i].result);
            final double tolerance = values[i].tol;

            final StringBuilder sb = new StringBuilder();
            sb.append("error ").append(error).append(" .gt. tolerance ").append(tolerance).append('\n');
View Full Code Here

Examples of org.jquantlib.instruments.EuropeanOption

                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();
        error = Math.abs(Math.abs(calculated - values[i].result));
        if(error>tolerance) {
            REPORT_FAILURE("dividend rho", payoff, exercise, values[i].s, values[i].q, values[i].r, today, values[i].v,
                    values[i].result, calculated, error, tolerance);
        }
View Full Code Here

Examples of org.jquantlib.instruments.EuropeanOption

                        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);
                                            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(Date.todaysDate());
                                            expected.put("theta", (value_p - value_m)/dT);

                                            // compare
                                            for (final Entry<String, Double> it: calculated.entrySet()){
View Full Code Here

Examples of org.jquantlib.instruments.EuropeanOption

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

        if (Math.abs(option2.NPV() - refValue) <= 1.0e-8) {
            fail("volatility change did not cause the value to change");
        }
    }
View Full Code Here

Examples of org.jquantlib.instruments.EuropeanOption

            final double volError = Math.abs(totalVol - value.v);

            if (volError >= 1.0e-13)
                throw new ArithmeticException(" mismatch");

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

            final double /* @Real */calculated = option.NPV();
            final double /* @Real */error = Math.abs(calculated - value.result);
            if (error > value.tol) {
                REPORT_FAILURE_2("value", payoff, exercise, value.s, value.q, value.r, today, value.v,
                        value.jumpIntensity, value.gamma, value.result, calculated, error, value.tol);
            }
View Full Code Here

Examples of org.jquantlib.instruments.EuropeanOption

                                    } 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);
                                                        expected.put("theta", (value_p - value_m) / dT);

                                                        // compare
                                                        for (final Entry<String, Double> it : calculated.entrySet()) {
View Full Code Here

Examples of org.jquantlib.instruments.EuropeanOption

            break;
        default:
            throw new IllegalStateException("unknown engine type");
        }

        final VanillaOption option = new EuropeanOption(payoff, exercise);
        option.setPricingEngine(engine);
        return option;
    }
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.