Module 10 · Financial Time-Series Foundations Lesson 93 of 120

Lags, Leads, and Temporal Dependence

Keeping past features separate from future labels.

2:22 clip5:01:28–5:03:51 in the full courseWatch on YouTube

Transcript

17 sentences · select one to jump there

Check your understanding

What does a one-row lag mean on an irregular event series?

Choose one answer

Code lab

Run it yourself

The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.

093-lags-leads-and-temporal-dependence.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 093 of 120
 * Lags, Leads, and Temporal Dependence
 * Module 10: Financial Time-Series Foundations
 *
 * Scenario: Keeping past features separate from future labels
 * Rule:     lag₁ at t = xₜ₋₁; lead₁ at t = xₜ₊₁
 *
 * Try it:   What does a one-row lag mean on an irregular event series?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/financial-time-series-foundations/lags-leads-and-temporal-dependence/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson093() {
  const values=[10,12,11,15];
  const lag=values.map((_,i)=>i===0?null:values[i-1]);
  const lead=values.map((_,i)=>i===values.length-1?null:values[i+1]);
  const result={lag,lead};
  return result;
}

export const checkedResult = {"lag":[null,10,12,11],"lead":[12,11,15,null]};

// Run this file directly: npx tsx lessons/10-financial-time-series-foundations/093-lags-leads-and-temporal-dependence.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson093(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "lag": [
    null,
    10,
    12,
    11
  ],
  "lead": [
    12,
    11,
    15,
    null
  ]
}

Prefer your own machine? Every file is in the course repository · open it in Codespaces.

Lesson notes

The rule

lag₁ at t = xₜ₋₁; lead₁ at t = xₜ₊₁