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

Autocovariance and Autocorrelation

Measuring lagged similarity on a declared finite-sample convention.

2:29 clip5:11:29–5:13:58 in the full courseWatch on YouTube

Transcript

18 sentences · select one to jump there

Check your understanding

What denominator does this source convention use at lag one?

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.

097-autocovariance-and-autocorrelation.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 097 of 120
 * Autocovariance and Autocorrelation
 * Module 10: Financial Time-Series Foundations
 *
 * Scenario: Measuring lagged similarity on a declared finite-sample convention
 * Rule:     γₖ=(1/n)Σ(xₜ−x̄)(xₜ₋ₖ−x̄); ρₖ=γₖ/γ₀
 *
 * Try it:   What denominator does this source convention use at lag one?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/financial-time-series-foundations/autocovariance-and-autocorrelation/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson097() {
  const x=[1,2,3,4];
  const mean=x.reduce((s,v)=>s+v,0)/x.length;
  const gamma=(k:number)=>x.slice(k).reduce((s,v,j)=>s+(v-mean)*(x[j]-mean),0)/x.length;
  const result={gamma0:gamma(0),gamma1:gamma(1),rho1:gamma(1)/gamma(0)};
  return result;
}

export const checkedResult = {"gamma0":1.25,"gamma1":0.3125,"rho1":0.25};

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

Your output

Press Run to execute the code in your browser.

Expected output

{
  "gamma0": 1.25,
  "gamma1": 0.3125,
  "rho1": 0.25
}

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

Lesson notes

The rule

γₖ=(1/n)Σ(xₜ−x̄)(xₜ₋ₖ−x̄); ρₖ=γₖ/γ₀