Skip to main content

Market Timing & Sales

STOCHASTIC DYNAMIC PROGRAMMING

Agriculture · Distribution · Tactical

After 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

3.4 Mt
of grain corn produced in Québec in the 2022 crop year — most marketed between September and the following July, giving about ten months of optimal-stopping decisions.
Statistics Canada, Table 32-10-0359-01 · StatCan field crops
$2–4 / t / mo
typical on-farm grain storage cost in Canada — interest, shrink, aeration energy, and insurance — the marginal cost of “hold one more week”.
Agriculture & Agri-Food Canada, farm financial benchmarks · agriculture.canada.ca
20–40%
range of corn-futures annual volatility (implied or realized) in recent cycles — large enough that “sell immediately” is rarely optimal and timing has measurable cash-flow value.
CME Group, Corn Futures options markets · cmegroup.com

Where this decision fits

Agriculture sector decision chain · tactical, post-harvest horizon

Strategiccrops & fields
Workforceseasonal labour
Growingirrigation & pests
Harvestscheduling
Transportfield to silo
Market & Salesthis page

Problem & formulation

Optimal stopping MDP with discrete price-state Markov chain

OR family
Stochastic DP / MDP
Complexity
P (value iteration)
Solver realism
★★★ Exact on discrete grid
Reference
Bellman (1957)

Sets & indices

SymbolMeaningDomain
\(t \in \{0, 1, \ldots, T\}\)Week index; \(t = 0\) is the decision being made now, \(t = T\) is the end of the marketing windowfinite
\(s \in S\)Discrete market-price state (5–11 buckets around the long-run mean)\(|S|\) buckets

Parameters

SymbolMeaningUnit
\(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

SymbolMeaningDomain
\(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:

$$V_T(s) \;=\; p_F$$ $$V_t(s) \;=\; \max\!\Bigl\{\underbrace{p_s}_{\text{sell now}}\,,\ \underbrace{-\,c \;+\; \gamma \sum_{s' \in S} P_{s,s'} \, V_{t+1}(s')}_{\text{hold, pay storage, await next week}}\Bigr\} \qquad t < T$$

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 officeIn 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

Market-timing MDP solver
Discrete Markov price chain · exact value iteration · O(T · |S|²)
★★★ Exact on grid
From harvest to next crop year
Lowest bucket
Odd ≥ 3 recommended
Prob. of staying in same state
Seasonal bias toward higher prices
$2–4/t/month → 0.5–1.0/wk
1 / (1 + weekly rate)
Spot liquidation before next harvest
V₀(midprice) ($/t)
Reservation @ t=0
Reservation @ t=T/2
Gain vs forced-sell
Sell now Hold Reservation threshold

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

Bellman, R. (1957).
Dynamic Programming.
Princeton University Press. Foundational text of dynamic programming and value iteration.
McCall, J. J. (1970).
“Economics of information and job search.”
Quarterly Journal of Economics, 84(1), 113–126. doi:10.2307/1879403
Schwartz, E. S., & Smith, J. E. (2000).
“Short-term variations and long-term dynamics in commodity prices.”
Management Science, 46(7), 893–911. doi:10.1287/mnsc.46.7.893.12034
Puterman, M. L. (1994).
Markov Decision Processes: Discrete Stochastic Dynamic Programming.
Ahumada, O., & Villalobos, J. R. (2009).
“Application of planning models in the agri-food supply chain: A review.”
European Journal of Operational Research, 196(1), 1–20. doi:10.1016/j.ejor.2008.02.014
Statistics Canada.
Table 32-10-0359-01 — Estimated areas, yield, production, average farm price and total farm value of principal field crops.
CME Group.
Corn Futures market data & volatility reports.

Need to time grain sales
on your farm or cooperative?

Get in Touch
Data and numerical examples are illustrative (representative Quebec grain-oilseed farm). This is an educational tool, not production software or trading advice.