Пример #1
0
def transition(s, x, i, j, in_, e):
    if j:
        return np.full_like(s, gamma * smax)
    else:
        return s + gamma * (smax - s)


model = DPmodel(basis,
                reward,
                transition,
                discount=delta,
                j=['keep', 'clear cut'])

model.solve()
resid, sr, vr = model.residuals()

# Plot Action-Contingent Value Functions

demo.figure('Action-Contingent Value Functions', 'Biomass', 'Value of Stand')
plt.plot(sr, vr.T)
plt.legend(model.labels.j, loc='upper center')

# Compute and Plot Optimal Harvesting Stock Level
scrit = np.interp(0.0, vr[1] - vr[0], sr)
vcrit = np.interp(scrit, sr, vr[0])
demo.annotate(scrit,
              vcrit,
              '$s^* = {:.2f}$'.format(scrit),
              'wo', (-5, 5),
              fs=12)
Пример #2
0
model = DPmodel(basis,
                reward,
                transition,
                bounds,
                x=['extracted'],
                discount=delta)

# Check Model Derivatives
# dpcheck(model,smax,0)

## SOLUTION

# Solve Bellman Equation
model.solve()
resid, s, v, q = model.residuals()

# Compute and print abandonment point
sstar = (b[0] - a[0]) / b[1]
print('Abandonment Point = %5.2f' % sstar)

# Plot Optimal Policy
demo.figure('Optimal Extraction', 'Ore Stock', 'Ore Extracted')
plt.plot(s, q.T)

# Plot Value Function
demo.figure('Value Function', 'Ore Stock', 'Value')
plt.plot(s, v.T)

# Plot Shadow Price Function
demo.figure('Shadow Price Function', 'Ore Stock', 'Shadow Price')
Пример #3
0
model = DPmodel(basis, reward, transition, bounds,
                i=['Low price', 'Average price', 'High Price'],
                x=['Current production'],
                discount=delta, q=q)


# Check Model Derivatives
# dpcheck(model,sstar,sstar)


## SOLUTION

# Solve Bellman Equation
model.solve()
resid, s, v, x = model.residuals()

"""





# Plot Optimal Policy
figure
plot(s,x)
legend('Low Price','Average Price','High Price')
legend('Location','Best')
legend('boxoff')
title('Optimal Production Policy')
xlabel('Lagged Production')
Пример #4
0
                 e=e,
                 w=w)

# Deterministic Steady-State
kstar = ((1 - delta * gamma) / (delta * beta))**(
    1 / (beta - 1))  # determistic steady-state capital investment
sstar = gamma * kstar + kstar**beta  # deterministic steady-state wealth

# Check Model Derivatives
# dpcheck(model,sstar,kstar)

## SOLUTION

# Solve Bellman Equation
growth.solve()
resid, s, v, k = growth.residuals()

# Plot Optimal Policy
demo.figure('Optimal Investment Policy', 'Wealth', 'Investment')
plt.plot(s, k.T)

# Plot Value Function
demo.figure('Value Function', 'Wealth', 'Value')
plt.plot(s, v.T)

# Plot Shadow Price Function
demo.figure('Shadow Price Function', 'Wealth', 'Shadow Price')
plt.plot(s, growth.Value(s, order=1).T)

# Plot Residual
demo.figure('Bellman Equation Residual', 'Wealth', 'Residual')