Backtesting & rule researchAdvanced#data-quality#backtest#python#hallucination-guard

Check your price files for splits, gaps and bad prints before scripts use them

A script inspects the daily price files your tests read for missing days, duplicate dates, impossible prices and one-day jumps that look like an unadjusted split. Flagged files are fixed or left out before any backtest runs.

How it works

  1. Keep the price files your scripts use in one folder, with a short note for each source: where it came from, the download date, and whether prices are adjusted for splits and dividends.
  2. Before any backtest, sizing calculation or stats run, a check script reads each file and lists missing trading days against an exchange calendar, duplicate dates, zero or negative prices, highs below lows, closes outside the day's range and zero-volume days.
  3. It flags one-day moves larger than a threshold you set, and tests whether each one matches a common split ratio (2-for-1, 3-for-1, 1-for-10 and so on). A match is labelled "possible unadjusted split" for you to confirm against the company's own announcement or a second source.
  4. Where you have both adjusted and unadjusted closes, it compares them and flags files whose adjustment status disagrees with your note.
  5. The script writes a dated report and a pass or hold status for each file. Files on hold stay out of every run until you fix them or record why they're fine.
  6. The agent explains the report in plain English and never edits a price. You make any fixes and write the reason in the source note.

Copy-paste prompt

Write a Python script that checks my daily price files before my own tests use them. It gives no trading advice and never suggests trades or securities.
Inputs: the folder {{price_dir}} (one CSV per instrument with date, open, high, low, close, volume and adj_close if available), my source notes {{source_notes}}, an exchange trading calendar {{calendar_file}}, and the thresholds {{jump_threshold}} and {{split_ratios}}.
For each file, report:
1. Missing trading days and duplicate dates.
2. Rows with zero or negative prices, high below low or close outside the high-low range, and zero-volume days.
3. One-day close-to-close moves above {{jump_threshold}}, marking any that match one of {{split_ratios}} within 2% as "possible unadjusted split".
4. Whether the adj_close behaviour matches the adjustment status in my notes.
Give each file a status, pass or hold, write a dated report to {{report_path}} and change no data. Include three small test files with known problems so I can check the script catches them.

Guardrails

  • The script and the agent never edit price data. You make any fix and note the reason.
  • Files on hold are left out of every test and calculation until cleared.
  • A flagged jump is a question to check against a primary source, not something the model settles by guessing.
  • Read-only on files; no broker access and no orders.

What can go wrong

A clean report doesn't mean clean data. Row-level checks catch the obvious breaks, but a dividend adjustment applied twice can pass every one of them, and a delisted company missing from the folder isn't a file problem at all. That's survivorship, which comes from how the list was built. Split matching also raises false alarms on genuine large moves such as earnings gaps, so the label says "possible" and the decision stays with you.

Why it helps

A backtest is only as good as the prices it reads, and the errors that matter most look like opportunity: an unadjusted split shows up as a huge one-day drop or jump that your rule happily trades. Agents make this worse, because a script written in minutes rarely checks its inputs, and a summary written by a model sounds equally confident on clean data and on broken data. A pass or hold status per file is a simple gate that every later step can respect.

How it fits with other entries

Run this before the quick rule backtest (aft-0018), the paper-vs-practice comparison (aft-0030) or any trial-logged testing (aft-0041). The prove-it-runs check (aft-0036) tests the script's logic on known cases; this entry tests the data the script is fed.

Where this comes from

A public post by Vinicio Donnarumma (@VinniDon) on X: data errors such as corrupted prints, restated histories and unadjusted splits turn up even in professional data, and he describes a strategy built on free data whose results came from an unadjusted split. The checklist, the split matching and the hold rule are ours.

Source and references

Based on a public post by Vinicio Donnarumma (@VinniDon) on X describing corrupted prints, restated histories and unadjusted splits in market data, including a strategy that only looked good because of an unadjusted split. The checklist, the hold status and the split matching are our adaptation.

Original: Vinicio Donnarumma on x

Spotted an error, or want your post removed? Email hello@agentsfortraders.com.

Educational content only. Not investment advice or a personal recommendation. No tickers, signals or trade alerts. Trading involves risk of loss.

Conteúdo exclusivamente educativo. Não constitui aconselhamento nem recomendação de investimento. Sem tickers, sinais ou alertas de negociação. Negociar envolve risco de perda.

Related use cases