Example #1
0
def delta(flag, S, K, t, r, sigma, q):
    """Returns the Black-Scholes-Merton delta of an option.
    

    :param flag: 'c' or 'p' for call or put.
    :type flag: str
    :param S: underlying asset price
    :type S: float
    :param K: strike price
    :type K: float
    :param t: time to expiration in years
    :type t: float
    :param r: annual risk-free interest rate
    :type r: float
    :param sigma: volatility
    :type sigma: float
    :param q: annualized continuous dividend yield
    :type q: float
    
    :returns:  float 

    """

    D1 = d1(S, K, t, r, sigma, q)

    if flag == 'p':
        return -numpy.exp(-q * t) * cnd(-D1)
    else:
        return numpy.exp(-q * t) * cnd(D1)
Example #2
0
def gamma(flag, S, K, t, r, sigma, q):
    """Returns the Black-Scholes-Merton gamma of an option.


    :param flag: 'c' or 'p' for call or put.
    :type flag: str
    :param S: underlying asset price
    :type S: float
    :param K: strike price
    :type K: float
    :param t: time to expiration in years
    :type t: float
    :param r: annual risk-free interest rate
    :type r: float
    :param sigma: volatility
    :type sigma: float
    :param q: annualized continuous dividend yield
    :type q: float

    :returns:  float 

    """

    D1 = d1(S, K, t, r, sigma, q)
    numerator = numpy.exp(-q * t) * pdf(D1)
    denominator = S * sigma * numpy.sqrt(t)

    return numerator / denominator
Example #3
0
def delta(flag, S, K, t, r, sigma, q):
    
    """Returns the Black-Scholes-Merton delta of an option.
    

    :param flag: 'c' or 'p' for call or put.
    :type flag: str
    :param S: underlying asset price
    :type S: float
    :param K: strike price
    :type K: float
    :param t: time to expiration in years
    :type t: float
    :param r: annual risk-free interest rate
    :type r: float
    :param sigma: volatility
    :type sigma: float
    :param q: annualized continuous dividend yield
    :type q: float
    
    :returns:  float 

    """

    D1 = d1(S, K, t, r, sigma, q)

    if flag == 'p':
        return -numpy.exp(-q*t) * cnd(-D1)
    else:
        return numpy.exp(-q*t) * cnd(D1)
Example #4
0
def gamma(flag, S, K, t, r, sigma, q):


    """Returns the Black-Scholes-Merton gamma of an option.


    :param flag: 'c' or 'p' for call or put.
    :type flag: str
    :param S: underlying asset price
    :type S: float
    :param K: strike price
    :type K: float
    :param t: time to expiration in years
    :type t: float
    :param r: annual risk-free interest rate
    :type r: float
    :param sigma: volatility
    :type sigma: float
    :param q: annualized continuous dividend yield
    :type q: float

    :returns:  float 

    """

    D1 = d1(S, K, t, r, sigma, q)
    numerator = numpy.exp(-q*t) * pdf(D1)
    denominator = S * sigma * numpy.sqrt(t)

    return numerator / denominator
Example #5
0
def theta(flag, S, K, t, r, sigma, q):

    """Returns the Black-Scholes-Merton theta of an option.


    :param flag: 'c' or 'p' for call or put.
    :type flag: str
    :param S: underlying asset price
    :type S: float
    :param K: strike price
    :type K: float
    :param t: time to expiration in years
    :type t: float
    :param r: annual risk-free interest rate
    :type r: float
    :param sigma: volatility
    :type sigma: float
    :param q: annualized continuous dividend yield
    :type q: float

    :returns:  float 

    """


    D1 = d1(S, K, t, r, sigma, q)
    D2 = d2(S, K, t, r, sigma, q)

    first_term = (S * numpy.exp(-q*t) * pdf(D1) * sigma) / (2 * numpy.sqrt(t))

    if flag == 'c':

        second_term = -q * S * numpy.exp(-q*t) * cnd(D1)
        third_term = r * K * numpy.exp(-r*t) * cnd(D2)

        return - (first_term + second_term + third_term) / 365.0

    else:

        second_term = -q * S * numpy.exp(-q*t) * cnd(-D1)
        third_term = r * K * numpy.exp(-r*t) * cnd(-D2)

        return (-first_term + second_term + third_term) / 365.0
Example #6
0
def theta(flag, S, K, t, r, sigma, q):
    """Returns the Black-Scholes-Merton theta of an option.


    :param flag: 'c' or 'p' for call or put.
    :type flag: str
    :param S: underlying asset price
    :type S: float
    :param K: strike price
    :type K: float
    :param t: time to expiration in years
    :type t: float
    :param r: annual risk-free interest rate
    :type r: float
    :param sigma: volatility
    :type sigma: float
    :param q: annualized continuous dividend yield
    :type q: float

    :returns:  float 

    """

    D1 = d1(S, K, t, r, sigma, q)
    D2 = d2(S, K, t, r, sigma, q)

    first_term = (S * numpy.exp(-q * t) * pdf(D1) * sigma) / (2 *
                                                              numpy.sqrt(t))

    if flag == 'c':

        second_term = -q * S * numpy.exp(-q * t) * cnd(D1)
        third_term = r * K * numpy.exp(-r * t) * cnd(D2)

        return -(first_term + second_term + third_term) / 365.0

    else:

        second_term = -q * S * numpy.exp(-q * t) * cnd(-D1)
        third_term = r * K * numpy.exp(-r * t) * cnd(-D2)

        return (-first_term + second_term + third_term) / 365.0