Inspiration

We were interested in the concept of price hedging in agriculture, which was referenced in a book one of our members read last year. After further looking into potential applications, we discovered a strong correlation between natural gas and fertilizer prices. To democratize data access and create tools to make agricultural workers more nimble in a data-driven world, we created foreGASt.

What it does

Prices in agriculture are largely inelastic, due to the production cycle being highly time-sensitive (i.e. seasonal planting cycles). As a result, farmers have few protections against price fluctuations. There exist loans and financial instruments in place to make price spikes manageable, but what if a farmer had the ability to see price fluctuations before they even occur?

Our goal with foreGASt is to use ML to quantify the correlation between the prices of fertilizer inputs, such as natural gas, and the price of fertilizer. By using a regression model and several Monte Carlo simulations, we have built a financial tool that we believe can confidently map the price of fertilizer 30, 60, or 90 days into the future with relative (75%) accuracy. Large processing and agricultural supply corporations will have access to this data- regular farmers won’t, which is why this tool is important.

How we built it

The project started with searching for databases with important data we needed, such as the price of natural gas and fertilizers in the previous decades. Afterwards, the team members diverged, with two of us working on the front-end aspects of the design, and the other two analyzing the data to train an AI model to predict fertilizer prices.

The front-end aspects were all built using Streamlit, a Python framework that integrates well with AI models and data visualization frameworks. To create the front-end, we first planned out the major features we wanted to add. These included: A login feature that saved user information The ability for users to add in plants along with the acreage A visual representation of all the crops An overview of the present-day fertilizer cost A recommendation of what the user should do All of the above was created with Claude, which was able to effectively create and debug code using good prompts and different sessions. Additionally, we utilized SQLite databases in order to store and encrypt important user login and input information.

With the major features being done, we then created another tab filled with all the data we processed in the backend. We first sorted out all the data into different categories before planning out all the features we could add. With a comprehensive list and description of all the features we wanted to add, we were easily able to input it all to Claude Code to quickly create working code. Finally, we researched simplistic designs tailored to farmers in order to make our site look as good as possible. By slowly changing small elements within the site, we were able to create a site that looked good and worked well.

To tackle the prediction engine, the backend team built a Decoupled Dual-Architecture using XGBoost. Predicting commodity markets is notoriously difficult because "Black Swan" events (like the 2008 crash or 2022 supply shocks) create massive price spikes that confuse standard algorithms. Instead of relying on one model, we trained six distinct models across 30, 60, and 90-day horizons. We used an XGBoost Regressor to predict the exact future dollar amount of Urea, and a completely separate XGBoost Classifier to strictly calculate the probability of the market trending up or down.

We trained this pipeline on a 25-year historical dataset (1997–2024). To ensure the AI learned real market fundamentals rather than just memorizing specific time periods, we used a Randomized Train/Test Split, hiding 15% of the data as a blind test set.

Finally, we implemented Walk-Forward Cross-Validation to generate a historical error distribution, which we fed into a custom Monte Carlo Risk Engine. This engine takes the XGBoost prediction and runs 10,000 randomized "what-if" future scenarios, allowing us to calculate true probabilistic confidence intervals for farmers to see if they would like more information.

Challenges we ran into

  • Our initial struggle was finding good, reliable data without much noise. Our model struggled with the massive 2021-2022 Ukraine fertilizer price spikes. When tested on the 2023-2024 stabilization period, the model hallucinated massive upward swings because it was over-weighting the 2022 volatility, resulting in an essentially coin flip accuracy. We solved this by changing our weighting multipliers based on how recent the year is, switching our classifier to a binary: logistic objective, and forcing the model to learn fundamentals rather than panicking over outliers.
  • Halfway through the 24 hours, we realized our team was slightly misaligned on who the product was actually for, and the project lacked the cohesiveness we wanted. We put a hard stop on coding, spent an hour getting everyone on the exact same page, and pivoted the project to be a "Farmer-First" tool rather than an abstract financial dashboard. It cost us some time, but the resulting productivity and novel direction were completely worth it.

Accomplishments that we're proud of

  • Predictive Edge on Free Data: We successfully built a model that predicts the direction of fertilizer prices 90 days out with ~75% accuracy (rigorously tested by averaging across 50 training runs). Predicting commodity markets is notoriously difficult, and doing it with this level of accuracy using only free, public datasets (World Bank, EIA) without paying for premium financial APIs is a massive win for the team.
    • We didn't want the dashboard to just spit out a single, fragile price guess. Our backend actually runs 10,000 randomized Monte Carlo simulations of future price paths. This allows the app to calculate true probabilistic confidence intervals (like P10/P90 worst-case scenarios) so farmers can see the actual mathematical risk of buying now versus waiting.
    • We hid all the heavy data science behind a clean Streamlit interface. A farmer doesn't need to be a quant to use it—they just type in their crop (e.g., Corn) and acreage, and the app automatically calculates their specific nitrogen exposure and translates the global energy shock into a personalized recommendation.

What we learned

  1. Yogeshwar - I really enjoyed developing and working on improving this model and integrating it into the frontend. I didn't have much financial knowledge, and I really enjoyed taking my ML skills and applying it to a new domain!
  2. Miles - I’ve done hackathons before, but working on a project like this with four people was new to me. It involved familiarizing myself with git (something I should have done a long time ago). I am grateful for what this project taught me about collaboration in app development, as well as allowing me a chance to apply economics concepts I have learned about in classes.
  3. Chris - It was a very new experience to be able to use AI to create the vast majority of the code. I was able to learn a lot about creating good prompts for the LLM’s to make sure nothing bad was added and creating code extremely efficiently with AI.
  4. Damien - It was interesting learning more about the energy markets and how I can tie this in with what I have learned in the past and create a potential product that could help end users. It helped me realize maybe entrepreneurship is something I will be interested in in the future. I also have limited finance knowledge so learning about monte carlo sims and other different predictive models I feel has enhanced my ml/data science background.

What's next for foreGASt

The next step, without question, would be acquiring more robust datasets. As it stands, it’s a miracle the model is as accurate as it currently is with the free datasets it is trained on. With just $50-$100, we could purchase access to more frequent and more historic datasets which would greatly increase prediction accuracy.

As a product, this tool makes the most sense if a bank or financial services company were to acquire it and offer it as a feature to customers. This naturally supplements a suite of financial dashboards targeting customers on a farming financial plan or something similar.

An interesting application of this tool, which we did not explore, would be informing on the use of natural gas options as a method of hedging against price volatility. A more advanced ML model could be used to advise on risk hedging, but that was outside the scope of our project for this 24 hour stretch.

Built With

Share this project:

Updates