---
title: "Safeguard Mechanism reform: pre- vs post-1 July 2023"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Safeguard Mechanism reform: pre- vs post-1 July 2023}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", eval = FALSE)
```

On 1 July 2023 the Safeguard Mechanism shifted from
production-adjusted facility-specific baselines to industry-average
default baselines declining 4.9 per cent per annum (nominal) to
2030. The *Safeguard Mechanism (Crediting) Amendment Act 2023*
also introduced Safeguard Mechanism Credits (SMCs), a new
crediting instrument. Time-series analysis across the reform
without flagging the regime break is a common analytical error.

## The regime flag

```{r}
library(cer)
cer_snapshot("2026-04-24")

fac_22_23 <- cer_safeguard_facilities(year = 2023)
fac_23_24 <- cer_safeguard_facilities(year = 2024)

unique(fac_22_23$regime)
unique(fac_23_24$regime)
```

The `regime` column is `"pre_reform"` for FY ending in 2023 or
earlier; `"post_reform"` from FY 2023-24 onward.

## Declining baseline trajectory

```{r}
traj <- cer_safeguard_baseline_trajectory("Aluminium",
                                            from_year = 2023,
                                            to_year = 2030)
traj
```

In 2029-30 the default baseline for primary aluminium is 0.657 times
the Schedule 1 default intensity, 31 per cent below its 2023-24 value
(0.657 / 0.951). This is the key number for emissions-intensity reform
analysis.

## TEBA facilities

```{r}
teba <- cer_safeguard_teba_facilities()
head(teba)

# Safeguard data merged with TEBA declaration status
sum(fac_23_24$teba_declared, na.rm = TRUE)
```

Trade-Exposed Baseline-Adjusted (TEBA) facilities are eligible for
softer baseline treatment where international competition would
otherwise lead to emissions-leakage.

## Analytical pitfall: summing across regimes

```{r}
# DO NOT do this without a regime-specific annotation:
all_years <- rbind(fac_22_23, fac_23_24)
# If you sum covered_emissions across all_years you are combining
# two different accounting regimes. Split by regime first:
aggregate(covered_emissions ~ regime, data = all_years, FUN = sum,
          na.rm = TRUE)
```

## SMCs post-reform

SMCs did not exist pre-reform. In post-reform data, the SMC columns
count issuances and surrenders for facilities operating below
their baseline.

```{r}
# Post-reform SMC issuances (approximation; column names may drift)
sum(fac_23_24[, grep("smc", names(fac_23_24))], na.rm = TRUE)
```

## Reconciling against the QCMR

The QCMR does not publish annual covered emissions, so there is no
bundled reference for the facility totals. It does publish Safeguard
surrenders each quarter, which can be checked against a register
extract:

```{r}
cer_qcmr_reference(measure = "safeguard_accu_surrenders")
cer_reconcile(
  value   = 623613,
  quarter = "2024-Q4",
  measure = "safeguard_accu_surrenders"
)
```

If the reconciliation gap exceeds 2 per cent, a CER restatement
has likely occurred between your snapshot date and the bundled
QCMR reference.
