Case Study 22 · Live, 30 November 2026

Grain Prices and Basis by Local Market: Forecasting and the Sell-or-Store Decision

Rolling-origin backtest · ETS · ARIMA · Global LightGBM · Conformal intervals · Diebold-Mariano · Hierarchical basis · Threshold cointegration · Storage decision · DuckDB SQL · R · Python · JavaScript · 89 tests

The business question

A grain cooperative or a farmer in Paraná sells corn and soybeans into a local market whose price follows the port and the world price, but not one for one and not at once. Three questions come back every season. Can the local price be forecast well enough to matter? Is the basis, the gap between the local price and a reference price, easier to forecast than the price itself, as the literature on basis forecasting suggests? And when the harvest comes in, does it pay to store and sell later, once storage and the interest on the money are paid?

This case answers them on 25 years of public daily quotes, in the way a forecast should be judged before anyone relies on it: every model sees only what was known at the time, and every result is compared with the simplest forecast there is, the last price. It shows the method; it is not market advice. The other commodity cases are the price distribution and the multi-agent analyst.

The data

All public, downloaded by a script with no account:

  • Local prices: SIMA, the daily survey of the Paraná state agriculture department (SEAB/DERAL), with the price the wholesale market intends to pay for corn and soybeans in each of the 19 administrative regions (minimum, most common and maximum, R$ per 60 kg bag), from August 2001 to December 2025: 25 yearly archives in three sheet layouts, 209,279 quotes, about 240 trading days a year. The reader finds dates, regions and products by content and is tested on each layout.
  • World prices: World Bank Commodity Price Data (the Pink Sheet, CC BY 4.0): maize, US No. 2 yellow, f.o.b. Gulf; soybeans, US, c.i.f. Rotterdam; monthly, US$ per tonne.
  • Exchange rate, interest and inflation: Banco Central do Brasil, SGS (ODbL): PTAX (series 1), the monthly Selic (4390) and the IPCA (433).
  • A check: CONAB’s weekly price received by Paraná producers, whose open file starts in November 2025. In the 7 weeks it overlaps SIMA, the state averages differ by R$ 0.25 (corn) and R$ 0.17 (soybeans) per bag, with a correlation of 0.99.

There is no public series of the port of Paranaguá or of the futures exchange that can be redistributed: the indicators of the port carry a non-commercial licence, and exchange data have their own distribution policy. So the basis here is measured against Ponta Grossa, the regional market on the road and rail corridor to the port and the seat of the crushing plants, and against export parity (the world price times the exchange rate), which carries freight, port costs and the export premium.

Try it

See prices and basis by market and month; pick a model and a past date and compare its forecast with what happened; read the band of prices within which two markets drift apart without trade correcting it; set the cost of storage and see what each way of selling would have earned in each crop year; and paste your own forecasts to audit them against the naive forecast, in your browser.

Method, and why this one

A weekly panel in SQL. The daily quotes become a weekly panel in DuckDB: the mean of the days quoted in each week, the PTAX of the week, export parity and real prices in money of October 2026 (IPCA). A quality report counts, per market, the weeks with a quote, the longest gap, the weeks at the previous week’s price and the jumps above 15%.

A backtest that only looks back. From January 2013, every four weeks, each model forecasts the price of each market 1, 4, 8 and 12 weeks ahead, using only data up to that date; scores start in 2015, after a two-year warm-up. Models: the naive forecast (the last price), seasonal carry (the last price plus the average change over the same weeks of the past five years), ETS and ARIMA chosen automatically on the last ten years (Hyndman and Khandakar, 2008), and one LightGBM per horizon trained on all markets and both crops with lagged returns, the basis and its deviation from the seasonal norm, the exchange rate and export parity, retrained every twelve weeks. Accuracy is the mean absolute error in R$ per bag and its ratio to the naive forecast (Hyndman and Koehler, 2006); differences are tested with Diebold and Mariano (1995) with the small-sample correction of Harvey, Leybourne and Newbold (1997), on the cross-market mean error of each date.

Intervals that are checked. Every model’s 80% and 95% bands come from the quantiles of its own past errors, already realised, in the previous 104 weeks (a conformal band with a moving window, which keeps coverage when the errors change; Barber et al., 2023). For ETS and ARIMA the page also shows the coverage of the bands the models produce themselves. Pinball loss scores the band and the median together (Gneiting and Raftery, 2007).

