Demo entry 6349817



Submitted by anonymous on Feb 27, 2017 at 15:34
Language: Python. Code size: 2.2 kB.

def run_analysis(utility_parameters, asset_parameters, ndarws):
    """Given an initial set of utility parameters and asset parameters, calculate the 
    optimal consumption-wealth ratio and the optimal shares of risk-free assets for 
    each grid point - for gamma and rho respectively.


    # Define a grid over which to loop.
    param_gamma_grid = np.linspace(utility_parameters["gamma_grid"]["start"], utility_parameters[
                                   "gamma_grid"]["stop"], utility_parameters["gamma_grid"]["n_points"])
    param_rho_grid = np.linspace(utility_parameters["gamma_grid"]["start"], utility_parameters[
                                 "rho_grid"]["stop"], utility_parameters["rho_grid"]["n_points"])

    # Store the values for plotting in a nested dictionary.
    plot_data = {
        'gamma': {
            'alpha': np.zeros(utility_parameters["gamma_grid"]["n_points"]),
            'theta': np.zeros(utility_parameters["gamma_grid"]["n_points"]),
            'grid': param_gamma_grid
        'rho': {
            'alpha': np.zeros(utility_parameters["rho_grid"]["n_points"]),
            'theta': np.zeros(utility_parameters["rho_grid"]["n_points"]),
            'grid': param_rho_grid

    # Calculate the optimal policy rules.
    for par in sorted(plot_data):  # plot-data is dictionary for
        # Use a copy of the original data to ensure c.p. analysis.
        preferences_grid = utility_parameters.copy()
        # adds a number to every grid point, count indicates the point we are at
        # i.e. how many loops we did so far
        for count, point in enumerate(plot_data[par]['grid']):
            # Save the value of the grid point. (save the parameter values used to
            # calculate a and theta for each grid point)
            preferences_grid[par] = point
            # Calculate the optimal parameters.
            plot_data[par]['alpha'][count], theta = c_pf_opt(
                utility_parameters, asset_parameters, ndraws)
            plot_data[par]['theta'][count] = theta[

    return plot_data

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).