Examples of CumulativeNormalDistribution


Examples of org.jquantlib.math.distributions.CumulativeNormalDistribution

                mu = Math.log(dividendDiscount / discount) / variance - 0.5;
                lambda = Math.sqrt( mu * mu - 2.0 * Math.log(discount) / variance);
            }
            D1 = log_H_S / stdDev + lambda * stdDev;
            D2 = D1 - 2.0 * lambda * stdDev;
            final CumulativeNormalDistribution f = new CumulativeNormalDistribution();
            cum_d1 = f.op(D1);
            cum_d2 = f.op(D2);
            n_d1 = f.derivative(D1);
            n_d2 = f.derivative(D2);
        } else {
            // TODO: not tested yet
            mu = Math.log(dividendDiscount / discount) / variance - 0.5;
            lambda = Math.sqrt( mu * mu - 2.0 * Math.log(discount) / variance);
            if (log_H_S > 0) {
View Full Code Here

Examples of org.jquantlib.math.distributions.CumulativeNormalDistribution

        @Real final double d1 = Math.log(forward / strike) / stddev + 0.5 * stddev;
        @Real final double d2 = d1 - stddev;

        // TODO: code review
        final CumulativeNormalDistribution phi = new CumulativeNormalDistribution();
        @Real final double result = discount * optionType.toInteger()
        * (forward * phi.op(optionType.toInteger() * d1) - strike * phi.op(optionType.toInteger() * d2));

        if (result >= 0.0) return result;
        throw new ArithmeticException("a negative value was calculated"); // TODO: message
    }
View Full Code Here

Examples of org.jquantlib.math.distributions.CumulativeNormalDistribution

        if (strike==0.0) return (optionType==Option.Type.Call ? 1.0 : 0.0);
        final double d1 = Math.log((forward+displacement)/(strike+displacement))/stddev + 0.5*stddev;
        final double d2 = d1 - stddev;

        // TODO: code review
        final CumulativeNormalDistribution phi = new CumulativeNormalDistribution();
        return phi.op(optionType.toInteger() * d2);
    }
View Full Code Here

Examples of org.jquantlib.math.distributions.CumulativeNormalDistribution

        forward = forward + displacement;
        strike = strike + displacement;
        final double d1 = Math.log(forward/strike)/stddev + .5*stddev;

        // TODO: code review
        final CumulativeNormalDistribution cdf = new CumulativeNormalDistribution();
        return discount * forward * cdf.derivative(d1);
    }
View Full Code Here

Examples of org.jquantlib.math.distributions.CumulativeNormalDistribution

        final double d = (forward - strike) * optionType.ordinal(), h = d / stddev;
        if (stddev == 0.0) return discount * Math.max(d, 0.0);

        // TODO: code review
        final CumulativeNormalDistribution phi = new CumulativeNormalDistribution();
        @NonNegative
        final double result = discount * stddev * phi.derivative(h) + d * phi.op(h);
        if (result >= 0.0) return result;
        throw new ArithmeticException("negative value");
    }
View Full Code Here

Examples of org.jquantlib.math.distributions.CumulativeNormalDistribution

            this.signedForward_ = (optionType.toInteger() * (forward + displacement));
            this.undiscountedBlackPrice_ = (undiscountedBlackPrice);
            signedMoneyness_ = optionType.toInteger() * Math.log((forward + displacement) / (strike + displacement));

            // TODO: code review
            this.N_ = new CumulativeNormalDistribution();
        }
View Full Code Here

