Could You Have Known That Data Then? Time Alignment Across Four Price Intervals
A backtest can have the wrong chronology even when there are no missing values and the code runs. Applying a decision made from today's closing price to today's already completed return puts later knowledge into an earlier decision.
Start with a small artificial price sequence. These numbers illustrate time alignment; they are not actual security or strategy returns.
Why the same prices produce +21% and −19%
Set prices to 100 → 110 → 99 → 108.9 → 98.01. The four interval returns are +10%, −10%, +10%, and −10%. Assume the rule: “If the interval that just ended was positive, hold the asset during the next interval.”
| Interval | Ending price | Interval return | Signal after interval ends | Weight incorrectly applied to that same interval | Weight delayed by one interval |
|---|---|---|---|---|---|
| 1 | 110 | +10% | 1 | 1 | 0 |
| 2 | 99 | −10% | 0 | 0 | 1 |
| 3 | 108.9 | +10% | 1 | 1 | 0 |
| 4 | 98.01 | −10% | 0 | 0 | 1 |
Incorrect alignment holds only the rising intervals: 1.1 × 1.1 − 1 = +21%. Delaying the signal by one interval holds the two falling intervals: 0.9 × 0.9 − 1 = −19%.
The following code performs the calculation with the standard library's Decimal. The code and its output labels are retained identically in both language versions; the two labels mean “applied to the same interval” and “applied one interval later.”
from decimal import Decimalprices = [Decimal(x) for x in ['100', '110', '99', '108.9', '98.01']]returns = [b / a - 1 for a, b in zip(prices, prices[1:])]signals = [int(r > 0) for r in returns]same_interval = signalsnext_interval = [0] + signals[:-1]def cumulative_return(positions): wealth = Decimal('1') for position, change in zip(positions, returns): wealth *= 1 + position * change return wealth - 1print(f'같은 구간에 적용: {cumulative_return(same_interval):+.0%}')print(f'한 구간 뒤에 적용: {cumulative_return(next_interval):+.0%}')Expected output:
같은 구간에 적용: +21%한 구간 뒤에 적용: -19%This example changes only the interval to which returns are assigned. It assumes weights can change immediately at interval boundaries and does not model order delays, execution prices, or costs. It is not evidence that a trade can execute instantly at a closing price after that price becomes known. A one-interval shift alone does not make a realistic backtest.
A data row needs more than one time
A financial statement's date being a quarter-end does not mean the figure was known at quarter-end. It becomes usable only after publication and delivery by the provider. The SEC's EDGAR API provides submission histories and financial XBRL data, updating JSON as filings are disseminated. EDGAR API guide
When joining actual data, trace this sequence:
Measurement period → publication/submission → availability → signal calculation → order/executionThe proposed check is availability time ≤ decision time < execution time. Events on the same date can still occur in the wrong order, so consider time zones and market closes. If delivery time is unknown, record a delay assumption instead of inventing an actual timestamp.
Align price definitions first
If one share costs 100 and a 2-for-1 split produces two shares at 50 each, the simple holding value remains 100. Joining only the closing-price column and calculating a −50% loss treats the split as a price decline. Investor.gov explanation of stock splits
For actual data, check:
- Whether prices are raw or adjusted, and whether adjustments include splits, dividends, or both.
- Whether the measure covers price changes alone or reinvested distributions.
- Whether adding cash dividends separately to adjusted prices would double-count them.
- Whether price and volume currencies, units, and trading sessions are consistent.
The column name adjusted_close cannot replace a definition. Connect the chosen provider's documentation and download settings to the input file.
Before removing blanks, inspect how the sample changes
Holidays, pre-listing periods, trading suspensions, collection failures, and join errors can all create blanks, but they are different events. Forward-filling assumes the previous value remains valid. Deleting a row excludes that time or asset from the sample.
Record original values, possible causes, supporting material, processing rules, and affected-row counts. Claiming leakage in a particular pipeline requires checking its actual inputs and calculation windows. Filling missing values or obtaining high performance does not by itself establish an error.
Also inspect the use of today's asset list throughout history. If securities that later disappeared are excluded from the beginning, the universe differs from what was available at the time. For research on a small fixed ETF set, state that scope rather than generalizing to the whole market.
Latest revised values differ from what was known then
Economic statistics can be revised after publication. Historical values downloaded today are not guaranteed to match values known at the time. The FRED API explains how to specify real-time periods to retrieve information known as of an earlier period. Distinguish default retrieval from historical vintages. FRED Real-Time Periods
If an indicator becomes a feature, preserve its observation date, initial release date, vintage, and the time a revised value takes effect. If historical information is unavailable, disclose the use of the latest revised values and include it in the research limitations.
A minimal audit table before the experiment
| Question | Material to check | What to record |
|---|---|---|
| What does the price represent? | Provider documentation and column definition | Adjustments, currency, and selection rationale |
| When could it be known? | Filing, release, and receipt times | When it entered the signal |
| What was changed? | Raw data and cleaning logs | Deletion, filling, and correction rules and row counts |
| Was the asset available then? | Membership, listing, and delisting information | Universe construction and missing coverage |
| Which revision is this? | Vintage and download records | Snapshot time and hash |
| When was trading assumed to occur? | Signal, order, and execution definitions | Return attribution intervals and cost assumptions |
The artificial example shows that time alignment alone can change the numbers. On your own data, the key question is not the size of that difference but whether each value used in a decision was already available then.
The next backtest-validation design article discusses how to split those inputs into training, validation, and test periods.
Report an error or share feedback
Open a draft with this article’s title and URL. Review the message and recipient before sending.
Open email draftIf no email app opens, copy these details into your usual email service.
Related posts
Quant & Data Research Designing a Logistic Regression Comparison: Timing, Evaluation, and Failure Handling
A design for comparing logistic regression with a baseline: timing, common evaluation periods, costs, and failure handling, distinguished from actual model results.
Quant & Data Research Why shift(1) Is Not Enough: A Time Contract for Signals, Execution, and Labels
Synthetic checks for signal timing, execution, return attribution, completed labels, and preprocessing, including deliberately faulty implementations.