~/projects/opus-equi
Opus Equi
Probabilistic forecasting of commodity spot prices: a C#/.NET 8 desktop app over a Python FastAPI service. Built as an MSc dissertation.
01What it does
Opus Equi is a Windows desktop application for forecasting commodity spot prices. A user loads historical price data, chooses a model and a date, and gets a chart of the observed prices and the forecast. For future dates the forecast is a range rather than a single number: a median estimate with a 5–95% prediction interval.
It was built as the dissertation for the MSc in Software Development at the University of Glasgow, over nine weeks between June and August 2025. The full dissertation is available to read: Opus Equi dissertation (PDF).
02How it works
The desktop client is written in C# on .NET 8, with WPF for the interface, the MVVM pattern for the view logic and OxyPlot for the charts. It talks to a local Python service built with FastAPI through three typed REST endpoints, one for each step of the workflow:
- Upload: CSV files are sent together, combined into one dataset and saved.
- Train: the chosen model is fitted to the dataset and saved to disk with joblib.
- Predict: a date within the data returns the observed price; a future date returns the forecast, made one day at a time, with each day's median fed into the next.
Two quantile models make the forecasts. XGBoost trains a separate model for each quantile with a custom pinball-loss objective, which weights over- and under-prediction differently for each, and an approximate Quantile Random Forest built on scikit-learn gives a second estimate. Both use features such as earlier prices, rolling averages and calendar information.
The desktop app starts the service itself: it checks for Conda, creates or verifies the Python environment, launches the server locally and waits until it answers before enabling the workflow. If a server is already running, it uses that one instead.
The split keeps the responsibilities clear: the desktop client handles the user's choices and the charts, and the Python service owns the data and the forecasting.
03Challenges
The forecasts depend on clean input, so the upload step had to combine several CSV files reliably. Two problems needed separate answers: the same file uploaded twice in one batch, and files whose date ranges overlapped.
Duplicate files are caught by a SHA-256 hash of each file's contents: a file whose hash has already been seen in the batch is skipped. The remaining files are parsed with pandas, columns with clashing names are renamed, and the files are joined on date, so dates from every file are kept. The result is sorted, identical rows are dropped, and each upload is saved as a uniquely named snapshot alongside a stable copy for the training and prediction steps. A test with files covering different dates confirms that no price history is lost when the files don't line up.
The second was the quantile model. The XGBoost forecasts are trained on the pinball loss, written as a custom objective. For a quantile level τ, the loss weights a forecast that falls short by τ and one that overshoots by 1 − τ, so minimising it gives the τ-quantile of the price rather than its mean.
The loss doesn't suit XGBoost as it stands. XGBoost sizes each step from the gradient divided by the second derivative, the Hessian, and the pinball loss is made of straight lines, so its second derivative is zero almost everywhere and the steps break down. The custom objective returns the gradient, 1 − τ or −τ depending on which side of the price the forecast falls, with a constant Hessian of 1, which keeps every step bounded and training stable.
The starting point needed the same care. XGBoost's default starting value is nowhere near a commodity price, so the early rounds would be spent climbing towards it. Instead, each quantile's booster starts from that quantile of the training prices. One booster is trained for each quantile, at 5%, 50% and 95%, and the trained boosters are kept in a map keyed by quantile.
04Results
- 15 of 18 prioritised requirements met, including all 5 must-haves, tracked in a full requirements traceability matrix.
- 22 automated unit tests, plus integration and acceptance suites aligned to ISO/IEC/IEEE 29119, covering both the Python service and the C# client.
- The data pipeline validated against 27 reproducible mock datasets.
- Short user-testing sessions, whose findings became the backlog for the next version.
05What's next
- Calibrated intervals: a calibration step over a rolling validation window, so that real prices fall inside the 5–95% range as often as it promises, measured with proper scoring rules alongside MAE and RMSE.
- Model versions: each trained model is currently saved under its name and replaced by the next. Timestamped versions and a small model registry would allow comparison and rollback, and tie each forecast to the exact data and model that produced it.
- Repeated dates: a stated policy for dates that appear in more than one file with different prices, with tests for it, so the dataset holds exactly one observation per date.
- From user testing: clearer errors in the client, export of charts as images, and short help text for choosing a model.
- The deferred features: accuracy measures, weather analysis and derivatives pricing.