Market Timing & Sales
STOCHASTIC DYNAMIC PROGRAMMING
Agriculture · Distribution · TacticalAfter harvest, the 1,200 ha Châteauguay-valley grain-oilseed farm has several thousand tonnes of dry corn sitting in on-farm silos. Chicago Board of Trade corn futures drift up and down from week to week; every week stored costs a few dollars a tonne in shrink, aeration, and capital. “Sell now or hold another week?” is an archetypal optimal-stopping problem solvable by backward induction on a finite state-action Markov Decision Process — the Stochastic Dynamic Programming toolbox that underlies modern commodity marketing advice.
Why this decision matters
Three verified facts on Canadian grain marketing
Where this decision fits
Agriculture sector decision chain · tactical, post-harvest horizon
Problem & formulation
Optimal stopping MDP with discrete price-state Markov chain
Sets & indices
| Symbol | Meaning | Domain |
|---|---|---|
| \(t \in \{0, 1, \ldots, T\}\) | Week index; \(t = 0\) is the decision being made now, \(t = T\) is the end of the marketing window | finite |
| \(s \in S\) | Discrete market-price state (5–11 buckets around the long-run mean) | \(|S|\) buckets |
Parameters
| Symbol | Meaning | Unit |
|---|---|---|
| \(p_s\) | Local cash price at state \(s\) (CBOT futures + local basis) | CAD / t |
| \(P_{s,s'}\) | One-step price transition probability \(\Pr(s_{t+1} = s' \mid s_t = s)\) | probability |
| \(c\) | Storage cost per tonne per week (interest + shrink + aeration) | CAD / t / wk |
| \(\gamma\) | Per-week discount factor (\(\gamma = 1/(1+r)\)) | \(0 < \gamma \leq 1\) |
| \(p_F\) | Forced-sale price at terminal week \(T\) (market still clears) | CAD / t |
Decision variables & value function
| Symbol | Meaning | Domain |
|---|---|---|
| \(a_t(s)\) | Action in state \(s\) at week \(t\): sell all remaining inventory, or hold | \(\{\text{sell}, \text{hold}\}\) |
| \(V_t(s)\) | Expected discounted net revenue per tonne from week \(t\) onward, starting in state \(s\) | CAD / t |
Bellman equation
Backward induction: terminal value is the forced-sale price minus any final storage cost; in every earlier week, value equals the maximum of selling now or holding for one week of stochastic price evolution:
Optimal action: \(a^*_t(s) = \text{sell}\) when the first argument is larger, else \(\text{hold}\). The problem is solvable in \(\mathcal{O}(T \cdot |S|^2)\) operations by filling the value table from \(t = T\) backward.
Why this formulation works
“When to sell” is an optimal-stopping problem (McCall 1970): the state is the current observable price, the action space is binary, and the optimal policy has a monotone-threshold structure — for each week, there is a reservation price above which selling is optimal. The Markov-chain assumption discretizes that structure so it can be computed exactly without continuous stochastic calculus. The dual view (via Snell envelope) also makes hedging extensions natural.
Real-world → OR mapping
Grain-marketing vocabulary translated to the MDP
| In the grain office | In the MDP model |
|---|---|
| Calendar week after harvest | \(t\) |
| Today's local cash price (futures + basis) | \(s\) |
| Historical volatility & trend → transition matrix | \(P_{s,s'}\) |
| Monthly storage fee / interest / shrinkage | \(c\) |
| Opportunity cost of capital tied up in unsold grain | \(1-\gamma\) |
| Latest possible sale date (next harvest clearing) | \(T\) |
| “Should I sell today?” | \(a^*_t(s)\) |
| Expected profit per tonne under optimal policy | \(V_0(s)\) |
Interactive solver
Backward induction on a discrete price grid
How the MDP is built
The user specifies a price range \([p_L, p_H]\) discretized into \(|S|\) evenly-spaced states. Persistence (weekly volatility) determines the self-transition probability; the remaining mass splits between the state above and the state below, plus a small drift. Transitions out of the top state are absorbed back in; same for the bottom. Backward induction then fills the value table \(V_t(s)\) from \(t = T\) to \(t = 0\), and the optimal action \(a^*_t(s)\) is recovered by comparing the two arguments of the Bellman equation at each cell.
Reading the solution
What the heatmap and value curves reveal
Three patterns to watch for
- Reservation price falls as \(T\) approaches. Early in the marketing window, the threshold to sell is high (the option to wait is valuable). As \(t \to T\), the threshold collapses toward the forced-sale price — the option runs out of time.
- Storage cost shifts the threshold down. Higher \(c\) makes holding less attractive; the sell region expands to lower price states.
- Persistence shapes patience. Higher volatility (lower persistence) means prices move around more — holding becomes more valuable at marginal states, and the sell region retreats to the very top.
Sensitivity questions the solver answers instantly
- What if weekly interest doubles? Drop \(\gamma\) to, say, 0.995 — the option-to-wait loses value and the hold region shrinks.
- What if futures have strong seasonal carry? Raise the drift parameter — the expected price path tilts up and the sell threshold rises.
- What if forward contracts lock in \(p_F\) early? Raise the forced-sale price — everyone's terminal outcome improves, and early-season hold regions expand.
Model extensions
Richer sales models that all reduce to stochastic DP
Partial-sale policies
Replace the binary sell/hold with a continuous action \(u_t \in [0, 1]\) representing the fraction of the remaining stock to sell at week \(t\). The DP is still tractable via a concave value function; the optimal policy is still a threshold but now “how much” replaces “whether”.
See the tactical cell →Partial observability (POMDP)
Real grain traders don't observe the “state” — they observe noisy prices that mix trend and transient shocks. A POMDP formulation marginalizes over the hidden trend state; solvable via particle filtering + value iteration on the belief simplex.
Stochastic family →Hedging with futures
Expand the action space to include futures-contract positions. The dual gain (reduced variance) shifts the optimal threshold and is directly observable in dynamic hedging strategies used by Canadian grain marketers.
See: Crop Portfolio Selection →Key references
Cited above · DOIs and permanent URLs