def theta(flag, S, K, t, r, sigma, b, pricing_function):
    """Calculate option theta using numerical integration.

    :param S: underlying asset price
    :type S: float
    :param K: strike price
    :type K: float
    :param sigma: annualized standard deviation, or volatility
    :type sigma: float
    :param t: time to expiration in years
    :type t: float
    :param r: risk-free interest rate
    :type r: float
    :param b: see above
    :type b: float
    :param flag: 'c' or 'p' for call or put.
    :type flag: str
    :param pricing_function: any function returning the price of an option
    :type pricing_function: python function object
    """
    if t <= 1.0 / 365.0:
        return pricing_function(flag, S, K, 1e-05, r, sigma, b
            ) - pricing_function(flag, S, K, t, r, sigma, b)
    else:
        return pricing_function(flag, S, K, t - 1.0 / 365.0, r, sigma, b
            ) - pricing_function(flag, S, K, t, r, sigma, b)
