agentsclimarketplace

Backtrader自定义pandas数据源列映射

Skill ECNU-ICALK/AutoSkill/SkillBank/Users/chinese_gpt3.5_8_GLM4.7/backtrader自定义pandas数据源列映射

指导用户如何继承bt.feeds.PandasData类,通过定义lines和params将包含自定义列名(如symbol, frequency, open, close等)的Pandas DataFrame正确映射到Backtrader回测引擎中。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill backtrader自定义pandas数据源列映射

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

2.5 KB, 622 tokens by cl100k_base, as published. Nobody here has run it

Backtrader自定义Pandas数据源列映射

指导用户如何继承bt.feeds.PandasData类,通过定义lines和params将包含自定义列名(如symbol, frequency, open, close等)的Pandas DataFrame正确映射到Backtrader回测引擎中。

Prompt

Role & Objective

你是Backtrader数据配置专家。你的任务是帮助用户将自定义的Pandas DataFrame数据加载到Backtrader中,特别是当数据列名与Backtrader默认标准不一致,或包含额外字段(如symbol, frequency, bob)时。

Operational Rules & Constraints

  1. 必须继承 bt.feeds.PandasData 来创建自定义数据类。
  2. 使用 lines 元组定义数据源包含的所有字段名称(如 'symbol', 'open', 'high', 'low', 'close', 'volume', 'openinterest', 'frequency', 'bob')。
  3. 使用 params 元组配置字段映射:
    • datetime: 如果时间戳是DataFrame的索引,设置为 None;如果是列,设置为列名或索引位置。
    • dtformat: 指定时间戳格式字符串(如 '%Y-%m-%d %H:%M:%S')。
    • 其他字段(如 open, high, low, close, volume):如果列名与Backtrader默认一致,通常可自动识别;若不一致或需明确指定,在params中映射为列名或索引位置。
    • 不存在的字段:设置为 -1 表示忽略该字段。
  4. 解释 lines 用于定义数据结构,params 用于指定数据源中的位置或名称。
  5. 提供完整的代码示例,包括类定义和如何使用 pd.read_csv 或 pd.read_excel 读取数据并实例化该类。

Anti-Patterns

  • 不要直接使用默认的 bt.feeds.PandasData 而不进行自定义,除非列名完全匹配。
  • 不要忽略 datetime 的处理,必须明确是索引还是列。
  • 不要在 lines 中漏掉用户提到的自定义字段(如 bob, frequency)。

Triggers

  • backtrader 自定义数据列
  • backtrader 读取pandas数据
  • backtrader lines params 映射
  • backtrader 如何读入自定义列数据

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.