Examples of org.jquantlib.math.distributions.CumulativeNormalDistribution

        log_H_S = Math.log(strike / spot);

        if (variance >= Math.E) {
            D1 = log_H_S / stdDev + mu * stdDev;
            D2 = D1 - 2.0 * mu * stdDev;
            final CumulativeNormalDistribution f = new CumulativeNormalDistribution();
            cum_d1 = f.op(D1);
            cum_d2 = f.op(D2);
            n_d1 = f.derivative(D1);
            n_d2 = f.derivative(D2);
        } else {
            if (log_H_S > 0) {
                cum_d1 = 1.0;
                cum_d2 = 1.0;
            }
View Full Code Here

Examples of org.jquantlib.math.distributions.CumulativeNormalDistribution

                - dividendYield_.currentLink().forwardRate(t0, t0, Compounding.Continuous).rate() - 0.5 * vol * vol;

                df = 4 * thetav_ * kappav_ / (sigmav_ * sigmav_);
                ncp = 4 * kappav_ * Math.exp(-kappav_ * dt) / (sigmav_ * sigmav_ * (1 - Math.exp(-kappav_ * dt))) * x01;

                p = new CumulativeNormalDistribution().op(dw1);
                if (p < 0.0) {
                    p = 0.0;
                } else if (p >= 1.0) {
                    p = 1.0 - Constants.QL_EPSILON;
                }
View Full Code Here

Examples of org.jquantlib.math.distributions.CumulativeNormalDistribution

                cum_d1 = 1.0;
                cum_d2 = 1.0;
            } else {
                D1 = Math.log(forward / strike) / stdDev + 0.5 * stdDev;
                D2 = D1 - stdDev;
                final CumulativeNormalDistribution f = new CumulativeNormalDistribution();
                cum_d1 = f.op(D1);
                cum_d2 = f.op(D2);
                n_d1 = f.derivative(D1);
                n_d2 = f.derivative(D2);
            }
        } else {
            if (forward > strike) {
                cum_d1 = 1.0;
                cum_d2 = 1.0;
View Full Code Here

Examples of org.jquantlib.math.distributions.CumulativeNormalDistribution

            moreGreeks.strikeSensitivity  = black.strikeSensitivity();
            moreGreeks.itmCashProbability = black.itmCashProbability();
        } else {
            // early exercise can be optimal
            final CumulativeNormalDistribution cumNormalDist = new CumulativeNormalDistribution();
            final NormalDistribution normalDist = new NormalDistribution();

            final double /*@Real*/ tolerance = 1e-6;
            final double /*@Real*/ Sk = BaroneAdesiWhaleyApproximationEngine.criticalPrice(payoff, riskFreeDiscount, dividendDiscount, variance, tolerance);

            final double /*@Real*/ forwardSk = Sk * dividendDiscount / riskFreeDiscount;

            final double /*@Real*/ alpha = -2.0*Math.log(riskFreeDiscount)/(variance);
            final double /*@Real*/ beta = 2.0*Math.log(dividendDiscount/riskFreeDiscount)/
            (variance);
            final double /*@Real*/ h = 1 - riskFreeDiscount;
            double /*@Real*/ phi;

            switch (payoff.optionType()) {
            case Call:
                phi = 1;
                break;
            case Put:
                phi = -1;
                break;
            default:
                throw new LibraryException(UNKNOWN_OPTION_TYPE); // QA:[RG]::verified
            }

            // TODO: study how zero interest rate could be handled
            QL.ensure(h != 0.0 , DIVIDING_BY_ZERO_INTEREST_RATE); // QA:[RG]::verified

            final double /* @Real */temp_root = Math.sqrt((beta - 1) * (beta - 1) + (4 * alpha) / h);
            final double /* @Real */lambda = (-(beta - 1) + phi * temp_root) / 2;
            final double /* @Real */lambda_prime = -phi * alpha / (h * h * temp_root);

            final double /* @Real */black_Sk = BlackFormula.blackFormula(payoff.optionType(), payoff.strike(), forwardSk, Math.sqrt(variance)) * riskFreeDiscount;
            final double /* @Real */hA = phi * (Sk - payoff.strike()) - black_Sk;

            final double /* @Real */d1_Sk = (Math.log(forwardSk / payoff.strike()) + 0.5 * variance) / Math.sqrt(variance);
            final double /* @Real */d2_Sk = d1_Sk - Math.sqrt(variance);
            final double /* @Real */part1 = forwardSk * normalDist.op(d1_Sk) / (alpha * Math.sqrt(variance));
            final double /* @Real */part2 = -phi * forwardSk * cumNormalDist.op(phi * d1_Sk) * Math.log(dividendDiscount) / Math.log(riskFreeDiscount);
            final double /* @Real */part3 = +phi * payoff.strike() * cumNormalDist.op(phi * d2_Sk);
            final double /* @Real */V_E_h = part1 + part2 + part3;

            final double /* @Real */b = (1 - h) * alpha * lambda_prime / (2 * (2 * lambda + beta - 1));
            final double /* @Real */c = -((1 - h) * alpha / (2 * lambda + beta - 1)) * (V_E_h / (hA) + 1 / h + lambda_prime / (2 * lambda + beta - 1));
            final double /* @Real */temp_spot_ratio = Math.log(spot / Sk);
            final double /* @Real */chi = temp_spot_ratio * (b * temp_spot_ratio + c);

            if (phi * (Sk - spot) > 0) {
                r.value = black.value() + hA * Math.pow((spot / Sk), lambda) / (1 - chi);
            } else {
                r.value = phi * (spot - payoff.strike());
            }

            final double /* @Real */temp_chi_prime = (2 * b / spot) * Math.log(spot / Sk);
            final double /* @Real */chi_prime = temp_chi_prime + c / spot;
            final double /* @Real */chi_double_prime = 2 * b / (spot * spot) - temp_chi_prime / spot - c / (spot * spot);
            greeks.delta = phi * dividendDiscount * cumNormalDist.op(phi * d1_Sk)
            + (lambda / (spot * (1 - chi)) + chi_prime / ((1 - chi)*(1 - chi))) *
            (phi * (Sk - payoff.strike()) - black_Sk) * Math.pow((spot/Sk), lambda);

            greeks.gamma = phi * dividendDiscount * normalDist.op(phi*d1_Sk) /
            (spot * Math.sqrt(variance))
 
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.