Turnip Prices in Animal Crossing

I was curious about the economy in Animal Crossing New Horizons, and how the stalk market works. The inspiration for this project is Treeki/TurnipPrices.cpp, which appears to be a disassembled version of the actual game source.

What controls the price of turnips?

If that is indeed the actual source of the game, then we can answer the main question a lot of people ask: there is nothing you can do to affect the price of turnips. It is not responding to any external stimuli.
The price is computed as one of four distinct patterns. The exact pattern is part of a random sequence. The pattern is computed once at the beginning of the week, and doesn't change until the next week.
To maximize your profit opportunity, there is some merit to identifying what pattern your market is in. There are several online tools meant to help with this, so I won't explore that avenue much further.

What is this graph?

I extracted the algorithmic portion of the code and broke it into two pieces: the turnip price calculator, and the pattern sequencer.
On cursory examination of the code linked above, a lot of it is devoted to random number generation. I punted trying to adapt that part to Javascript and used the built-in random number facility (with a few helpers). This may mean there is some variation in behavior from this applet to the real game, but I am making an educated guess that the Javascript random number generator is a good enough proxy to allow some analysis of the functions' behaviors.
Using the two pieces of code, this web page samples each pattern 1,000,000 times and computes the average. It similarly samples the pattern sequencer 1,000,000 times to glean information about the relative distribution of the patterns over time. These two values are combined to get the Overall Average.
Some of the characteristics of this code match the empirically observed aspects of the stalk market, namely the 4 patterns, and their relative frequencies. This provides at least anecdotal confirmation that the results are accurate.
If I was going to pursue this further, I would use this code to generate a large number of exemplars and train a neural network to recognize the individual patterns in-game. However...
My assessment for a single player is that whatever price you buy at on Sunday, sell on Wednesday morning for the best overall return of about 10%. But really, don't bother with that at all - go online to the Turnip Exchange website and find a friend in Pattern 1 where the Turnip prices are 500+ Bells.