示例#1
0
def black_scholes(spot_value,
                  strike_value,
                  vol_value,
                  time_value,
                  is_call_bool,
                  rate=0.):
    """
    Black Scholes option pricing formula on log-normal spot value

    :param forward_value: forward price of underlying at exercise date
    :type forward_value: real
    :param strike_value: strike of the option
    :type strike_value: real
    :param vol_value: volatility of underlying price
    :type vol_value: non-negative real
    :param time_value: year fraction until exercise date
    :type time_value: non-negative real
    :param is_call_bool: call -> True, put -> False
    :type is_call_bool: boolean
    :param rate: risk free rate
    :type rate: real
    :return: option price
    :rtype: real
    :return:

    """
    if not vol_value >= 0:
        raise AssertionError("Negative vol in %s" % __name__)
    sigma = vol_value * math.sqrt(time_value)

    if sigma == 0:
        # non-random option value, e.g. on exercise date
        return option_payoff(spot_value, strike_value, is_call_bool)

    d1 = (math.log(spot_value / strike_value) + rate * time_value +
          0.5 * sigma**2) / sigma
    d2 = d1 - sigma

    if is_call_bool:
        return spot_value * normal_cdf(d1) - strike_value * math.exp(
            -rate * time_value) * normal_cdf(d2)
    else:
        return strike_value * math.exp(-rate * time_value) * normal_cdf(
            -d2) - spot_value * normal_cdf(-d1)
示例#2
0
def hw_discount_bond_option(forward_value, strike_value, implied_vol_value, time_value, is_call_bool,
                            time_to_bond_value, mean_reversion_value, maturity_discount_value):
    """
    discount bond option pricing formula in the Hull White  framework

    :param float forward_value: forward price of underlying (discount bond) at bond maturity (D(t,Tau,r))
    :param float strike_value: strike price
    :param float implied_vol_value: volatility of the spot rate
    :param float time_value: year fraction until exercise date (option maturity date)
    :param float bool is_call_bool: call -> True, put -> False
    :param float time_to_bond_value: year fraction between option's maturity and bond's maturity
    :param float maturity_discount_value: forward price of underlying (discount bond) at option maturity date (D(t,T,r))
    :param float mean_reversion_value: mean reversion / alpha
    :return: float

    discount bond option pricing formula in the Hull White framework
    as described in A. Pelsser, *Efficient Methods for Valuing Interest Rate Derivatives*, 2000, pp. 50

    """
    if time_value == 0:
        return 0.0
    else:
        strike = maturity_discount_value * strike_value
        A = forward_value / strike
        B = (1 - math.exp(-mean_reversion_value * (time_to_bond_value))) / mean_reversion_value
        var = ((implied_vol_value ** 2) / (2 * mean_reversion_value)) * \
              (1 - math.exp(-2 * mean_reversion_value * time_value))
        sigma = B * math.sqrt(var)
        h = (math.log(A) / sigma) + 0.5 * sigma
        if is_call_bool:
            # call
            option_bond_price = forward_value * normal_cdf(h) - strike * normal_cdf(h - sigma)
        else:
            # put
            option_bond_price = strike * normal_cdf(-h + sigma) - forward_value * normal_cdf(-h)
        return option_bond_price