Logo Search packages:      
Sourcecode: quantlib version File versions  Download package

Real QuantLib::blackFormula ( Option::Type  optionType,
Real  strike,
Real  forward,
Real  stdDev,
Real  discount = 1.0,
Real  displacement = 0.0 
)

Black 1976 formula

Warning:
instead of volatility it uses standard deviation, i.e. volatility*sqrt(timeToMaturity)

Definition at line 45 of file blackformula.cpp.

References QL_ENSURE, and QL_REQUIRE.

Referenced by blackFormula(), QuantLib::UnitDisplacedBlackYoYInflationCouponPricer::optionletPriceImp(), and QuantLib::BlackYoYInflationCouponPricer::optionletPriceImp().

    {
        checkParameters(strike, forward, displacement);
        QL_REQUIRE(stdDev>=0.0,
                   "stdDev (" << stdDev << ") must be non-negative");
        QL_REQUIRE(discount>0.0,
                   "discount (" << discount << ") must be positive");

        if (stdDev==0.0)
            return std::max((forward-strike)*optionType, Real(0.0))*discount;

        forward = forward + displacement;
        strike = strike + displacement;

        // since displacement is non-negative strike==0 iff displacement==0
        // so returning forward*discount is OK
        if (strike==0.0)
            return (optionType==Option::Call ? forward*discount : 0.0);

        Real d1 = std::log(forward/strike)/stdDev + 0.5*stdDev;
        Real d2 = d1 - stdDev;
        CumulativeNormalDistribution phi;
        Real nd1 = phi(optionType*d1);
        Real nd2 = phi(optionType*d2);
        Real result = discount * optionType * (forward*nd1 - strike*nd2);
        QL_ENSURE(result>=0.0,
                  "negative value (" << result << ") for " <<
                  stdDev << " stdDev, " <<
                  optionType << " option, " <<
                  strike << " strike , " <<
                  forward << " forward");
        return result;
    }


Generated by  Doxygen 1.6.0   Back to index