Package org.jquantlib

Examples of org.jquantlib.Settings


    //

    @Override
  //XXX::OBS public void update(final Observable o, final Object arg) {
    public void update() {
        final Date newEvaluationDate = new Settings().evaluationDate();
        if (!evaluationDate.equals(newEvaluationDate)) {
            evaluationDate = newEvaluationDate;
            initializeDates();
        }
        //XXX::OBS super.update(o, arg);
View Full Code Here


                {0.8, 0.84162123357291441},
                {0.9, 1.2815515655446004},
                {0.99, 2.3263478740408412}};


        final Settings settings = new Settings();

        //FIXME: obtain original value :: this is a thread safety problem :(
        final boolean oldHighPrecision = settings.isRefineHighPrecisionUsingHalleysMethod();

        settings.setRefineHighPrecisionUsingHalleysMethod(false);
        InverseCumulativeNormal icn;

        //test the normal values
        icn = new InverseCumulativeNormal();
        for (final double[] normalTestvalue : normal_testvalues) {
            final double x_position = normalTestvalue[0];
            final double tolerance = 1.0e-15;//(Math.abs(x_position)<3.01) ? 1.0e-15: 1.0e-10;

            final double normal_expected = normalTestvalue[1];
            final double computed_normal = icn.op(x_position);
            if (Math.abs(normal_expected-computed_normal)>tolerance) {
                fail("x_position " + x_position + " normal_expected: " + normal_expected + " normal_computed: " + normal_expected);
            }
        }


        //test the normal values using high machine precision Halley's method
        settings.setRefineHighPrecisionUsingHalleysMethod(true);
        icn = new InverseCumulativeNormal();
        for (final double[] precisionTestvalue : precision_testvalues) {
            final double x_position = precisionTestvalue[0];
            final double tolerance = 1.0e-15;//(Math.abs(x_position)<3.01) ? 1.0e-15: 1.0e-10;

            final double precision_expected = precisionTestvalue[1];
            final double computed_precision = icn.op(x_position);

            if (Math.abs(precision_expected-computed_precision)>tolerance) {
                fail("x_position " + x_position + " precision_expected: " + precision_expected + " precision_computed: " + computed_precision);
            }
        }

        //FIXME: back to original value :: this is a thread safety problem :(
        settings.setRefineHighPrecisionUsingHalleysMethod(oldHighPrecision);
    }
View Full Code Here

        // set up dates
        final Calendar calendar = new Target();
        final Date todaysDate = new Date(15, Month.May, 1998);
        final Date settlementDate = new Date(17, Month.May, 1998);
        new Settings().setEvaluationDate(todaysDate);

        // our options
        final Option.Type type = Option.Type.Put;
        final double strike = 40.0;
        final double underlying = 36.0;
View Full Code Here

        /* @Integer */ final int lengths[] = { 1, 2 };
        /* @Volatility */ final double vols[] = { 0.05, 0.20, 0.70 };

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

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

        /* @Real */ final double tolerance = 1.0e-2;
        /* @Real */ final double expected = 3.67;

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

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

        /* @Integer */ final int lengths[] = { 1, 2 };
        /* @Volatility */ final double vols[] = { 0.05, 0.20, 0.70 };

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

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

        /* @Integer */ final int lengths[] = { 1, 2 };
        /* @Volatility */ final double vols[] = { 0.05, 0.20, 0.70 };

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

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

        /* @Integer */ final int lengths[] = { 1, 2 };
        /* @Volatility */ final double vols[] = { 0.05, 0.20, 0.40 };

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

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

        for (final Type type : types)
            for (final double strike : strikes)
                for (final int length : lengths) {
                  final Date exDate = today.add(new Period(length, TimeUnit.Years));
                  final Exercise exercise = new EuropeanExercise(exDate);

                  final List<Date> dividendDates = new ArrayList<Date>();
                  final List</* @Real */ Double> dividends = new ArrayList<Double>();
                  for (final Date d = today.add(new Period(3, TimeUnit.Months));
                             d.lt(exercise.lastDate());
                             d.addAssign(new Period(6, TimeUnit.Months))) {
                      dividendDates.add(d.clone());
                      dividends.add(5.0);
                  }

                  final StrikedTypePayoff payoff = new PlainVanillaPayoff(type, strike);
                  final BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(new Handle<Quote>(spot), qTS, rTS, volTS);
                  final PricingEngine engine = new AnalyticDividendEuropeanEngine(stochProcess);

                  final DividendVanillaOption option = new DividendVanillaOption(payoff, exercise, dividendDates, dividends);
                  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);

                                /* @Real */ 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("vega",  option.vega());

                                if (value > spot.value()*1.0e-5) {
                                    // perturb spot and get delta and gamma
                                    /* @Real */ final double du = u*1.0e-4;
                                    spot.setValue(u+du);
                                    /* @Real */ double value_p = option.NPV();
                                    final double delta_p = option.delta();
                                    spot.setValue(u-du);
                                    /* @Real */ 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 risk-free /* @Rate */ double and get rho
                                    final /* @Spread */ 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) );

                                    // perturb /* @Volatility */ double and get vega
                                    final /* @Spread */ 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 /*@Time*/ double dT = dc.yearFraction(today.sub(1), today.add(1));
                                    new Settings().setEvaluationDate(today.sub(1));
                                    value_m = option.NPV();
                                    new Settings().setEvaluationDate(today.add(1));
                                    value_p = option.NPV();
                                    new Settings().setEvaluationDate(today);
                                    expected.put("theta", (value_p - value_m)/dT );

                                    // compare
                                    for (final Map.Entry<String, Double> it : calculated.entrySet()) {

View Full Code Here

        /* @Integer */ final int lengths[] = { 1, 2 };
        /* @Volatility */ final double vols[] = { 0.05, 0.20, 0.40 };

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

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

    @Test
    public void testFdEuropeanGreeks() {

        QL.info("Testing finite-differences dividend European option greeks...");
        final Date today = Date.todaysDate();
        new Settings().setEvaluationDate(today);

        /* @Integer */ final int lengths[] = { 1, 2 };

        for (final int length : lengths) {
            final Date exDate = today.add(new Period(length, TimeUnit.Years));
View Full Code Here

TOP

Related Classes of org.jquantlib.Settings

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.