| Dataset | Records | First observation | Last observation | Missing cells |
|---|---|---|---|---|
| Annual crop | 672 | 1965-12-31 | 2020-12-31 | 0 |
| Daily FX | 1,033 | 2017-01-03 | 2021-02-18 | 0 |
| Monthly FX | 50 | 2017-01-01 | 2021-02-01 | 0 |
| Farm prices | 2,678 | 1985-01-01 | 2020-12-01 | 0 |
Canadian Crop Market Analytics
Production, farm prices and currency exposure for grain procurement
This portfolio project converts four preserved agricultural and foreign-exchange datasets into a validated SQLite decision layer. It demonstrates how an analyst can move from raw snapshots to parameterized SQL, explicit units, tested business logic and an executive interpretation.
Executive snapshot
Largest 2020 crop Wheat 35,183,000 metric tonnes
Barley farm price CAD 220.53 per metric tonne · Dec 2020
250-tonne scenario CAD 55,132 farm-price estimate before logistics and contracts
What the evidence says
- Wheat leads national volume. In the latest annual snapshot, Wheat is the largest of the four covered crops.
- Provincial context matters. Alberta and Saskatchewan represent only the provincial observations included in this teaching dataset; the remainder of Canada is not decomposed.
- Currency changes the USD view. Dividing CAD per tonne by CAD per USD provides a comparable USD estimate for months where price and FX observations overlap.
- This is a monitoring layer, not a purchasing recommendation. Grade, freight, basis, storage, counterparties and contract terms remain outside the data.
Decision question
Canadian breweries, distilleries and food manufacturers need to monitor grain availability and farm-price exposure. This analysis asks:
- Which covered crops dominate national production?
- How have barley, rye and wheat volumes changed over time?
- How much of national barley production is represented by Alberta and Saskatchewan?
- How do Saskatchewan barley prices translate from CAD to USD?
- What would a simple volume scenario cost before commercial adjustments?
Data quality and coverage
The committed files are dated snapshots, not live feeds. Their URLs, checksums and retrieval metadata are documented under data/. See the complete data dictionary.
Analytical architecture
flowchart LR A[Validated CSV snapshots] --> B[(Temporary SQLite)] B --> C[Versioned SQL files] C --> D[R analytical functions] D --> E[English report] D --> F[Spanish report] G[testthat] --> B G --> C H[GitHub Actions] --> G H --> E H --> F
The database is recreated during every run. Composite indexes support the crop–geography–time access patterns, while parameterized queries keep user-supplied values outside SQL text. The full model is documented in Analytical architecture.
National production
The analytical query is executed directly in the notebook so the transformation from relational data to the chart remains visible and reproducible.
WITH latest_year AS (
SELECT MAX(YEAR) AS year
FROM crop_data
WHERE GEO = 'Canada'
)
SELECT
c.YEAR,
c.CROP_TYPE,
c.SEEDED_AREA AS seeded_area_hectares,
c.HARVESTED_AREA AS harvested_area_hectares,
c.PRODUCTION AS production_metric_tonnes,
c.AVG_YIELD AS yield_kg_per_hectare
FROM crop_data AS c
INNER JOIN latest_year AS y
ON c.YEAR = y.year
WHERE c.GEO = 'Canada'
ORDER BY c.PRODUCTION DESC;ggplot(latest_notebook, aes(reorder(CROP_TYPE, production_metric_tonnes), production_metric_tonnes, fill = CROP_TYPE)) +
geom_col(show.legend = FALSE, width = 0.7) +
coord_flip() +
scale_y_continuous(labels = scales::label_number(scale_cut = scales::cut_short_scale())) +
scale_fill_viridis_d(end = 0.85) +
labs(
title = "Wheat dominates the latest national snapshot",
subtitle = "Canadian production in 2020",
x = NULL,
y = "Metric tonnes"
) +
theme_minimal(base_size = 12) +
theme(plot.title = element_text(face = "bold"), panel.grid.minor = element_blank())
Long-run volume provides supply context, but it does not represent inventory available for immediate purchase. Production also needs to be interpreted alongside grade, regional concentration and logistics.
Provincial barley context
WITH national AS (
SELECT PRODUCTION
FROM crop_data
WHERE GEO = 'Canada'
AND CROP_TYPE = ?barley_crop
AND CAST(strftime('%Y', YEAR) AS INTEGER) = ?barley_year
)
SELECT
c.GEO AS geography,
c.PRODUCTION AS production_metric_tonnes,
ROUND(100.0 * c.PRODUCTION / national.PRODUCTION, 1) AS national_share_pct
FROM crop_data AS c
CROSS JOIN national
WHERE c.GEO <> 'Canada'
AND c.CROP_TYPE = ?barley_crop
AND CAST(strftime('%Y', c.YEAR) AS INTEGER) = ?barley_year
ORDER BY c.PRODUCTION DESC;| Covered province | Production (metric tonnes) | Share of Canada (%) |
|---|---|---|
| Alberta | 5,283,000 | 49.2 |
| Saskatchewan | 4,385,100 | 40.8 |
The shares do not sum to 100% because the source includes only Alberta, Saskatchewan and the Canadian total. That constraint is made explicit instead of treating the two provinces as a complete provincial breakdown.
Price and currency exposure
SELECT
CAST(strftime('%Y', p.DATE) AS INTEGER) AS year,
ROUND(AVG(p.PRICE_PRERMT), 2) AS avg_price_cad,
ROUND(AVG(p.PRICE_PRERMT / fx.FXUSDCAD), 2) AS avg_price_usd,
COUNT(*) AS months_observed
FROM farm_prices AS p
INNER JOIN monthly_fx AS fx
ON p.DATE = fx.DATE
WHERE p.CROP_TYPE = ?price_crop
AND p.GEO = ?price_geography
GROUP BY CAST(strftime('%Y', p.DATE) AS INTEGER)
ORDER BY year;SELECT
p.DATE,
p.PRICE_PRERMT AS price_cad_per_tonne,
fx.FXUSDCAD AS cad_per_usd,
ROUND(p.PRICE_PRERMT / fx.FXUSDCAD, 2) AS price_usd_per_tonne
FROM farm_prices AS p
INNER JOIN monthly_fx AS fx
ON p.DATE = fx.DATE
WHERE p.CROP_TYPE = ?price_crop
AND p.GEO = ?price_geography
ORDER BY p.DATE DESC
LIMIT 6;| Month | CAD / tonne | CAD per USD | USD / tonne |
|---|---|---|---|
| 2020-12-01 | 220.53 | 1.2808 | 172.19 |
| 2020-11-01 | 210.63 | 1.3068 | 161.18 |
| 2020-10-01 | 209.91 | 1.3215 | 158.85 |
| 2020-09-01 | 211.70 | 1.3228 | 160.04 |
| 2020-08-01 | 208.87 | 1.3222 | 157.97 |
| 2020-07-01 | 204.45 | 1.3498 | 151.46 |
The conversion is an analytical estimate based on monthly average FX, not an executable foreign-exchange quote.
Procurement scenario
scenario |>
select(
crop, geography, price_date, volume_tonnes,
unit_price_cad, unit_price_usd,
estimated_cost_cad, estimated_cost_usd
) |>
knitr::kable(
col.names = c(
"Crop", "Province", "Price month", "Volume (t)",
"CAD / t", "USD / t", "Estimated CAD", "Estimated USD"
),
format.args = list(big.mark = ","),
digits = 2
)| Crop | Province | Price month | Volume (t) | CAD / t | USD / t | Estimated CAD | Estimated USD |
|---|---|---|---|---|---|---|---|
| Barley | Saskatchewan | 2020-12-01 | 250 | 220.53 | 172.19 | 55,132.5 | 43,047.5 |
This scenario multiplies observed farm price by volume. It excludes freight, quality premiums or discounts, storage, taxes, hedging, financing and negotiated terms. It is useful for sensitivity analysis—not for placing an order.
SQL in the notebook and reusable layer
The decision-driving SQL now appears beside the result it produces and executes during every render. This makes joins, filters, aggregation grain and parameter binding auditable without leaving the notebook. The equivalent production queries remain under sql/ and are called by tested functions in R/analysis.R, preserving a single reusable analytics layer for applications and automated tests.
Reproduce the project
GitHub Actions executes validation, tests and a full bilingual render for every pull request. The generated website is uploaded as a workflow artifact.
Conclusion
The strongest market signal in the covered data is the scale difference between wheat and the other crops, while Saskatchewan and Alberta provide useful—but incomplete—regional context. The price/FX join adds a procurement-oriented currency view, and the scenario layer makes assumptions auditable. A production decision would still require current quotes, delivered-cost modeling, grades, logistics and contract terms.
Continue with the Spanish version or inspect the source and methodology.

