Package org.jquantlib.math.distributions

Examples of org.jquantlib.math.distributions.CumulativeNormalDistribution


        greeks.delta = futureWeight*black.delta(forwardPrice)*forwardPrice/s;
        greeks.gamma = forwardPrice*futureWeight/(s*s)*(black.gamma(forwardPrice)*futureWeight*forwardPrice
                - pastWeight*black.delta(forwardPrice) );

        /*@Real*/ double Nx_1, nx_1;
        final CumulativeNormalDistribution CND = new CumulativeNormalDistribution();
        final NormalDistribution ND = new NormalDistribution();

        if (sigG > Constants.QL_EPSILON) {
            /*@Real*/ final double x_1  = (muG-Math.log(payoff.strike())+variance)/sigG;
            Nx_1 = CND.op(x_1);
            nx_1 = ND.op(x_1);
        } else {
            Nx_1 = (muG > Math.log(payoff.strike()) ? 1.0 : 0.0);
            nx_1 = 0.0;
        }
View Full Code Here


            moreGreeks.thetaPerDay        = black.thetaPerDay(spot, t);
            moreGreeks.strikeSensitivity  = black.strikeSensitivity();
            moreGreeks.itmCashProbability = black.itmCashProbability();
        } else {
            // early exercise can be optimal
            final CumulativeNormalDistribution cumNormalDist = new CumulativeNormalDistribution();
            final double /*@Real*/ tolerance = 1e-6;
            final double /*@Real*/ Sk = criticalPrice(payoff, riskFreeDiscount, dividendDiscount, variance, tolerance);
            final double /*@Real*/ forwardSk = Sk * dividendDiscount / riskFreeDiscount;
            final double /*@Real*/ d1 = (Math.log(forwardSk/payoff.strike()) + 0.5*variance)/Math.sqrt(variance);
            final double /*@Real*/ n = 2.0*Math.log(dividendDiscount/riskFreeDiscount)/variance;
            final double /*@Real*/ K = -2.0*Math.log(riskFreeDiscount)/(variance*(1.0-riskFreeDiscount));
            double /*@Real*/ Q, a;
            switch (payoff.optionType()) {
            case Call:
                Q = (-(n-1.0) + Math.sqrt(((n-1.0)*(n-1.0))+4.0*K))/2.0;
                a =  (Sk/Q) * (1.0 - dividendDiscount * cumNormalDist.op(d1));
                if (spot<Sk)
                    r.value = black.value() + a * Math.pow((spot/Sk), Q);
                else
                    r.value = spot - payoff.strike();
                break;
            case Put:
                Q = (-(n-1.0) - Math.sqrt(((n-1.0)*(n-1.0))+4.0*K))/2.0;
                a = -(Sk/Q) * (1.0 - dividendDiscount * cumNormalDist.op(-d1));
                if (spot>Sk)
                    r.value = black.value() + a * Math.pow((spot/Sk), Q);
                else
                    r.value = payoff.strike() - spot;
                break;
View Full Code Here

        // Newton Raphson algorithm for finding critical price Si
        double /*@Real*/ Q, LHS, RHS, bi;
        double /*@Real*/ forwardSi = Si * dividendDiscount / riskFreeDiscount;
        double /*@Real*/ d1 = (Math.log(forwardSi/payoff.strike()) + 0.5*variance) / Math.sqrt(variance);
        final CumulativeNormalDistribution cumNormalDist = new CumulativeNormalDistribution();
        final double /*@Real*/ K = (riskFreeDiscount!=1.0 ? -2.0*Math.log(riskFreeDiscount)/ (variance*(1.0-riskFreeDiscount)) : 0.0);
        final double /*@Real*/ temp = BlackFormula.blackFormula(payoff.optionType(), payoff.strike(), forwardSi, Math.sqrt(variance))*riskFreeDiscount;
        switch (payoff.optionType()) {
        case Call:
            Q = (-(n-1.0) + Math.sqrt(((n-1.0)*(n-1.0)) + 4 * K)) / 2;
            LHS = Si - payoff.strike();
            RHS = temp + (1 - dividendDiscount * cumNormalDist.op(d1)) * Si / Q;
            bi =  dividendDiscount * cumNormalDist.op(d1) * (1 - 1/Q)
            + (1 - dividendDiscount * cumNormalDist.derivative(d1) / Math.sqrt(variance)) / Q;
            while (Math.abs(LHS - RHS)/payoff.strike() > tolerance) {
                Si = (payoff.strike() + RHS - bi * Si) / (1 - bi);
                forwardSi = Si * dividendDiscount / riskFreeDiscount;
                d1 = (Math.log(forwardSi/payoff.strike())+0.5*variance)/Math.sqrt(variance);
                LHS = Si - payoff.strike();
                final double /*@Real*/ temp2 = BlackFormula.blackFormula(payoff.optionType(), payoff.strike(), forwardSi, Math.sqrt(variance))*riskFreeDiscount;
                RHS = temp2 + (1 - dividendDiscount * cumNormalDist.op(d1)) * Si / Q;
                bi = dividendDiscount * cumNormalDist.op(d1) * (1 - 1 / Q)
                + (1 - dividendDiscount * cumNormalDist.derivative(d1) / Math.sqrt(variance)) / Q;
            }
            break;
        case Put:
            Q = (-(n-1.0) - Math.sqrt(((n-1.0)*(n-1.0)) + 4 * K)) / 2;
            LHS = payoff.strike() - Si;
            RHS = temp - (1 - dividendDiscount * cumNormalDist.op(-d1)) * Si / Q;
            bi = -dividendDiscount * cumNormalDist.op(-d1) * (1 - 1/Q)
            - (1 + dividendDiscount * cumNormalDist.derivative(-d1) / Math.sqrt(variance)) / Q;
            while (Math.abs(LHS - RHS)/payoff.strike() > tolerance) {
                Si = (payoff.strike() - RHS + bi * Si) / (1 + bi);
                forwardSi = Si * dividendDiscount / riskFreeDiscount;
                d1 = (Math.log(forwardSi/payoff.strike())+0.5*variance)/Math.sqrt(variance);
                LHS = payoff.strike() - Si;
                final double /*@Real*/ temp2 = BlackFormula.blackFormula(payoff.optionType(), payoff.strike(), forwardSi, Math.sqrt(variance))*riskFreeDiscount;
                RHS = temp2 - (1 - dividendDiscount * cumNormalDist.op(-d1)) * Si / Q;
                bi = -dividendDiscount * cumNormalDist.op(-d1) * (1 - 1 / Q)
                - (1 + dividendDiscount * cumNormalDist.derivative(-d1) / Math.sqrt(variance)) / Q;
            }
            break;
        default:
            throw new LibraryException(UNKNOWN_OPTION_TYPE); // QA:[RG]::verified
        }
View Full Code Here

         return bs.op(k);

     }

      public static  double evaluateCumulativeNormalDistribution(double mean, double sigma, double z){
          CumulativeNormalDistribution cnd = new CumulativeNormalDistribution(mean, sigma);
      return     cnd.op(z);
      }
View Full Code Here

    //
    // public constructors
    //

    public AnalyticBarrierEngine(final GeneralizedBlackScholesProcess process) {
        this.f = new CumulativeNormalDistribution();
        this.a = (BarrierOption.ArgumentsImpl)arguments_;
        this.r = (BarrierOption.ResultsImpl)results_;
        this.process = process;
        this.process.addObserver(this);
    }
View Full Code Here

        QL.info("Testing differential operators...");

        final double average = 0.0, sigma = 1.0;

        final NormalDistribution normal = new NormalDistribution(average,sigma);
        final CumulativeNormalDistribution cum = new CumulativeNormalDistribution(average,sigma);

        final double xMin = average - 4*sigma,
        xMax = average + 4*sigma;
        final int N = 10001;
        final double h = (xMax-xMin)/(N-1);

        final Array x = new Array(N), y = new Array(N), yi = new Array(N), yd = new Array(N);
        Array temp = new Array(N);
        final Array diff = new Array(N);

        int i;
        for(i=0; i < x.size(); i++) {
            x.set(i, xMin+h*i);
        }

        for(i = 0; i < x.size(); i++) {
            y.set(i, normal.op(x.get(i)));
        }

        for(i = 0; i < x.size(); i++) {
            yi.set(i, cum.op(x.get(i)));
        }

        for (i=0; i < x.size(); i++) {
            yd.set(i, normal.derivative(x.get(i)));
        }
View Full Code Here

   */
  public /*@Real*/ double gaussianRegret(/*@Real*/ double target) /* @ReadOnly */ {
        /*@Real*/ double m = this.mean();
        /*@Real*/ double std = this.standardDeviation();
        /*@Real*/ double variance = std*std;
        final CumulativeNormalDistribution gIntegral = new CumulativeNormalDistribution(m, std);
        final NormalDistribution g = new NormalDistribution(m, std);
        /*@Real*/ double firstTerm = variance + m*m - 2.0*target*m + target*target;
        /*@Real*/ double alfa = gIntegral.op(target);
        /*@Real*/ double secondTerm = m - target;
        /*@Real*/ double beta = variance*g.op(target);
        /*@Real*/ double result = alfa*firstTerm - beta*secondTerm;
        return result/alfa;
    }
View Full Code Here

    /**
     * gaussian-assumption Shortfall (observations below target)       
     */
    public /*@Real*/ double gaussianShortfall(/*@Real*/ double target) /* @ReadOnly */ {
        final CumulativeNormalDistribution gIntegral = new CumulativeNormalDistribution(mean(), standardDeviation());
        return gIntegral.op(target);
    }
View Full Code Here

     * gaussian-assumption {@link Average} Shortfall (averaged shortfallness)       
     */
    public /*@Real*/ double gaussianAverageShortfall(/*@Real*/ double target) /* @ReadOnly */ {
      /*@Real*/ double m = mean();
      /*@Real*/ double std = standardDeviation();
        final CumulativeNormalDistribution gIntegral = new CumulativeNormalDistribution(m, std);
        final NormalDistribution g = new NormalDistribution(m, std);
        return ( (target-m) + std*std*g.op(target)/gIntegral.op(target) );
    }
View Full Code Here

TOP

Related Classes of org.jquantlib.math.distributions.CumulativeNormalDistribution

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.