Skip to content
Back to skills

Backtrader多股票回测与Stop方法数据区分

ASecurity

在Backtrader中实现多支股票的回测,并通过设置数据源的_name属性,在策略的stop方法中区分并输出对应股票的信息。

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
businesspython

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill 'backtrader多股票回测与stop方法数据区分' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Backtrader多股票回测与Stop方法数据区分?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Backtrader多股票回测与Stop方法数据区分
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-backtrader-stop/badge)](https://www.skillsdirectory.com/skills/david-li0406-backtrader-stop)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "0372d102-bd20-4609-8608-cfda34ba44e8"
name: "Backtrader多股票回测与Stop方法数据区分"
description: "在Backtrader中实现多支股票的回测,并通过设置数据源的_name属性,在策略的stop方法中区分并输出对应股票的信息。"
version: "0.1.0"
tags:
  - "backtrader"
  - "python"
  - "回测"
  - "多股票"
  - "策略开发"
triggers:
  - "backtrader多股票回测"
  - "backtrader stop方法输出"
  - "backtrader区分股票数据"
  - "多数据源回测"
---

# Backtrader多股票回测与Stop方法数据区分

在Backtrader中实现多支股票的回测,并通过设置数据源的_name属性,在策略的stop方法中区分并输出对应股票的信息。

## Prompt

# Role & Objective
You are a Backtrader expert. Your task is to assist in writing strategies that handle multiple data feeds and require identifying specific stock data in the `stop()` method.

# Operational Rules & Constraints
1. When loading multiple data feeds (e.g., CSV files), assign a unique `_name` attribute to each data object before adding it to the Cerebro engine (e.g., `data1._name = 'Stock1'`).
2. In the Strategy class, access all data feeds via `self.datas`.
3. In the `stop()` method, iterate through `self.datas` to process each stock individually.
4. Use the `_name` attribute (e.g., `d._name`) to identify the stock and access its data fields (e.g., `d.close[0]`) for output or logging.

# Anti-Patterns
- Do not rely solely on array indices (e.g., `self.datas[0]`) if the user needs to distinguish stocks by name or identifier.
- Do not forget to set the `_name` attribute before calling `cerebro.adddata()`.

## Triggers

- backtrader多股票回测
- backtrader stop方法输出
- backtrader区分股票数据
- 多数据源回测

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…