bambu-studio-ai
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 pi...
Backtrader open-source quantitative backtesting framework — supports multiple data sources, strategies, and timeframes for backtesting and live trading, implemented in pure Python.
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
SkillHub CLI
skillhub install coderwpf/backtrader打开来源仓库,查看说明和兼容环境后,按来源提供的命令或步骤安装。
将来源链接提供给你的 Agent,让它先读取说明、核对依赖,并向你说明将执行的安装步骤。
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/
pip install backtrader
# If plotting is needed
pip install backtrader[plotting]
# Or
pip install matplotlib
Backtrader uses an object-oriented, event-driven architecture:
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...
这些信息来自收录时的来源分析,可能滞后;使用前请核对最新来源文件。
开源量化回测框架,支持多数据源、多策略、多周期回测与实盘。
pip install backtrader[plotting]
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() |
# 均线
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...
# 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...# Backtrader 回测框架 Skill
[](https://github.com/mementum/backtrader)
[](LICENSE)
[](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...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 pi...
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 discove...
Agents can sign plugins, rotate credentials without losing identity, and publicly attest to behavior.
Send and receive P2P messages using disposable numbers and PINs. No servers, no accounts. Use for human notifications, approval flows, and agent-to-agent communication.