Blog
Point-in-time joins for option quotes
Sample post. Why an as-of join is the default for any intraday options study.
Tarlan Shabanov1 min read
Placeholder. This post demonstrates the blog layout with code highlighting.
The problem
Intraday option studies combine at least two clocks: the time a quote was published and the time a decision is made. Joining on equal timestamps silently drops rows; joining on the nearest timestamp can silently use the future. The safe default is a backward as-of join: for each decision time , take the latest quote with timestamp .
A minimal implementation
import pandas as pd
def asof_quotes(decisions: pd.DataFrame, quotes: pd.DataFrame,
max_staleness: str = "5s") -> pd.DataFrame:
"""Attach the last quote known at each decision time, never a later one."""
decisions = decisions.sort_values("ts")
quotes = quotes.sort_values("ts").assign(ts_quote=lambda q: q["ts"])
out = pd.merge_asof(
decisions, quotes,
on="ts", by="contract",
direction="backward", # never look forward
tolerance=pd.Timedelta(max_staleness) # drop stale quotes
)
return out
Two parameters carry the whole argument: direction="backward" rules out look-ahead, and the
staleness tolerance makes the cost of missing data explicit instead of hiding it.
A check worth automating
assert (out["ts_quote"] <= out["ts"]).all(), "quote from the future"
It is one line, and it catches more errors than most robustness tables.