TopRank Skills

Home / Claw Skills / Git / GitHub / backtrader
Official OpenClaw rules 36%

backtrader

Backtrader open-source quantitative backtesting framework — supports multiple data sources, strategies, and timeframes for backtesting and live trading, implemented in pure Python.

Stars

0

Installs

0

Status

ACTIVE

Visibility

PUBLIC

安装方式

直接复制以下提示词,发送给你的 AI 助手即可完成安装。

请先检查是否已安装 SkillHub 商店,若未安装,请根据 https://skillhub-1388575217.cos.ap-guangzhou.myqcloud.com/install/skillhub.md 安装 SkillHub 商店,然后安装 backtrader 技能。 若已安装,则直接安装 backtrader 技能。

Overview

Skill Key
coderwpf/backtrader
Author
coderwpf
Source Repo
openclaw/skills
Version
1.0.0
Source Path
skills/coderwpf/backtrader
Latest Commit SHA
ff9daad049e33ad102e9c32bd90c9a6a26859c1c

Extracted Content

SKILL.md excerpt

# Backtrader (Open-Source Quantitative Backtesting Framework)

[Backtrader](https://github.com/mementum/backtrader) is a powerful open-source Python quantitative backtesting framework that supports multiple data sources, strategies, and timeframes for backtesting and live trading. Implemented in pure Python with no external dependencies, it features a clean and extensible architecture.

> Documentation: https://www.backtrader.com/docu/

## Installation

```bash
pip install backtrader
# If plotting is needed
pip install backtrader[plotting]
# Or
pip install matplotlib
```

## Core Concepts

Backtrader uses an object-oriented, event-driven architecture:

- **Cerebro**: The strategy engine, responsible for coordinating data, strategies, and the broker
- **Strategy**: The strategy class where trading logic is written
- **Data Feed**: Data sources, supporting CSV, Pandas, and online data
- **Broker**: Broker simulation, managing funds and orders
- **Indicator**: Technical indicators, with 100+ built-in common indicators
- **Analyzer**: Analyzers for calculating strategy performance metrics
- **Observer**: Observers that record strategy runtime status

## Minimal Example

```python
import backtrader as bt

class MyStrategy(bt.Strategy):
    """Simple moving average strategy"""
    params = (('period', 20),)  # Strategy parameter: MA period

    def __init__(self):
        # Initialize indicators (defined in __init__, calculated automatically)
        self.sma = bt.indicators.SimpleMovingAverage(self.data.close, period=self.params.period)

    def next(self):
        # Triggered once per bar, write trading logic here
        if self.data.close[0] > self.sma[0]:
            if not self.position:  # Buy if no position
                self.buy()
        elif self.data.close[0] < self.sma[0]:
            if self.position:      # Sell if holding position
                self.sell()

# Create engine
cerebro = bt.Cerebro()
cerebro.addstrategy(MyStrategy)

# Load data (Yahoo CSV f...

README excerpt

# Backtrader 回测框架 Skill

[![Version](https://img.shields.io/badge/version-1.0.0-blue.svg)](https://github.com/mementum/backtrader)
[![License](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE)
[![ClawHub](https://img.shields.io/badge/ClawHub-BossQuant-purple.svg)](https://clawhub.com)

开源量化回测框架,支持多数据源、多策略、多周期回测与实盘。

## ✨ 特性

- 🐍 **纯 Python 实现** - 无需外部依赖,易于扩展
- ⚡ **事件驱动架构** - 逐 Bar 回测,贴近真实交易
- 📊 **100+ 内置指标** - SMA、EMA、MACD、RSI、布林带等
- 🔧 **参数优化** - 内置网格搜索参数优化
- 📈 **多股票支持** - 同时回测多只股票组合

## 📥 安装

```bash
pip install backtrader[plotting]
```

## 🚀 快速开始

```python
import backtrader as bt

class MyStrategy(bt.Strategy):
    params = (('sma_period', 20),)

    def __init__(self):
        self.sma = bt.indicators.SMA(self.data.close, period=self.params.sma_period)

    def next(self):
        if self.data.close[0] > self.sma[0] and not self.position:
            self.buy()
        elif self.data.close[0] < self.sma[0] and self.position:
            self.sell()

# 创建引擎
cerebro = bt.Cerebro()
cerebro.addstrategy(MyStrategy)

# 加载数据
data = bt.feeds.PandasData(dataname=df)
cerebro.adddata(data)

# 设置初始资金
cerebro.broker.setcash(100000)

# 运行回测
results = cerebro.run()
cerebro.plot()
```

## 📊 核心组件

| 组件 | 说明 | 示例 |
|------|------|------|
| Cerebro | 回测引擎 | `bt.Cerebro()` |
| Strategy | 策略基类 | `class MyStrategy(bt.Strategy)` |
| Data Feed | 数据源 | `bt.feeds.PandasData()` |
| Indicator | 技术指标 | `bt.indicators.SMA()` |
| Analyzer | 分析器 | `bt.analyzers.SharpeRatio` |
| Observer | 观察器 | `bt.observers.DrawDown` |
| Broker | 模拟经纪商 | `cerebro.broker.setcash()` |

## 📖 常用指标

```python
# 均线
sma = bt.indicators.SMA(self.data.close, period=20)
ema = bt.indicators.EMA(self.data.close, period=12)

# MACD
macd = bt.indicators.MACD(self.data.close)

# RSI
rsi = bt.indicators.RSI(self.data.close, pe...

Related Claw Skills

heyixuan2

bambu-studio-ai

★ 41

Bambu Lab 3D printer control and automation. Activate when user mentions: printer status, 3D printing, slice, analyze model, generate 3D, AMS filament, print monitor, Bambu Lab, or any 3D printing task. Full pipeline: search → generate → analyze → colorize → preview → open BS → user slice → print → monitor. Supports all 9 Bambu Lab printers (A1 Mini, A1, P1S, P2S, X1C, X1E, H2C, H2S, H2D).

capt-marbles

geo-optimization

★ 1

Generative Engine Optimization (GEO) for AI search visibility. Optimize content to appear in ChatGPT, Perplexity, Claude, and Google AI Overviews. Use when optimizing websites, pages, or content for LLM discoverability and citation.

carlzhao007

feishu-process-feedback

★ 0

飞书消息自动处理与进度反馈技能。安装后后台运行,监听飞书任务消息并自动创建独立进程处理。 在处理前后发送实时进度反馈(任务确认、进度百分比、完成通知)。 支持任务类型识别、智能解析、错误重试、并发控制、状态持久化。 使用场景:飞书自动化工作流、任务进度追踪、批量任务处理、需要实时反馈的场景。

carlulsoe

parakeet-stt

★ 0

Local speech-to-text with NVIDIA Parakeet TDT 0.6B v3 (ONNX on CPU). 30x faster than Whisper, 25 languages, auto-detection, OpenAI-compatible API. Use when transcribing audio files, converting speech to text, or processing voice recordings locally without cloud APIs.

caoyumin97

structure-thinking

★ 0

Structured problem analysis and communication using system mapping and hierarchical logic. Use when a request involves messy, multi-factor problems, root-cause analysis, intervention design, feedback loops or delays, or when a clear top-line recommendation with logically grouped support is required.

cartoonitunes

bottyfans

★ 0

BottyFans agent skill for autonomous creator monetization. Lets AI agents register, build a profile, publish posts (public, subscriber-only, or pay-to-unlock), upload media, accept USDC subscriptions and tips on Base, send and receive DMs, track earnings, and appear on the creator leaderboard. Use this skill when an agent needs to monetize content, interact with fans, manage a creator profile, handle payments in USDC, or operate as an autonomous creator on the BottyFans platform.