Integrated R Laboratory

Two self-contained browser labs for financial tail risk and real-time macroeconomic forecasting.

Integrated R Laboratory

Laboratory standard

Every result should expose five objects:

  1. target: what will be known, and at which horizon;
  2. information set: what is available when the forecast is issued;
  3. transformation: units and matrix operation;
  4. recursion or estimator: the exact equation implemented;
  5. evaluation: benchmark and decision-aligned loss.

The two labs below use simulated data so that the true mechanism and information boundary are visible. Replace the simulation only after the audit trail works.

Lab A — financial tail risk without look-ahead

Question

Does a dynamic variance forecast improve one-day risk measurement relative to a variance fixed in the training sample?

The exponentially weighted recursion

h^tt1=λh^t1t2+(1λ)rt12\hat h_{t|t-1} =\lambda\hat h_{t-1|t-2} +(1-\lambda)r_{t-1}^2

uses only returns observed before tt. It is not a full GARCH estimate, but it makes the timing transparent.

R

Finance mini-case: dynamic versus constant one-day risk

Idle

Interpretation

A good conclusion is:

The dynamic forecast has lower QLIKE in this fixed test sample and adapts its quantile to recent squared returns. Coverage is reported overall and by subperiod; neither result establishes adequacy for another asset or a regulatory decision.

A weak conclusion is “EWMA works.” The experiment supports only a model, horizon, loss, and simulated regime.

Extension

Replace the EWMA recursion with the GARCH estimate from Module 4. Estimate parameters using observations through the training endpoint, freeze them, and update only the variance state during evaluation. Then compare Normal and Student-tt quantiles without choosing between them on the final test sample.

Lab B — revised macro data and an impossible forecast

Question

How much apparent accuracy can arise from using a later revision that was unavailable at the forecast origin?

Suppose a first release is noisy and the final revised estimate is more precise. At origin tt, the forecaster observes the first release for period tt, not its final value.

R

Economics mini-case: real-time versus revised-data leakage

Idle

The leaky forecast will often look better because it observes a more precise value for the current latent state. That is exactly why it is invalid. A feasible forecast must be reconstructed from a vintage panel, not from the final column of a modern download.

Matrix and timing audit

For either lab, annotate code with:

CheckEvidence
dimensionsrows of XX equal target observations; covariance matrices are square
datingevery predictor date precedes or equals its forecast origin
state recursionthe forecast at tt uses data no later than t1t-1 when required
numerical identitysymmetry, factorisation, or normal-equation error is near zero
test integrityno model choice uses final test losses
interpretationconclusion names horizon, loss, and population limits

Submission exercise

Choose one lab and make one predeclared change:

  • Finance: compare two fixed λ\lambda values using a validation window, then evaluate the selected value once on a separate test window.
  • Economics: increase the revision delay from three to six periods and rebuild the vintage information set.

Submit the changed equation, code diff, result table, and a 150-word conclusion. A correct null or disappointing result earns the same evidential credit as improvement when the design is honest.

Next: Capstones, Data, and Reading Ladder.

Copyright © 2026