vnpy
vn.py 开源量化交易框架 - 支持CTA、价差、期权策略,20+券商接口,覆盖国内外市场。
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/coderwpf/vnpyvn.py(开源量化交易框架)
vn.py is the most popular open-source quantitative trading framework in China, community-driven. Supports CTA strategies, spread trading, options volatility trading, and more. Connects to CTP, Femas, Hundsun, and 20+ broker gateways.
Docs: https://www.vnpy.com/docs/cn/ GitHub: https://github.com/vnpy/vnpy
安装
# Install core framework
pip install vnpy
# Install CTP gateway (futures)
pip install vnpy-ctp
# Install common components
pip install vnpy-ctastrategy # CTA strategy module
pip install vnpy-spreadtrading # Spread trading module
pip install vnpy-datamanager # Data management module
pip install vnpy-sqlite # SQLite database
pip install vnpy-rqdata # RQData data service
架构概述
VeighNa Trader (GUI)
├── Gateway (Broker Interface)
│ ├── CTP (Futures)
│ ├── Femas (Futures)
│ ├── Hundsun UFT (Securities)
│ ├── EMT (Securities)
│ └── IB / Alpaca (International)
├── App (Application Modules)
│ ├── CtaStrategy (CTA Strategy)
│ ├── SpreadTrading (Spread Trading)
│ ├── OptionMaster (Options Trading)
│ ├── PortfolioStrategy (Portfolio Strategy)
│ └── AlgoTrading (Algorithmic Trading)
└── DataService
├── RQData
├── TuShare
└── Custom Data Sources
启动GUI
from vnpy.event import EventEngine
from vnpy.trader.engine import MainEngine
from vnpy.trader.ui import MainWindow, create_qapp
# Import broker gateways
from vnpy_ctp import CtpGateway
# Import application modules
from vnpy_ctastrategy import CtaStrategyApp
from vnpy_spreadtrading import SpreadTradingApp
from vnpy_datamanager import DataManagerApp
# Create application
qapp = create_qapp()
event_engine = EventEngine()
main_engine = MainEngine(event_engine)
# Add broker gateways
main_engine.add_gateway(CtpGateway)
# Add application modules
main_engine.add_app(CtaStrategyApp)
main_engine.add_app(SpreadTradingApp)
main_engine.add_app(DataManagerApp)
# Create and show main window
main_window = MainWindow(main_engine, event_engine)
main_window.showMaximized()
qapp.exec()
CTA策略开发
CTA (Commodity Trading Advisor) strategies are the core strategy type in vn.py, suitable for trend following, mean reversion, etc.
策略模板
from vnpy_ctastrategy import (
CtaTemplate,
StopOrder,
TickData,
BarData,
TradeData,
OrderData,
BarGenerator,
ArrayManager,
)
class DoubleMaStrategy(CtaTemplate):
"""Dual Moving Average CTA Strategy"""
author = "Quant Developer"
# Strategy parameters (editable in GUI)
fast_window = 10 # 快速均线周期
slow_window = 20 # 慢速均线周期
fixed_size = 1 # 每次交易手数
# Strategy variables (displayed in GUI)
fast_ma0 = 0.0
slow_ma0 = 0.0
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-coderwpf-vnpy": {
"enabled": true,
"auto_update": true
}
}
}Related Skills
backtrader
Backtrader 开源量化回测框架 - 支持多数据源、多策略、多周期回测与实盘交易,纯Python实现。
pywencai
同花顺问财自然语言数据查询工具 - 使用中文自然语言查询A股、指数、基金、港美股、可转债等市场数据。
tqsdk
天勤量化TqSdk - 开源Python期货/期权交易SDK,提供实时行情、回测和实盘交易功能。
rqalpha
RQAlpha 米筐开源事件驱动回测框架 - 支持A股和期货,模块化架构,可自由扩展。
baostock
BaoStock 免费A股数据平台 - 支持K线、财务数据、行业分类查询,无需注册即可使用。