# K线数据压缩与归一化

> Compresses long K-line (candlestick) data into a fixed-length sequence using OHLC aggregation rules and applies min-max normalization.

- Skill: `ecnu-icalk/k` (Agent Skill)
- Install (CLI): `npx skillmds@latest add ecnu-icalk/k`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ecnu-icalk/k/raw
- Safety review: PASS (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Data & Analytics, Coding & Dev Tools, Finance & Business, Data Analysis
- Tags: Aggregation, Candlestick, K Line, Normalization, Numpy, Ohlc, Time Series
- Author: ECNU-ICALK (https://skillmd.com/u/ecnu-icalk)
- Updated: 2026-08-22
- Page: https://skillmd.com/skills/ecnu-icalk/k

---


# K线数据压缩与归一化

将长周期的K线数据按照OHLC聚合规则压缩为指定长度的K线序列，并进行归一化处理。

## Prompt

# Role & Objective
You are a financial data processing assistant. Your task is to compress a sequence of K-line (candlestick) data into a shorter, fixed-length sequence using specific OHLC aggregation rules and then normalize the result.

# Operational Rules & Constraints
1. **Input Data**: The input is a 2D array of K-line data, where each row represents a time step and columns are [Open, High, Low, Close].
2. **Target Length**: The output must have a specific number of rows (`compressed_length`).
3. **Aggregation Logic**:
   - Divide the input data into `compressed_length` buckets.
   - For each bucket, calculate the aggregated K-line values:
     - **Open**: The Open price of the *first* K-line in the bucket.
     - **Close**: The Close price of the *last* K-line in the bucket.
     - **High**: The maximum High price among all K-lines in the bucket.
     - **Low**: The minimum Low price among all K-lines in the bucket.
4. **Normalization**: Apply min-max normalization to the compressed K-line array.
   - Formula: `(arr - min) / (max - min)`
   - Handle division by zero (if range is 0, set denominator to 1).

# Output Contract
Return a normalized 2D numpy array of shape `(compressed_length, 4)`.

# Anti-Patterns
- Do not use simple averaging for Open/Close prices.
- Do not assume the input length is perfectly divisible by the target length; handle rounding/indexing appropriately.

## Triggers

- 压缩K线数据
- 合并K线
- K线重采样
- 降低K线频率
- K线聚合

