Package org.jquantlib.quotes

Examples of org.jquantlib.quotes.SimpleQuote


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

        QL.info("Today: " + today);

        final SimpleQuote           spot  = new SimpleQuote(80.0);
        final SimpleQuote           qRate = new SimpleQuote(-0.03);
        final YieldTermStructure    qTS   = Utilities.flatRate(today, qRate, dc);
        final SimpleQuote           rRate = new SimpleQuote(0.05);
        final YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
        final SimpleQuote           vol   = new SimpleQuote(0.20);
        final BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

        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 AnalyticContinuousGeometricAveragePriceAsianEngine(stochProcess);

        final AverageType averageType = AverageType.Geometric;
        final Option.Type type = Option.Type.Put;
        /* @Real */final double strike = 85.0;

        final Date exerciseDate = today.clone().addAssign(90);

        /* @Size */int pastFixings = Integer.MAX_VALUE;
        /* @Real */double runningAccumulator = Double.NaN;

        final StrikedTypePayoff payoff = new PlainVanillaPayoff(type, strike);
        final Exercise exercise = new EuropeanExercise(exerciseDate);

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

        /* @Real */double calculated = option.NPV();
        /* @Real */final double expected = 4.6922;
        /* @Real */double tolerance = 1.0e-4;

        if (Math.abs(calculated - expected) > tolerance) {
            reportFailure("value", averageType, runningAccumulator, pastFixings, new ArrayList<Date>(), payoff, exercise, spot
                    .value(), qRate.value(), rRate.value(), today, vol.value(), expected, calculated, tolerance);

        }
        // trying to approximate the continuous version with the discrete version
        runningAccumulator = 1.0;
        pastFixings = 0;

        final List<Date> fixingDates = new ArrayList<Date>(91);

        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


        /* @Integer */final int lengths[] = { 1, 2 };
        /* @Volatility */final double vols[] = { 0.11, 0.50, 1.20 };

        final DayCounter dc = new Actual360();

        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 BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(
                new Handle<Quote>(spot),
                new Handle<YieldTermStructure>(qTS),
                new Handle<YieldTermStructure>(rTS),
                new Handle<BlackVolTermStructure>(volTS));

        final PricingEngine engine = new AnalyticContinuousGeometricAveragePriceAsianEngine(stochProcess);



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

        for (final Type type : types) {
            for (final double strike : strikes) {
                for (final int length : lengths) {

                    final Date exerciseDate = new Date(today.dayOfMonth(), today.month(), today.year() + length);
                    final EuropeanExercise maturity = new EuropeanExercise(exerciseDate);
                    final PlainVanillaPayoff payoff = new PlainVanillaPayoff(type, strike);

                    final ContinuousAveragingAsianOption option = new ContinuousAveragingAsianOption(
                            AverageType.Geometric, payoff, maturity);
                    option.setPricingEngine(engine);

                    /* @Size */final int pastFixings = Integer.MAX_VALUE;
                    /* @Real */final double runningAverage = Double.NaN;

                    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();
                                    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
                                        /* @Real */final double du = u * 1.0e-4;
                                        spot.setValue(u + du);
                                        /* @Real */double value_p = option.NPV();
                                        /* @Real */final double delta_p = option.delta();
                                        spot.setValue(u - du);
                                        /* @Real */double value_m = option.NPV();
                                        /* @Real */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
                                        /* @Spread */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));

                                        /* @Spread */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
                                        /* @Volatility */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

    public void testObservable() {

        QL.info("Testing observability of instruments...");


        final SimpleQuote me1 = new SimpleQuote(0.0);
        final RelinkableHandle<Quote>  h = new RelinkableHandle<Quote>(me1);
        final Instrument s = new Stock(h);

        final Flag f = new Flag();
        s.addObserver(f); //f.registerWith(s);

        s.NPV();
        me1.setValue(3.14);
        if (!f.isUp()) {
            fail("Observer was not notified of instrument change");
        }

        s.NPV();
        f.lower();
        final SimpleQuote me2 = new SimpleQuote(0.0);

        h.linkTo(me2);
        if (!f.isUp()) {
            fail("Observer was not notified of instrument change");
        }

        f.lower();
        s.freeze();
        s.NPV();
        me2.setValue(2.71);
        if (f.isUp()) {
            fail("Observer was notified of frozen instrument change");
        }

        s.NPV();
View Full Code Here

        exercise = exercise.add(new Period(2,TimeUnit.Years));


        final double residualTime = dc.yearFraction(today, exercise);

        final SimpleQuote spot = new SimpleQuote(0.0);
        final YieldTermStructure qTS = Utilities.flatRate(today, q, dc);
        final YieldTermStructure rTS = Utilities.flatRate(today, r, dc);

        final BlackVolTermStructure volTS = Utilities.flatVol(today, sigma, dc);
View Full Code Here

            final /*@Rate*/ double forward,
            final DayCounter dayCounter,
            final Compounding compounding,
            final Frequency frequency) {
        super(referenceDate, new NullCalendar(), dayCounter);
        this.forward = new Handle<SimpleQuote>(new SimpleQuote(forward));
        this.compounding = compounding;
        this.frequency = frequency;
        updateRate();
    }
View Full Code Here

            final /*@Rate*/ double forward,
            final DayCounter dayCounter,
            final Compounding compounding,
            final Frequency frequency) {
        super(settlementDays, calendar, dayCounter);
        this.forward = new Handle<Quote>(new SimpleQuote(forward));
        this.compounding = compounding;
        this.frequency = frequency;
        updateRate();
    }
View Full Code Here

TOP

Related Classes of org.jquantlib.quotes.SimpleQuote

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.