phillips_drifts_volatilities: `kalman_forward` pairs each observation with the previous date's volatility

Open Beginner friendly
#1,108 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@bennibyx is already working on this.

Since Nov 9, 2026.

  • #1116 by @bennibyx — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
77/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
numpy, python

Research direction

Find kalman_forward and inspect how it constructs r from the volatility path h; the issue identifies the current indexing and the intended h[1:] alignment. Read the sampler code that builds h and the filter loop to confirm dates 1 through T align with the observations. Done when each observation uses the same date's volatility and a focused check confirms the final volatility row is used.

Written by the indexing model from the issue text.

Description

kalman_forward builds r from the whole volatility path h, whose rows are dates 0 to T: run_sampler starts it with T + 1 rows, and draw_volatility_path updates log h_0 to log h_T. The filter's loop then uses r[t] for y[t], the observation at date t + 1, so each observation is filtered with R built from the previous date's volatility: R_1 comes from h_0, and h_T is never used. The rest of the sampler pairs h[t] with date t: draw_volatility_path matches h[t] with the residual at date t, draw_β standardises the residuals by h[1:], and the retained draws keep h[1:]. The model is R_t = B^{-1} H_t B^{-1}′ at the same date, which is also what the line's own comment (# R_1, ..., R_T) says.

This came in with the vectorised filter in #1105. The version before it paired h[t] with y[t - 1] in draw_coefficient_path.

The change is to build r from h[1:]:

r = np.einsum('ij,tj,kj->tik', b_inverse, h[1:], b_inverse)    # R_1, ..., R_T

The size of the effect on the posterior has not been measured: the figures and tables would need re-running with the change.

Found by Copilot's review of QuantEcon/lectures#36, which copies this lecture at 4d82fff: https://github.com/QuantEcon/lectures/pull/36#discussion_r4464453856

Dominant language
TeX
Stars
129
Forks
61
Avg merge
2d 4h
Merged PRs (30d)
12

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from QuantEcon/lecture-python.myst

All issues in QuantEcon/lecture-python.myst

Similar issues

More Data Engineering issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.