TITLE: Optimal strategy for selling turnips
QUESTION [5 upvotes]: You have a pile of $N$ turnips that you need to get rid of in $n$ days. The turnip price every day is independently and uniformly distributed in $[0, 1]$. You can sell any amount of turnips every day, but you must sell everything by the last day. What strategy should you employ to maximize your profits?
(Context. This is related to the "stalk market" in Animal Crossing: New Horizons; see edit history.)

REPLY [2 votes]: Following Rob's suggestion to use dynamic programming, I was able to work out the answer for prices following an arbitrary distribution. Here are the details.
The states are $(n, N, x)$ where

$n$ is the number of days remaining,
$N$ is the number of turnips you've got, and
$x$ is the current day's price.

Let $V(n, N, x)$ be the maximum profit over all possible strategies starting from the state $(n, N, x)$. The expected maximum profit with $n$ days and $N$ turnips is equal to
$$W(n, N) = \int_{\mathbb{R}} V(n, N, x) \, \mathrm{d}\mu(x) \tag{1}$$
where $\mu(x)$ is the price distribution.
Now, here's the key idea. Regardless of what strategy you're following, at the end of the day you're going to sell some number $M$ of your turnips at the day's price $x$, for a profit of $Mx$, and then have $N\!-\!M$ turnips left over to sell within the next $n\!-\!1$ days, for an expected profit of at most $W(n\!-\!1, N\!-\!M)$. Therefore, the maximum profit satisfies the recurrence relation
$$V(n, N, x) = \max_{0 \leqslant M \leqslant N} \Big\{ Mx + W(n\!-\!1, N\!-\!M) \Big\}. \tag{2}$$
Although the relation (2) seems complicated, it's simplified—and, in fact, solved—by the observation that $V$ is homogeneous in $N$.
Proof. It's clear that $V(0, N, x) = 0$, since there are no days left to sell anything. Note that the zero function is homogeneous. So suppose by induction that for some $n$, the function $V(n, N, x)$ is homogeneous in $N$, i.e., we have $V(n, N, x) = NV(n, 1, x)$ for all $N$ and $x$. Then the function $W(n, N)$ is also homogeneous in $N$, by (1). Now, by the recurrence relation (2) and the homogeneity just established, we have
$$V(n+1, N, x) = \max_M \big\{ Mx + (N - M)W(n, 1)\big\}, $$
which is the maximum of a linear function in $M$ with slope $x - W(n,1)$. If the slope is positive, the function is maximized at the right endpoint $M = N$ with maximum $Nx$; if negative, it's maximized at the left endpoint $M = 0$ with maximum $NW(n,1)$. These two cases can be combined into one expression, yielding
$$V(n+1, N, x) = N \max\{x, W(n,1)\}. \tag{3}$$
Not only does (3) show that $V(n+1, N, x)$ is homogeneous in $N$ (thus completing the proof), it also encodes the optimal strategy: with $n+1$ days left, sell if $x > W(n, 1)$, otherwise hold.
The sequence of cutoffs $\lambda_n := W(n, 1)$ is highly dependent on the particular price distribution $\mu$. Combining (1) and (3) yields the recurrence relation
$$\lambda_{n+1} = \int_{\mathbb{R}} \max\{x, \lambda_n\} \, \mathrm{d}\mu(x) \tag{4}$$
where, of course, $\lambda_0 = 0$. Specializing to the case $\mu \sim U(0, 1)$ from the OP we get $\mathrm{d}\mu(x) = 1_{[0,1]}(x) \mathrm{d}x$, so that
$$\lambda_{n+1} = \int_0^1 \max\{x, \lambda_n\} \, \mathrm{d}x = \frac{\lambda_n^2 + 1}{2}.$$
The first few values are approximately
\begin{array}{c|ccccccc}
n & 0 & 1 & 2 & 3 & 4 & 5 & 6 \\ 
\hline 
\lambda_n & 0 & 0.5 & 0.625 & 0.695 & 0.742 & 0.775 & 0.800
\end{array}
For completeness' sake, I'll also address my original intended application: the Fluctuating pattern in the AC:NH stalk market. There, $\mu \sim U(0.9, 1.4)$ and you have $n = 7$ chances to sell. The cutoffs are
\begin{array}{c|ccccccc}
n & 0 & 1 & 2 & 3 & 4 & 5 & 6 \\
\hline 
\lambda_n & 0 & 1.15 & 1.213 & 1.248 & 1.271 & 1.288 & 1.300
\end{array}
and, following the optimal strategy, your expected profit is $W(7, N) \approx 1.31015 N$, just over a 31% return!