vnpy-export
できること
このスキルは、テスト済みの戦略を、vnpyの取引フレームワークが読み込めるファイルに変換します。vnpyを使う開発者やクオンツのトレーダー向けです。
使う場面
- ✓バックテストした戦略を、vnpyのCTAバックテスターの中で動かしたいとき。
- ✓戦略をvnpyでの実際の取引に近づけたいとき。
- ✓説明した取引のアイデアを、vnpyのCtaTemplateクラスとして書いてほしいとき。
スキルのリンク
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/vnpy-export/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私の移動平均の戦略を、CTAのアプリに読み込めるvnpyのクラスとしてエクスポートしてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
このスキルは、戦略の設定とシグナルのロジックを読み、それをvnpyのテンプレートクラスに書き直します。株式、先物、暗号資産のそれぞれに適した規約を選び、読み込める準備ができたPythonファイルを保存します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Overview
This skill translates a Vibe-Trading strategy into a vnpy CtaTemplate subclass .py file
that can be loaded directly into the vnpy CTA Strategy App for live trading or vnpy backtesting.
Output file: artifacts/vnpy_strategy/<StrategyName>Strategy.py (inside the run directory).
vnpy is the most widely-used open-source quant framework in mainland China (39k+ GitHub stars).
Use this skill when the user asks to export to vnpy, requests a /vnpy command, or wants to
run a Vibe-Trading strategy inside vnpy's CTA backtester or live trading engine.
Workflow: Export from Backtest Run
load_skill("vnpy-export")— read this guideread_file("config.json")— extract instrument, dates, parameters, intervalread_file("code/signal_engine.py")— understand the Python signal logic- Determine asset class from
config.json→ choose correct CtaTemplate convention (see below) - Translate signal logic to CtaTemplate using the reference tables
write_file("artifacts/vnpy_strategy/<StrategyName>Strategy.py")— save the output- Return the class in a code block with setup instructions
Workflow: Generate from Description
load_skill("vnpy-export")— read this guide- Write a CtaTemplate class from the user's strategy description
write_file("artifacts/vnpy_strategy/<StrategyName>Strategy.py")— save the output- Return the class with setup and usage instructions
Asset Class Conventions
vnpy uses the same CtaTemplate base class for all asset types, but parameter conventions differ:
| Asset Class | Instrument Example | vt_symbol Format |
Position Unit |
|---|---|---|---|
| A-share stock | Ping An Bank | 000001.SZSE |
shares (整手, min 100) |
| Futures | IF2406 | IF2406.CFFEX |
lots |
| Crypto | BTC/USDT | BTC/USDT.BINANCE |
coin units |
For stocks: use buy / sell only (no short selling unless margin account).
For futures / crypto: use all four directions — buy, sell, short, cover.
CtaTemplate Structure
Every strategy must subclass CtaTemplate and implement these methods:
| Method | Purpose |
|---|---|
__init__ |
Declare parameters, variables, BarGenerator, ArrayManager |
on_init |
Called once at startup; call load_bar(n) to warm up indicators |
on_start |
Called when strategy is started by user |
on_stop |
Called when strategy is stopped |
on_tick |
Receives live tick data; forward to BarGenerator |
on_bar |
Main logic — called once per bar by BarGenerator |
on_order |
Order status updates |
on_trade |
Fill notifications |
on_stop_order |
Stop-order status (if using stop orders) |
Always call self.cancel_all() at the start of on_bar to avoid stale orders.
Always call self.put_event() at the end of on_bar to refresh the UI.
Full Template
See scripts/cta_template.py for a complete, runnable example (MA crossover).
The template below is the canonical skeleton — replace the # SIGNAL LOGIC section:
from vnpy_ctastrategy import (
CtaTemplate,
StopOrder,
TickData,
BarData,
TradeData,
OrderData,
BarGenerator,
ArrayManager,
)
class {{StrategyName}}Strategy(CtaTemplate):
"""
Vibe-Trading export — {{StrategyName}}
Generated from run: {{run_id}}
Instrument: {{vt_symbol}}
"""
author = "Vibe-Trading"
# ── Parameters (editable in vnpy UI) ──────────────────────────────────
{{param_name}} = {{param_default}} # add one line per parameter
parameters = [{{param_list_as_strings}}]
# ── Variables (displayed in vnpy UI, reset on strategy restart) ────────
{{var_name}} = 0.0 # add one line per runtime variable
variables = [{{var_list_as_strings}}]
def __init__(self, cta_engine, strategy_name, vt_symbol, setting):
super().__init__(cta_engine, strategy_name, vt_symbol, setting)
self.bg = BarGenerator(self.on_bar)
self.am = ArrayManager()
# initialise variable attributes to match class-level defaults
# (vnpy requires instance attributes for variables declared above)
def on_init(self):
self.write_log("Strategy initialised")
self.load_bar({{warmup_bars}}) # load enough bars to warm up all indicators
def on_start(self):
self.write_log("Strategy started")
self.put_event()
def on_stop(self):
self.write_log("Strategy st
よくある質問
vnpyとは何ですか?
中国本土で広く使われているオープンソースのクオンツ取引フレームワークです。
Pythonを知っている必要がありますか?
少しPythonの知識があると役立ちます。出力はvnpyに読み込むPythonのクラスだからです。
どの資産の種類に対応していますか?
A株の株式、先物、暗号資産に対応しており、それぞれ異なる規約があります。
詳細
作者による元の説明
Export a Vibe-Trading backtest strategy to a runnable vnpy CtaTemplate Python class — supports A-share equities, futures, and crypto via BarGenerator + ArrayManager.
repo: HKUDS/Vibe-Trading
人気
- GitHubのスター
- 37k
- ランキング
- #7565
- ライセンス
- MIT
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
vibe-trading
37kバックテスト、ファクター分析、オプション価格、多くの市場にまたがる市場データを含む、金融リサーチの完全なツールキットをエージェントに与えます。
adr-hshare
37k中国企業が複数の市場に上場している価格差、例えば米国のADRと香港株の差を比べる方法をエージェントに示します。
akshare
37kエージェントが、APIキーなしで、中国と世界の株式、先物、外国為替、経済指標の無料の市場データを取得できるよう支援します。
alpha-zoo
37k既製のストックファクターのライブラリを閲覧し、選んだ市場で一群のファクターがリターンをどれだけ予測するかを検証できるよう支援します。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。