示例#1
0
    def value(self, time, instrument, numeraire):
        ttm = self.maturity - time
        forward = instrument * numeraire[-1] / numeraire
        m = tf.math.log(forward / self.strike)
        v = self.volatility * tf.math.sqrt(ttm)

        return norm_cdf(m / v - v / 2.) / numeraire[-1]
示例#2
0
def bachelier_delta(time_to_maturity, spot, strike, volatility):
    """Returns delta in Bachelier's model.
    Args:
        see black_price
    Returns:
        delta: (batch_size, timesteps + 1)
    """
    v = volatility * tf.math.sqrt(time_to_maturity)
    d = (spot - strike) / v

    return utils.norm_cdf(d, approx=True)
示例#3
0
def bachelier_price(time_to_maturity, spot, strike, volatility):
    """Returns price in Bachelier's model.
    Args:
        see black_price
    Returns:
        price: (batch_size, timesteps + 1)
    """
    v = volatility * tf.math.sqrt(time_to_maturity)
    d = (spot - strike) / v
    price = v * (d * utils.norm_cdf(d, approx=True) + utils.norm_pdf(d))

    # due to no interest rate, v=0 implies S_T=S_t a.s.
    return tf.where(tf.equal(v, 0.0), tf.maximum(spot - strike, 0.0), price)
示例#4
0
def black_price(time_to_maturity, spot, strike, drift, volatility, theta):
    """Returns price in Black's model.
    Args:
        time_to_maturity: (timesteps + 1, )
        spot: (batch_size, timesteps + 1)
        strike: float
        rate: float
        volatility: float
        theta: float
    Returns:
        price: (batch_size, timesteps + 1)
    """
    forward = spot * tf.math.exp(drift * time_to_maturity)
    m = tf.math.log(forward / strike)
    v = volatility * tf.math.sqrt(time_to_maturity)
    m_over_v = tf.where(tf.equal(m, 0.0), 0.0, m / v)
    v_over_2 = v / 2.0

    p1 = utils.norm_cdf(theta * (m_over_v + v_over_2), approx=True)
    p2 = utils.norm_cdf(theta * (m_over_v - v_over_2), approx=True)

    return theta * (forward * p1 - strike * p2)
示例#5
0
def black_delta(time_to_maturity, spot, strike, drift, volatility, theta):
    """Returns delta in Black's model.
    Args:
        see black_price
    Returns:
        delta: (batch_size, timesteps + 1)
    """
    inflator = tf.math.exp(drift * time_to_maturity)
    forward = spot * inflator
    m = tf.math.log(forward / strike)
    v = volatility * tf.math.sqrt(time_to_maturity)

    p1 = utils.norm_cdf(theta * (m / v + v / 2.0), approx=True)

    raw_delta = theta * inflator * p1
    payoff_delta = theta * tf.cast(theta * (spot - strike) > 0, FLOAT_DTYPE)
    delta = tf.where(tf.equal(v, 0.0), payoff_delta, raw_delta)

    return delta
示例#6
0
    def value(self, time, instrument, numeraire):
        ttm = self.maturity - time
        vol_time = self.volatility * tf.sqrt(ttm)
        d = (instrument - self.strike) / vol_time

        return utils.norm_cdf(d)