Skip to content

Close Reading of 3.2: One K-Line Becomes Five Numbers ​

This is the most "K-line-specific" section of the entire paper. After working through it, you will be able to write out formula (3), state what problem each of the three properties solves, and use the ablation numbers to explain how much this design is worth.

Start with the Problem: Why Raw OHLCV Doesn't Work ​

The first paragraph of the paper says three things:

  1. Absolute prices across different instruments differ by three orders of magnitude (from a few yuan to several thousand)
  2. Volatility levels differ across timeframes
  3. Volume units vary by market (shares, lots, coins)

The most crucial part is the third sentence: even if every instrument is standardized to zero mean, the problem is not solved. Two stocks can have the same standardized opening price, yet their "ratio of wicks to price" may be completely different. In other words, the shape information of a K-line is hidden in the "absolute values," and subtracting the mean and dividing by the variance cannot dig it out.

Formula (3) ​

Each K-line t becomes a five-dimensional vector:

ComponentFormulaMeaning
r_gapln(O_t / C_{t−1})Gap: today's open relative to yesterday's close
r_bodyln(C_t / O_t)Body: close relative to open
r_upln(H_t / max(O_t, C_t))Upper wick: high relative to the upper edge of the body
r_dnln(min(O_t, C_t) / L_t)Lower wick: lower edge of the body relative to the low
v_tln((V_t + 1) / (E_t + 1))Volume: volume relative to its exponential moving average

E_t is a "strictly causal" volume moving average: it only uses volumes before t, never peeking at the current bar. In the code it is compute_volume_ema, and the moving average for bar 0 is just its own volume, so v_0 = 0.

In Chapter 1 you already worked with this:

Drag it yourselfOne candlestick, turned into five numbers
Previous close
r_gapGapToday's open vs. yesterday's close+2.0%
r_bodyBodyClose vs. open+3.8%
r_upUpper shadowHigh vs. top of the body+2.8%
r_dnLower shadowBody bottom is lower than the low+2.0%
vVolumeVolume relative to its recent average+40.5%

All five numbers are logarithms of "ratios". Upper and lower shadows are always ≥ 0, so the generated candlesticks will never have a high lower than the close.

Three Properties, Each Solving One Problem ​

(i) Invertible. Given the previous close C_{t−1}, the five numbers can exactly reconstruct O, H, L, C, V using a chain of exponentials:

  • O = C_{t−1} · exp(r_gap),C = O · exp(r_body)
  • H = max(O, C) · exp(r_up),L = min(O, C) · exp(−r_dn)

No information is lost. This is the fundamental difference from papers like Kronos that "quantize into discrete tokens," and it is what "no tokenizer needed" means in the contributions. Code: invert_features.

(ii) Scale-invariant. Each component is the logarithm of a ratio of two quantities of the same kind. Multiply all prices by any number, or all volumes by any number, and the five numbers stay unchanged. That's why a stock priced at 5 and one at 2000, or A-shares and Bitcoin, can go into the same model.

(iii) Structurally valid. By definition, r_up and r_dn are ≥ 0. During generation, they are clipped to ≥ 0, so the reconstructed K-line is guaranteed to satisfy H ≥ max(O, C) and L ≤ min(O, C). No weird K-lines where the high is below the close will appear.

Normalization: MAD plus tanh ​

The last paragraph is just one sentence, but it's important: each component is scaled per (market, timeframe, feature) using robust statistics, then softly clipped with tanh, "stabilizing training while not discarding outliers."

To elaborate (code kit_v1/data/normalize.py):

  • Scale s = 1.4826 × MAD. MAD is the median of the absolute deviations from the median; multiplying by 1.4826 makes it consistent with the standard deviation under a normal distribution. Using MAD instead of the standard deviation is because extreme values like limit-ups and flash crashes inflate the standard deviation, while MAD is unaffected.
  • y = 6 · tanh(x / s / 6): |x/s| is left almost unchanged when small, while extremely large values are smoothly compressed to within ±6.
  • The statistics are computed only on the training period (Section 4.1 of the paper stresses "no leakage") and stored in stats.json.

Evidence: Appendix E Table 9 ​

Changing only the input representation with everything else held fixed, the return RankIC averaged over seven timeframes:

Representation per K-lineAverage return RankIC
Five-dimensional log ratios (KiT)0.0571
Standardized raw OHLCV0.0209
Log of close price only0.0183

How to read this table: switching back to raw OHLCV (even with robust normalization), RankIC drops to less than forty percent of the original; and even discarding open, high, low, and volume, keeping only the close price, it drops a bit further. The paper's explanation: raw values lose the layer of "relative shape" information in K-lines.

This is the largest gap attributable to a single design in the entire paper.

Quiz timeWhy can't ”standardizing each stock to zero mean and unit variance” replace the five-dimensional log-ratio?

Check Yourself ​

  • I can write out the formulas for the five components
  • I can state what invertibility, scale invariance, and structural validity each solve
  • I can use the numbers in Table 9 to explain the value of this representation

Next section: Close Reading of 3.3–3.4: Architecture and Conditioning.

gaodong.aiAboutPrivacyContact

Independent tutorials, not affiliated with any product mentioned. Product names and trademarks belong to their owners. Check official pages for prices and policies.