Anchors and windows
After finishing this section, you will be able to pick a workable anchor for any demo stock and any granularity, and when you see an error you will know which rule was not satisfied.
An anchor is "the moment from which you look forward"
Imagine opening your market software after the close at 3 p.m. on 2026-2-9. What you can see is all the K-line bars before that moment; what you want to know is what comes after. That moment is the anchor.
--case 300733.SZ,1h,"2026-02-09 15:00" means: standing at the close of the 1-hour K-line bar at 2/9 15:00, predict forward from there.
- When only a date is given (
2026-01-05), the last bar of that day is used - When you specify down to the minute, add quotes because there is a space in the middle
Seven granularities, fixed window lengths
These are the lengths used for each granularity during model training, and they cannot be changed at inference time:
| Granularity | 1m | 5m | 15m | 30m | 1h | 2h | 1d |
|---|---|---|---|---|---|---|---|
How many history bars are read Lc | 1200 | 960 | 800 | 640 | 400 | 360 | 250 |
How many bars are predicted Lh | 120 | 96 | 64 | 40 | 20 | 20 | 20 |
In terms of time, roughly: the 1-minute line reads 5 trading days and draws half a day; the daily line reads one year and draws one month.
Look it upI want to predict…
Click one to see.
Three requirements the anchor must satisfy
1. There must be enough history before the anchor. The daily line needs 250 bars, not one fewer (the script does not allow zero-padding). If insufficient, you will get:
300368.SZ 1d anchor 2016-09-01 23:59:59 has only 24 bars before it, the model needs 250 bars of history (padding not allowed). Move the anchor later. local 300368.SZ 1d data range 2016-08-01 15:00:00 .. 2026-04-10 15:00:002. There must be enough real K-line bars after the anchor. This script is used to "check the answer", plotting the prediction together with the real trend. The demo data ends at 2026-04-10, so the latest daily anchor is around mid-March (month 3). If insufficient, you will get has only N real bars after it.
3. The future segment must contain no trading halts or missing data. The script projects the timestamps of the next 20 bars based on the trading calendar, then compares them with the real timestamps in the data. If they do not match (for example, due to a trading halt in between), you will get:
timestamps of the real following bars differ from the calendar projection (possible suspension/missing bars in the range); this window is unsuitable for prediction, choose another anchorJust pick a different anchor.
Try it
Pick one stock, keep the same anchor date, and switch among three granularities:
python eval/infer_for_pred.py --case 300368.SZ,1d,2026-02-10 --case 300368.SZ,1h,"2026-02-10 15:00" --case 300368.SZ,15m,"2026-02-10 15:00"You should see three rows of results and three charts:
[1/3] 300368.SZ 1d history 2025-02-07 15:00:00 .. 2026-02-10 15:00:00 (250 bars) predicted 2026-02-11 15:00:00 .. 2026-03-18 15:00:00 (20 bars)
[2/3] 300368.SZ 1h history 2025-09-12 10:30:00 .. 2026-02-10 15:00:00 (400 bars) predicted 2026-02-11 10:30:00 .. 2026-02-25 15:00:00 (20 bars)
[3/3] 300368.SZ 15m history 2025-12-01 09:45:00 .. 2026-02-10 15:00:00 (800 bars) predicted 2026-02-11 09:45:00 .. 2026-02-24 15:00:00 (64 bars)The daily line read one year and drew up to 3/18; the 1-hour line read 5 months; the 15-minute line read only a bit over two months. The 1-hour line's 20 bars and the 15-minute line's 64 bars both span about 5 trading days, and the Spring Festival holiday falls in between, so the dates stretch into late February (month 2): the future timestamps are projected from the trading calendar, and holidays are skipped automatically.
Quiz timeTo predict with 1-hour candles, how many 1-hour candles are needed at minimum before the anchor?
Check yourself
- I understand that the anchor is "the last bar of the history"
- I can state how many bars the daily line and the 1-hour line each read and draw
- I have seen an "insufficient history" or "trading halt mismatch" error once and switched the anchor
Next section: Path count, steps, and speed.