PurposeIntegrating artificial intelligence and quantitative investment has given birth to various agricultural futures price prediction models suitable for nonlinear and non-stationary data. However, traditional models have limitations in testing the spatial transmission relationship in time series, and the actual prediction effect is restricted by the inability to obtain the prices of other variable factors in the future.Design/methodology/approachTo explore the impact of spatiotemporal factors on agricultural prices and achieve the best prediction effect, the authors innovatively propose a price prediction method for China's soybean and palm oil futures prices. First, an improved Granger Causality Test was adopted to explore the spatial transmission relationship in the data; second, the Seasonal and Trend decomposition using Loess model (STL) was employed to decompose the price; then, the Apriori algorithm was applied to test the time spillover effect between data, and CRITIC was used to extract essential features; finally, the N-Beats model was selected as the prediction model for futures prices.FindingsUsing the Apriori and STL algorithms, the authors found a spillover effect in agricultural prices, and past trends and seasonal data will impact future prices. Using the improved Granger causality test method to analyze the unidirectional causality relationship between the prices, the authors obtained a spatial effect among the agricultural product prices. By comparison, the N-Beats model based on the spatiotemporal factors shows excellent prediction effects on different prices.Originality/valueThis paper addressed the problem that traditional models can only predict the current prices of different agricultural products on the same date, and traditional spatial models cannot test the characteristics of time series. This result is beneficial to the sustainable development of agriculture and provides necessary numerical and technical support to ensure national agricultural security.