Basis forecasts. Four forecasts of each basis: the last value; the five-year average of the same week; that average corrected by how far the basis is from its norm today, with the correction estimated on past data (the approach compared by Sanders and Manfredo, 2006); and the same with the seasonal profile of each market shrunk toward the shape all markets share, more where a market’s own years are few or noisy. The shrinkage is empirical Bayes in closed form, checked against a Gibbs sampler of the same hierarchical model.

Integration between markets. For each market against Ponta Grossa, on weekly log prices 2003-2025: the Engle and Granger (1987) relation with MacKinnon (1994) p-values, the Johansen (1988) trace test, the error-correction speed, and the band threshold model of Balke and Fomby (1997): inside a band the gap can wander because moving grain does not pay; outside it, trade closes the gap (Goodwin and Piggott, 2001). The band is chosen by least squares and linearity is tested by bootstrap (Hansen, 1997). The estimator is written in R and in Python, and a test checks that both give the same band and speeds.

Sell or store, out of sample. For each crop year from 2015 (soybeans from March, second-crop corn from July), market and model, four ways of selling over 24 weeks, reviewed every four: everything at harvest; one seventh at each review; hold while some forecast for 4, 8 or 12 weeks ahead, net of the extra storage and interest, beats selling now; and the best date with hindsight, as a ceiling. Results are R$ per bag over the harvest price, net of storage (R$ 1.00 per bag per month by default, a parameter in the app) and of the Selic the harvest money would have earned. Storage pays only when prices rise by more than the cost of carrying the grain, which is the theory of storage (Fama and French, 1987; Deaton and Laroque, 1992); whether a forecast can time it is what studies of marketing advice find hard (Zulauf and Irwin, 1998; Cabrini, Irwin and Good, 2007).

Result

Beyond one week, the last price is the forecast to beat, and nothing beats it. Over 2015-2025, the 19 markets and both crops, the naive forecast misses by R$ 1.18 per bag for corn and R$ 1.98 for soybeans one week ahead, and by R$ 5.34 and R$ 7.83 twelve weeks ahead. From four weeks on, the best model (ARIMA) is within 2% of the naive forecast and never significantly better (Diebold-Mariano p between 0.22 and 0.86). LightGBM, with lagged returns, basis, exchange rate and export parity, is 5% to 15% worse from four weeks on, significantly so for soybeans, and seasonal carry is 10% to 20% worse: the average rise after past harvests is not a forecast. This is what Tomek (1997) and Fama and French (1987) lead one to expect of a storable commodity, and fits how world soybean prices pass into Brazil (Margarido, Turolla and Bueno, 2007).

The one-week edge comes from averaging. One week ahead, ARIMA, ETS and LightGBM miss soybean prices by 5% to 7% less than the naive forecast (p between 0.001 and 0.011), and LightGBM beats it for corn in every market (4% less error, p = 0.14). A weekly mean of daily quotes has correlated changes even when the daily price is a random walk (Working, 1960), so part of next week’s mean is already known. It is a property of the series, not a trading signal.

Bands keep their promise at one week, not through a break. The conformal 80% bands cover 77% to 81% of outcomes one week ahead. Twelve weeks ahead they cover 70% to 74%, and only 58% to 69% for soybeans in 2020-2022, when price changes outgrew the errors of the two years before. The bands ETS and ARIMA produce themselves are wider: they cover 81% to 92% overall, more than promised, and 74% to 91% in 2020-2022. A desk that quotes a band twelve weeks ahead should widen it after a shock, whichever method it uses.

The basis is not much easier to forecast than the price. The plain five-year average of the same week is worse than the last value up to eight weeks ahead, because the level of the basis shifted: the export basis of soybeans went from R$ 13 to 16 below parity in 2015-2019 to R$ 31 to 45 below in 2021-2023. Corrected by today’s deviation and shrunk across markets, the average does better: for soybeans against Ponta Grossa, 9% to 10% less error than the last value at 8 and 12 weeks, in 16 and 17 of 18 markets; for corn against export parity, 6% less at 8 and 12 weeks, in all 19. The pooled Diebold-Mariano test does not call either significant (p between 0.15 and 0.40). Shrinkage across markets adds under 2% to the corrected average: with 19 markets and five years each, the regional profiles are already well measured.

