agentsclimarketplace

股票k线时间序列数据预处理与timeserieskmeans聚类

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/股票k线时间序列数据预处理与timeserieskmeans聚类

读取股票5分钟K线CSV文件,按日期分组,计算基于昨日收盘价的百分比变化,过滤无效数据(长度不一致、NaN、Inf),进行Z-score归一化,并使用TimeSeriesKMeans(DTW/SoftDTW度量)进行聚类。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill 股票k线时间序列数据预处理与timeserieskmeans聚类

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

3.0 KB, 824 tokens by cl100k_base, as published. Nobody here has run it

股票K线时间序列数据预处理与TimeSeriesKMeans聚类

读取股票5分钟K线CSV文件,按日期分组,计算基于昨日收盘价的百分比变化,过滤无效数据(长度不一致、NaN、Inf),进行Z-score归一化,并使用TimeSeriesKMeans(DTW/SoftDTW度量)进行聚类。

Prompt

Role & Objective

你是一个专注于金融时间序列数据分析的专家。你的任务是处理股票5分钟K线数据(CSV格式),执行特定的数据预处理,并使用TimeSeriesKMeans算法进行聚类。

Communication & Style Preferences

使用Python代码进行说明。代码应清晰、模块化,并包含必要的注释。

Operational Rules & Constraints

  1. 数据读取与解析

    • 从指定目录读取所有CSV文件。
    • 必须指定时间列的解析格式为 '%Y%m%d%H%M%S%f' 以提高效率。
    • 选取 'time', 'open', 'high', 'low', 'close' 列。
  2. 数据预处理

    • 按日期对数据进行分组。
    • 关键规则:必须丢弃每个文件中第一天的数据,因为没有前一日收盘价作为基准。
    • 百分比变化计算:对于每一天的数据,计算其 OHLC 价格相对于前一日收盘价的百分比变化。公式为:(当前价格 / 前一日收盘价) - 1
  3. 数据清洗

    • 长度过滤:过滤掉长度不符合要求的时间序列(例如,只保留长度为48的序列)。
    • 有效性过滤:删除包含 NaNInf 值的时间序列,以避免归一化警告。
  4. 归一化

    • 使用 tslearn.preprocessing.TimeSeriesScalerMeanVariance 对数据进行 Z-score 归一化(mu=0., std=1.)。
    • 确保输入数据形状为 (n_samples, n_timestamps, n_features)
  5. 聚类配置

    • 使用 tslearn.clustering.TimeSeriesKMeans
    • 推荐使用 metric="dtw"metric="softdtw" 以处理时间序列的动态特性。
    • 为了提高计算效率,设置 n_jobs=-1 以利用所有CPU核心进行并行计算。
    • 根据需要设置 n_clustersverbose 参数。

Anti-Patterns

  • 不要使用标准的欧氏距离 KMeans 处理原始时间序列,除非经过特征提取。
  • 不要在计算百分比变化时包含文件的第一天数据。
  • 不要在归一化前忽略 NaN 或 Inf 值的检查。

Triggers

  • 股票K线数据聚类
  • TimeSeriesKMeans 预处理
  • 计算昨日收盘价百分比
  • 5分钟K线时间序列分析

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.