Package org.jquantlib.instruments

Examples of org.jquantlib.instruments.DiscreteAveragingAsianOption$EngineImpl


        QL.info("Average Dates:\n");
        for (final Date d : fixingDates) {
            QL.info(d.toString());
        }

        final DiscreteAveragingAsianOption option = new DiscreteAveragingAsianOption(
                averageType, runningAccumulator, pastFixings, fixingDates, payoff, exercise);
        option.setPricingEngine(engine);

        /* @Real */final double calculated = option.NPV();
        /* @Real */final double expected = 5.3425606635;

        /* @Real */final double tolerance = 1e-10;
        if (Math.abs(calculated - expected) > tolerance) {
            reportFailure("value", averageType, runningAccumulator, pastFixings, fixingDates, payoff, exercise, spot.value(),
View Full Code Here


                        fixingDates.add(d.clone());
                    }

                    final PricingEngine engine = new AnalyticDiscreteGeometricAveragePriceAsianEngine(process);

                    final DiscreteAveragingAsianOption option = new DiscreteAveragingAsianOption(
                            AverageType.Geometric, runningAverage, pastFixings, fixingDates, payoff, maturity);
                    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();
                                    final Map<String, Double> calculated = new HashMap<String, Double>();
                                    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());

                                    final Map<String, Double> expected = new HashMap<String, Double>();
                                    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();
                                        expected.put("theta", (value_p - value_m) / dT);
                                        new Settings().setEvaluationDate(today);
                                        // compare
                                        for (final Entry<String, Double> greek : calculated.entrySet()) {
                                            final double expct = expected.get(greek.getKey());
View Full Code Here

        for (/* @Size */int i = 0; i < 91; i++) {
            fixingDates.add(today.clone().addAssign(i));
        }

        final PricingEngine engine2 = new AnalyticDiscreteGeometricAveragePriceAsianEngine(stochProcess);
        final DiscreteAveragingAsianOption option2 = new DiscreteAveragingAsianOption(
                averageType, runningAccumulator, pastFixings, fixingDates, payoff, exercise);
        option2.setPricingEngine(engine2);

        calculated = option2.NPV();
        tolerance = 3.0e-3;
        if (Math.abs(calculated - expected) > tolerance) {
            reportFailure("value", averageType, runningAccumulator, pastFixings, fixingDates, payoff, exercise, spot.value(),
                    qRate.value(), rRate.value(), today, vol.value(), expected, calculated, tolerance);
        }
View Full Code Here

TOP

Related Classes of org.jquantlib.instruments.DiscreteAveragingAsianOption$EngineImpl

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.