Markets move together, within a band of about R$ 5 a bag. Every market is cointegrated with Ponta Grossa (Johansen trace statistic between 46 and 131, against a 5% critical value of 20). The band within which a gap can last is about 8% of the price for corn and 4.4% for soybeans, which at 2025 prices is the same money, R$ 4.80 and R$ 5.20 per bag: moving a bag between markets costs the same whatever grain is in it. Outside the band, half of a gap closes in 2.4 weeks for both crops; inside, in 9.5 weeks for corn and 4.3 for soybeans. The band matters for corn (linearity rejected in 14 of 18 markets) and much less for soybeans (6 of 18), whose deeper market keeps prices together even for small gaps.

Storing paid in few years, and no forecast found them. With storage at R$ 1.00 per bag per month and the harvest money earning the Selic, selling one seventh at each review loses R$ 1.36 per bag on average for corn (gains in 2 of 10 crops, 2020 and 2024) and R$ 4.14 for soybeans (gains in 4 of 11, losses of R$ 22 in 2022 and 2023). The forecast-guided rule mostly sells at harvest: with ETS forecasts it rarely holds and ends near zero (R$ -0.12 for corn, R$ -0.05 for soybeans; ARIMA, R$ +0.12 and R$ -0.93); with seasonal carry it holds five weeks on average and loses R$ 2.60 and R$ 3.14; with LightGBM it loses R$ 0.96 and R$ 2.39, almost all of it in 2023, when it held soybeans and prices fell (R$ 24.94 per bag). Perfect timing would have earned R$ 3.94 (corn) and R$ 5.55 (soybeans) per bag, under R$ 0.96 and R$ 1.70 in half the years. With Brazilian interest rates the rise after harvest rarely pays for carrying the grain (Fama and French, 1987; Deaton and Laroque, 1992), and timing it is as hard as studies of marketing advice find (Zulauf and Irwin, 1998; Cabrini, Irwin and Good, 2007). The app lets you lower the storage cost or drop the interest and see when storing starts to pay.

Limits

SIMA is the price the wholesale market intends to pay, surveyed by the state, not a record of trades, and corn quotes often repeat from one week to the next (20% of weeks). Without a public port or futures series that can be republished, the basis is measured against a regional hub and against a world price that carries freight and premium; a desk with exchange data would add the futures basis. World prices are monthly. Storage costs, quality discounts, taxes and the farmer’s need for cash are outside the decision model, and one bag stands for the whole crop. The case shows the method; it is not a forecast of prices to come.

Applied to your business

For a cooperative, a trading company or an agribusiness lender, the same steps run on your own markets and prices: a weekly panel with a quality report, forecasts judged against the naive one before anyone uses them, the basis of each market you buy or sell in, the band within which your markets drift apart, and a backtest of your own marketing or hedging rule. The audit tab is the start: your forecasts, scored against the last price, with the test that says whether the difference is real. It begins with the Data & AI Diagnostic and runs in your environment.

Code

github.com/rhozon/grain-basis-forecasting

With Python 3.11 or later, R 4.4 and Node 18 or later:

pip install -e ".[dev,models]"
python -I tools/fetch_data.py ~/data/grain-basis   # public data, no account
python -m gbx.cli all --data ~/data/grain-basis
pytest -v                                          # Python, and the page's JavaScript against it
cd R/tests && Rscript -e 'testthat::test_dir(".")'

The suite has 89 tests (86 in Python, 3 in R): the reader on each SIMA layout, the weekly panel and quality report in SQL, the accuracy measures against hand computation, the conformal band using only realised errors, features that cannot see past the origin, the hierarchical shrinkage against its Gibbs sampler, the threshold estimator in R against Python, the selling rules, and the audit arithmetic of the page against Python. CI runs them on every push.

References

