Quant Trading Bot Devlog

한국어로 보기

Intraday Trade Filter Fixed to Use the Regular-Session Close - A Portal's Daily-Bar Close Definition Had Changed

The intraday filter I added to the live account yesterday was judging spikes and drops against a wrong reference (the prior-day close). A portal's daily-bar "close" had started including after-hours trades, so I recut it to use the broker API's regular-session close as v1.1. The same day, a regression run accidentally fired six real notifications.

This is the English version of a post originally written in Korean for my algorithmic trading system devlog(new tab).

A reference-value defect that surfaced one day later

Yesterday I wrote about adding an intraday trade filter(new tab) to the live account.

It's a simple guard: if a stock I meant to buy spikes intraday, it delays the buy; if one I meant to sell drops sharply, it delays the sell.

But to decide "spiked" or "dropped," you need a baseline. You have to measure how far the current price has moved against the prior-day close.

This morning I found that the prior-day close I'd been using as that baseline was itself wrong.

There were two closing prices

The root cause was in the data source. The filter reads a prior-day close from the market data(new tab) feed, and that value differed subtly from the exchange's regular-session close.

Tracing it, a portal's daily-bar "close" definition had, at some point, started including after-hours trading (such as the post-market single-price session).

So there were effectively two closes — "the price when the regular session ended" and "the price after after-hours was folded in." The filter was treating the latter as the prior-day close.

It looks like a tiny gap, but near the threshold where a spike or drop gets judged, that one difference can flip a hold into a trade or vice versa.

Recut to the regular-session close as v1.1

So I built and deployed v1.1, which swaps the baseline to the regular-session close provided by the broker API.

The first version I shipped yesterday (v1.0) ran on a contaminated baseline, so it has no standing to answer "did it work." I closed it out as undecided.

Instead I pre-registered the corrected v1.1 under a validation window of roughly two months. The rule and thresholds are written down in advance, and I won't change the rule based on results before the window closes.

One check is still open. Whether the "prior-day close" the API returns early in the session really equals the previous day's regular-session close has to be confirmed by cross-checking the next trading day's first-round record.

A regression run that fired six real notifications

In the afternoon there was an incident of a different kind.

I ran the full regression suite to verify a batch of review fixes, and in the middle of it six real notification messages went out.

Tests are supposed to run with every touchpoint to the "real outside world" — outbound sends, live quote lookups — swapped out for fakes (mocked).

But one notification path, and the path the newly added filter uses to look up its baseline, weren't caught by that blocking net. The test performed real sends and real quote lookups.

Luckily the messages that went out were internal notifications, so there was no external harm — but "a test can cause real side effects" is dangerous in itself.

So I globally blocked notification sending and baseline lookups in the test environment at the source, then reran the offending regression suite and confirmed it passed.

Side notes — an operational review and a false alarm cleanup

In the evening I handed the question of whether to keep running this filter to an external AI for an operational review.

I'd been nursing the hope that this filter could let the system steadily beat the index, but the review's conclusion was to dial that expectation back considerably.

The filter is only a small lever that trims leakage from trading costs; the far bigger lever is "trading less in the first place" (cutting turnover). That said, any change that large gets touched only after the other validation currently in flight finishes, and only through the formal process.

Separately, the daily summary report had been showing filter holds and intraday executions against plan figures rather than the actual ledger, raising a "the numbers don't add up" false alarm — I switched that to the ledger basis.

I also checked some resident processes (the simulator and the live monitor) that had stayed down after a reboot, and brought them back up.

Why it matters

The two incidents today look different in texture, but the lesson is the same: even when the judgment logic is sound, if the input it consumes and the environment around it are wrong, the output is wrong.

The filter's idea was identical to yesterday's. But the "prior-day close" it compares against was contaminated, so for a full day a perfectly good rule was running on top of bad data.

Tests were the same story. The test code itself was correct, but because the touchpoints to the outside world weren't fully sealed, "verification" leaked into "real action."

So lately I spend as much time doubting "is the data this logic sees really the data I think it is" and "is this test actually isolated" as I spend fixing the logic itself.

#quant #trading bot #devlog #data quality #test isolation #operations