Example #1
0
def baseline_utility(x, alpha):
    """ This function returns the baseline utility.
    """
    # Guard interface.
    assert basic_checks('baseline_utility', 'in', x, alpha)

    # Calculate utility.
    rslt = x ** alpha

    # Check result.
    assert basic_checks('baseline_utility', 'out', rslt)

    # Finishing
    return rslt
Example #2
0
def _wrapper_baseline(alpha, shape, x):
    """ This private function constructs the integrand for the application of
    numerical integration strategies.
    """
    # Guard interface.
    assert basic_checks('_wrapper_baseline', 'in', alpha, shape, x)

    # Evaluate utility and weigh by probability.
    rslt = baseline_utility(x, alpha) * lognorm.pdf(x, shape)

    # Check result.
    assert basic_checks('_wrapper_baseline', 'out', rslt)

    # Finishing
    return rslt
Example #3
0
def get_baseline_lognormal(alpha, shape, technique, int_options):
    """ Get the expected returns by drawing numerous random deviates from a
    lognormal distribution.
    """
    # Guard interface.
    args = (alpha, shape, technique, int_options)
    assert basic_checks('get_baseline_lognormal', 'in', args)

    # Construct bounds based on quantiles of lognormal distribution.
    lower, upper = EPS, lognorm.ppf(0.9999999, shape)

    # Prepare wrapper for alternative integration strategies.
    func = partial(_wrapper_baseline, alpha, shape)
    # Perform native monte carlo integration.
    if technique == 'naive_mc':
        # Distribute relevant integration options.
        implementation = int_options['naive_mc']['implementation']
        num_draws = int_options['naive_mc']['num_draws']
        seed = int_options['naive_mc']['seed']
        # Perform naive Monte Carlo integration.
        rslt = naive_monte_carlo(func, (lower, upper), num_draws,
                                 implementation, seed)
    elif technique == 'quad':
        # Perform integration based on quadrature.
        rslt = scipy_quad(func, (lower, upper))
    elif technique == 'romberg':
        # Perform integration based on Romberg.
        rslt = scipy_romberg(func, (lower, upper))
    else:
        pass

    # Check result.
    assert basic_checks('get_baseline_lognormal', 'out', rslt)

    # Finishing
    return rslt