Data: SEAB/DERAL, Sistema de Informação de Mercado Agrícola (SIMA), historical daily quotes (Fonte: SEAB/DERAL); World Bank, Commodity Price Data (The Pink Sheet), CC BY 4.0; Banco Central do Brasil, SGS (ODbL); Conab, Portal de Informações Agropecuárias, weekly prices (Fonte: Conab).

  • Balke, N. S. and Fomby, T. B. (1997). Threshold Cointegration. International Economic Review, 38(3), 627-645. doi:10.2307/2527284
  • Barber, R. F., Candès, E. J., Ramdas, A. and Tibshirani, R. J. (2023). Conformal prediction beyond exchangeability. The Annals of Statistics, 51(2), 816-845. doi:10.1214/23-AOS2276
  • Cabrini, S. M., Irwin, S. H. and Good, D. L. (2007). Style and Performance of Agricultural Market Advisory Services. American Journal of Agricultural Economics, 89(3), 607-623. doi:10.1111/j.1467-8276.2007.01007.x
  • Deaton, A. and Laroque, G. (1992). On the Behaviour of Commodity Prices. The Review of Economic Studies, 59(1), 1-23. doi:10.2307/2297923
  • Diebold, F. X. and Mariano, R. S. (1995). Comparing Predictive Accuracy. Journal of Business & Economic Statistics, 13(3), 253-263. doi:10.1080/07350015.1995.10524599
  • Engle, R. F. and Granger, C. W. J. (1987). Co-Integration and Error Correction: Representation, Estimation, and Testing. Econometrica, 55(2), 251-276. doi:10.2307/1913236
  • Fama, E. F. and French, K. R. (1987). Commodity Futures Prices: Some Evidence on Forecast Power, Premiums, and the Theory of Storage. The Journal of Business, 60(1), 55-73. doi:10.1086/296385
  • Gneiting, T. and Raftery, A. E. (2007). Strictly Proper Scoring Rules, Prediction, and Estimation. Journal of the American Statistical Association, 102(477), 359-378. doi:10.1198/016214506000001437
  • Goodwin, B. K. and Piggott, N. E. (2001). Spatial Market Integration in the Presence of Threshold Effects. American Journal of Agricultural Economics, 83(2), 302-317. doi:10.1111/0002-9092.00157
  • Hansen, B. E. (1997). Inference in TAR Models. Studies in Nonlinear Dynamics & Econometrics, 2(1). doi:10.2202/1558-3708.1024
  • Harvey, D., Leybourne, S. and Newbold, P. (1997). Testing the equality of prediction mean squared errors. International Journal of Forecasting, 13(2), 281-291. doi:10.1016/S0169-2070(96)00719-4
  • Hyndman, R. J. and Khandakar, Y. (2008). Automatic Time Series Forecasting: The forecast Package for R. Journal of Statistical Software, 27(3). doi:10.18637/jss.v027.i03
  • Hyndman, R. J. and Koehler, A. B. (2006). Another look at measures of forecast accuracy. International Journal of Forecasting, 22(4), 679-688. doi:10.1016/j.ijforecast.2006.03.001
  • Johansen, S. (1988). Statistical analysis of cointegration vectors. Journal of Economic Dynamics and Control, 12(2-3), 231-254. doi:10.1016/0165-1889(88)90041-3
  • MacKinnon, J. G. (1994). Approximate Asymptotic Distribution Functions for Unit-Root and Cointegration Tests. Journal of Business & Economic Statistics, 12(2), 167-176. doi:10.1080/07350015.1994.10510005
  • Margarido, M. A., Turolla, F. A. and Bueno, C. R. F. (2007). The world market for soybeans: price transmission into Brazil and effects from the timing of crop and trade. Nova Economia, 17(2), 241-270. doi:10.1590/s0103-63512007000200002
  • Sanders, D. R. and Manfredo, M. R. (2006). Forecasting Basis Levels in the Soybean Complex: A Comparison of Time Series Methods. Journal of Agricultural and Applied Economics, 38(3), 513-523. doi:10.1017/s1074070800022586
  • Tomek, W. G. (1997). Commodity Futures Prices as Forecasts. Review of Agricultural Economics, 19(1), 23-44. doi:10.2307/1349677
  • Working, H. (1960). Note on the Correlation of First Differences of Averages in a Random Chain. Econometrica, 28(4), 916-918. doi:10.2307/1907574
  • Zulauf, C. R. and Irwin, S. H. (1998). Market Efficiency and Marketing to Enhance Income of Crop Producers. Applied Economic Perspectives and Policy, 20(2), 308-331. doi:10.2307/1349992
WhatsApp ↑