Day 22 — The store, part two: adjustment as a view, not a column

Friday, 28 August 2026 · Week 4 of 52 · Markets · Study day · 55 min

Storing adjusted prices bakes today’s history into the file and makes yesterday’s file disagree with today’s; computing the adjustment on read costs microseconds and never lies.

What you should be able to do tonight

  • Explain why a stored adjusted-close column is wrong the moment the next dividend is paid.
  • Return a total-return series and a raw price series from the same store with one function and a flag.

Tasks 55 min

35 min Write qlib/store.py’s bars(security, start, end, adjust=True): join bar_daily to corporate_action, compute the cumulative adjustment factor from the end of the window backwards, and apply it. Reuse the arithmetic you validated on day 16.

20 min Test it against the reference: your adjusted SPY series against yfinance’s auto_adjust=True, over 2005-today, and assert the maximum relative difference is under a tolerance you choose and state. When they disagree, the dividend timing convention is the usual culprit.

The running strategy

The store can now return both a raw price series and a total-return series from the same rows, with adjustment computed at read time. That choice is what will let a backtest run in March against the same file you ingested in September without the history having quietly moved.

Resources

Deliverable

qlib/store.py with a working bars() function and a passing comparison against the vendor’s adjusted series to a stated tolerance.

Checkpoint

Your file was correct on Monday. On Tuesday a stock in it goes ex-dividend. What is now wrong if you stored the adjusted close?

Prepare for tomorrow

Ten minutes tonight so Day 23, Saturday, 29 August 2026 starts clean. This is what the evening email sends you.

Create tests/ in the work repo and check pytest runs on an empty test file.

Write down, in one sentence, what an as-of test should assert. Tomorrow you implement whatever you wrote.

Pick a date in 2019 and note what you would want your store to return for it if you asked as of that date.