End-to-end workflow · Calgary unleaded retail price

From daily price ticks to a working next-day forecast

A complete, auditable pipeline for Calgary retail unleaded fuel prices — collection, three data-processing stages, model selection, validation against a naive baseline, governance, and a live forecasting console below, built on 1,516 recorded trading days from Jan 2021 to Oct 2026.

1,516
recorded trading days
5.91¢
best model MAE (vs 6.17¢ baseline)
8
lag & rolling features
5
models benchmarked
1
Data Collection

Daily retail price ticks, business days only

The source file records Calgary unleaded retail price for every trading day from 1 Jan 2021 to 23 Oct 2026 — no entries on weekends, so the series follows the market's own posting calendar rather than the full civil calendar.

FieldDescription
DatesMM/DD/YYYY, one row per trading day
UnleadedRetail price, as recorded

Range: 1 Jan 2021 → 23 Oct 2026  ·  1,516 rows  ·  0 duplicate dates  ·  0 missing values

167.5 ledger.csv 10/21/2026 156.2 10/22/2026 167.5 10/23/2026 167.5 10/24/2026 — (weekend, no entry) 10/26/2026 …
2
DP1 · Cleaning & Quality Checks

Verify before trusting a single row

No weekend data was invented. Cleaning only parsed, sorted and checked what was actually recorded — gaps from weekends were left as gaps, not filled.

CheckResult
Dates parsed (MM/DD/YYYY)1,516 / 1,516 parsed
Duplicate dates0 removed
Non-positive / missing prices0 removed
Rows kept1,516
Added fieldsday_of_week, gap_days

Output: cleaned_data.csv — sorted chronologically with the real recorded calendar intact.

3
DP2 · Feature Engineering

Lag and rolling features, chosen from the data's own autocorrelation

Price levels stay highly correlated out to lag 10 (0.88+); day-over-day changes show momentum at lag 1 and reversal at lag 2 before fading to noise — so the feature set spans both signals without reaching past where that signal decays.

Lag (days back)Price-level correlation
10.987
20.969
30.956
50.937
100.883
200.772

Selected features (window: 5 trading days)

lag_1lag_2lag_3 lag_5lag_10diff_1 roll_mean_5roll_std_5

Target: target_next_price — the next recorded day's price, never an invented weekend row. Every feature uses information strictly before the predicted day.

Output: lag_features.csv — 1,505 rows (11 dropped: 10 for insufficient lag history, 1 for no next-day target).

4
DP3 · Standardization & Split

Scale on the past only, split on time, never shuffle

Each feature was standardized ((value − mean) ÷ std) using statistics from the training rows alone, then applied unchanged to validation — fitting on the full series would leak future information into training.

Chronological split

Training15 Jan 2021 → 27 Aug 2025
Validation28 Aug 2025 → 22 Oct 2026
Split ratio80 / 20, no shuffling

Why no shuffling

This is a time series: shuffling would let a model train on days after the ones it's tested on — something it could never see in real use. Validation deliberately covers the most recent, most volatile 14 months, including the sharp 2026 jumps.

Outputs: train_data.csv (1,204 rows) and validation_data.csv (301 rows).

5
Modeling

Four models, one honest benchmark

Each model targets a different pattern found in the data — a near-random-walk level, non-linear jump/reversal structure, and the risk of overfitting daily noise.

ModelReason selected
Previous-Price BaselineNaive benchmark — any model must beat "tomorrow = today"
Linear RegressionLag_1 correlates ~0.99 with next price — a near-linear relationship
Decision TreeCaptures the jump/reversal thresholds a straight line can't
Random ForestAverages many trees to steady a single tree's overfitting
Gradient BoostingTargets residual errors round by round, tuned shallow against overfitting

Alternatives considered

  • Ridge / Lasso — regularizes correlated lag features
  • ARIMA / exponential smoothing — built for serial dependence; a second baseline
  • XGBoost / LightGBM — faster, often stronger boosting if more accuracy is needed

All five artifacts (including the baseline) were trained on train_data.csv and saved for reuse.

6
Validation

Measured against 301 held-out days the models never trained on

Linear Regression has the lowest error on every metric but RMSE, edging out the baseline — evidence the series is close to a random walk, where "today's price" is already a strong predictor and the extra features add a modest, real improvement.

ModelMAERMSEMedAERMSLE

Recommendation: Linear Regression — MAE 5.91¢/L vs. 6.17¢/L for the baseline. All models lag slightly behind the actual price during sharp jumps (e.g. early Oct 2026), since every feature is built from past prices only.

7
AI Governance

Checklist before this model informs a decision

Data quality

  • Validate date format & units on every refresh
  • Check gaps, duplicates, non-positive prices
  • Re-run autocorrelation checks periodically

Leakage

  • Features use only pre-prediction information
  • Scaler mean/std fixed from training only
  • Chronological split preserved on every retrain

Licensing

  • Confirm usage terms for the price data source
  • Record source & attribution with the model files

Market changes

  • Supply shocks, tax/policy shifts trigger review
  • Flag high-volatility periods as lower confidence

Monitoring

  • Track rolling MAE/RMSE vs. the baseline threshold
  • Watch feature drift vs. training distribution
  • Log every prediction with inputs & model version

Human review

  • A person reviews forecasts before any purchasing or pricing action
  • Large/anomalous predictions flagged for manual check
  • Review each quarter, and after any market shock
Key risk: the model cannot anticipate sudden jumps — it is built only from past prices. Mitigation: treat every forecast as a planning input a human reviews, never an autonomous trigger, with a wider safety margin during known volatility.
8
Deployment

Live forecasting console

Enter the last 10 recorded trading-day prices (oldest to newest) and the page computes the same lag features used in training, standardizes them with the training-set mean and standard deviation, and applies the saved Linear Regression weights — entirely in your browser.

Next-day price forecast
Final model: Linear Regression · lags 1, 2, 3, 5, 10
Example data loaded
DatePrice (¢/L)
↓
Downloads

All generated files

Every CSV produced across the workflow, ready to open in a spreadsheet or load back into Python.