Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Solutions · 7. Decisions under uncertainty: stochastic dynamic programming for energy storage

School of Engineering, Nazarbayev University

Worked solutions to the three exercises of Lecture 7. Each solution is computed here and checked with assert statements against an exact identity or an independent calculation. The first code cell sets up the notebook and runs Demonstration 1 of the lecture without showing its output, because some of the solutions use its variables.

Exercise 1

Problem. Verify numerically that (a) V0(s)V_0(s) on an evening peak stochastic dispatch horizon is monotonically non-decreasing (ΔV0≥0\Delta V_0 \geq 0) and concave (Δ2V0≤0\Delta^2 V_0 \leq 0) across soc_grid, and (b) on a 2-period pure arbitrage test (P0=40 USD/MWhP_0 = 40\ \mathrm{USD/MWh}, η=0.80  ⟹  P∗=P0/η2=62.5 USD/MWh\eta = 0.80 \implies P^* = P_0 / \eta^2 = 62.5\ \mathrm{USD/MWh}), stochastic_bellman_storage holds (a0∗(0)=0a_0^*(0) = 0) for every P1<62.5P_1 < 62.5 and charges at full rate (a0∗(0)=+25 MWa_0^*(0) = +25\ \mathrm{MW}) for every P1>62.5P_1 > 62.5.


Exercise 1: Monotonicity and concavity of V_0(s) and exact 1/eta^2 arbitrage threshold
======================================================================================
V0(s) monotonicity min(dV) = +178.33 >= 0 | concavity max(d^2V) = +9.095e-13 <= 0
Exact arbitrage threshold P* = P_buy / eta^2 = 62.50 USD/MWh verified across all 36 prices
<Figure size 1012x418 with 2 Axes>

Figure S7.1. Checks of the Bellman solution. (a) Marginal value of stored energy against the state of charge; it decreases, so V0V_0 is concave. (b) Optimal first-period action against the second-period price: the switch from holding to charging occurs at Pbuy/η2=62.5P_{\mathrm{buy}}/\eta^2 = 62.5 USD/MWh (dashed).

Explanation. Each additional MWh of initial charge can only be sold during progressively less lucrative hours once the highest-price peak discharge slots (Rmax⁡R_{\max}) are saturated, making marginal storage value ∂V0/∂s≥0\partial V_0/\partial s \geq 0 monotonically non-increasing (V0V_0 concave). Meanwhile, buying aa MWh at PbuyP_{\mathrm{buy}} yields η2a\eta^2 a MWh sold at PsellP_{\mathrm{sell}}, so net gain a(η2Psell−Pbuy)a(\eta^2 P_{\mathrm{sell}} - P_{\mathrm{buy}}) switches sign sharply at Psell=Pbuy/η2P_{\mathrm{sell}} = P_{\mathrm{buy}} / \eta^2.


Exercise 2

Problem. Verify ValueError guards on stochastic_bellman_storage, then audit (a) how forward myopic greedy dispatch empties a 50 MWh50\ \mathrm{MWh} battery on a 48 USD/MWh48\ \mathrm{USD/MWh} morning bump right before a 240 USD/MWh240\ \mathrm{USD/MWh} evening spike, and (b) how tabular grid DP memory ∣S∣d∣A∣dT|S|^d |A|^d T grows across d=1…6d = 1 \dots 6 coupled reservoirs.


Exercise 2: Failure-mode audit — forward myopic trap and multi-reservoir curse of dimensionality
================================================================================================
Forward Myopic Profit (s0=50 MWh) : $2,160.00 (dumped early at $48/MWh)
Bellman Optimal Profit (s0=50 MWh): $10,800.00 (5.0x higher; held for the $240/MWh peak)
Curse of Dimensionality (d=1 -> d=6): states grow from 21 -> 85,766,121; Q-evaluations/sweep -> 3.65e+15

Explanation. (a) Selling at 48 USD/MWh48\ \mathrm{USD/MWh} has positive immediate cash flow, blinding any zero-lookahead greedy rule to the opportunity cost ∂Vt+1/∂s=0.90×240=216 USD/MWh\partial V_{t+1}/\partial s = 0.90 \times 240 = 216\ \mathrm{USD/MWh} encoded in Bellman’s continuation value. (b) Bellman coined the phrase Curse of Dimensionality precisely because tensor-product grids scale as ∣S∣d|S|^d: at d=6d = 6 coupled reservoirs, one 24-hour backward sweep requires 3.65×10153.65 \times 10^{15} inner Q-evaluations, motivating approximate/dual dynamic programming (SDDP) in high dimensions.


Exercise 3

Problem. Implement simulate_closed_loop_bellman_fleet(prices, bellman_sol, inflow_samples, max_capacity=100.0, efficiency=0.92, terminal_value_per_unit=25.0) to evaluate closed-loop Bellman control across 500 random 24-hour weather trajectories (inflow_samples of shape (500, 24)), verifying convergence to theoretical expected DP profit and strict superiority over fixed price-threshold rules.


Exercise 3: Implement it yourself — Monte Carlo closed-loop Bellman fleet simulator
===================================================================================
Theoretical Bellman V_0(0)    : $15,001.78
Closed-Loop MC Mean (N = 500) : $15,050.66 +/- $29.50
Heuristic Price-Band Mean     : $9,437.59 (Bellman wins on 100.0% of days)
<Figure size 814x440 with 1 Axes>

Figure S7.2. Closed-loop Bellman dispatch over 500 synthetic weather days: median state of charge (line) and the band between the 10th and 90th percentiles.

Summary. The closed-loop Monte Carlo mean over 500 synthetic weather days, 15,051±3015{,}051 \pm 30 USD, agrees with the backward Bellman value 15,00215{,}002 USD to within 1.7 standard errors. The feedback policy adjusts its charging to the realised inflows and beats the fixed price-band rule on every one of the 500 days.