1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/vnpy-vnpy

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
README_ENG.md 24 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
vn.py Отправлено 31.03.2025 14:12 d300b1d

VeighNa - By Traders, For Traders, AI-Powered.

💬 Want to read this in chinese ? Go here

VeighNa is a Python-based open source quantitative trading system development framework that has grown step by step into a fully-featured quantitative trading platform with continuous contributions from the open source community. It currently has many users from domestic and international financial institutions, including hedge funds, investment banks, futures brokers, university research institutions, proprietary trading companies, etc.

:rocket: :rocket: :rocket: The VeighNa Elite Quantitative Terminal for professional traders has been officially released, providing comprehensive support for professional traders' needs in areas such as massive strategy concurrency, intelligent position rolling, algorithmic order execution, multi-account trading support, and more. For more detailed information, please scan the QR code below and follow the account, then click on the menu bar's [Community Exchange -> Elite Member Services]:

If you have any questions about using VeighNa for secondary development (strategies, modules, etc.), please check the VeighNa Project Documentation. If you can't solve it, please go to the [Questions and Help] section of the Official Community Forum for help, or share your experience in the [Experience Sharing] section!

Want to get more information about VeighNa? Please scan the QR code below to add the assistant and join the [VeighNa Community Exchange WeChat Group]:

AI-Powered

On the tenth anniversary of VeighNa's release, version 4.0 officially introduces the vnpy.alpha module targeting AI quantitative strategies, providing professional quantitative traders with an all-in-one multi-factor machine learning (ML) strategy development, research, and live trading solution:

  • :bar_chart: dataset: Factor Feature Engineering

    • Designed specifically for ML algorithm training optimization, supporting efficient batch feature calculation and processing
    • Built-in rich factor feature expression calculation engine, enabling rapid one-click generation of training data
    • Alpha 158: A collection of stock market features from Microsoft's Qlib project, covering multiple dimensions of quantitative factors including K-line patterns, price trends, and time-series volatility
  • :bulb: model: Prediction Model Training

    • Provides standardized ML model development templates, greatly simplifying model building and training processes
    • Unified API interface design, supporting seamless switching between different algorithms for performance comparison testing
    • Integrates multiple mainstream machine learning algorithms:
      • Lasso: Classic Lasso regression model, implementing feature selection through L1 regularization
      • LightGBM: Efficient gradient boosting decision tree with a training engine optimized for large-scale datasets
      • MLP: Multi-layer perceptron neural network, suitable for modeling complex non-linear relationships
  • :robot: strategy: Strategy Research and Development

    • Quickly build quantitative trading strategies based on ML signal prediction models
    • Support for both cross-sectional multi-asset and time-series single-asset strategy types
  • :microscope: lab: Research Process Management

    • Integrates complete workflow including data management, model training, signal generation, and strategy backtesting
    • Simple API design with built-in visualization analysis tools for intuitive evaluation of strategy performance and model effectiveness
  • :book: notebook: Quantitative Research Demo

    • download_data_rq: Download A-share index constituent stock data based on RQData, including index constituent tracking and historical market data retrieval
    • research_workflow_lasso: Quantitative research workflow based on Lasso regression model, demonstrating feature selection and prediction capability of linear models
    • research_workflow_lgb: Quantitative research workflow based on LightGBM gradient boosting tree, utilizing efficient ensemble learning methods for prediction
    • research_workflow_mlp: Quantitative research workflow based on multilayer perceptron neural network, demonstrating the application of deep learning in quantitative trading

The design concept of the vnpy.alpha module was inspired by the Qlib project, providing powerful AI quantitative capabilities while maintaining ease of use. We would like to express our sincere gratitude to the Qlib development team!

Functional Features

Modules marked with :arrow_up: have completed the upgrade compatibility testing for version 4.0. Additionally, the 4.0 core framework uses an upgrade approach that prioritizes compatibility, so most modules can also be used directly (interfaces involving C++ API encapsulation must be upgraded before use).

  1. :arrow_up: Multi-functional quantitative trading platform (vnpy.trader) that integrates various trading interfaces and provides simple and easy-to-use APIs for specific strategy algorithm and function development, for quickly building quantitative trading applications required by traders.

  2. Trading interfaces (vnpy.gateway) covering all domestic and international trading varieties:

    • Domestic market

      • :arrow_up: CTP (ctp): Domestic futures and options

      • CTP Mini (mini): Domestic futures, options

      • CTP Securities (sopt): ETF options

      • FEMAS (femas): Domestic futures

      • UFT (uft): Domestic futures, ETF options

      • Esunny (esunny): Domestic futures, Gold TD

      • APEX XSpeed (sec): ETF options

      • APEX HTS (hts): ETF options

      • XTP (xtp): Domestic securities (A shares), ETF options

      • TORA (tora): Domestic securities (A shares), ETF options

      • Guotai Junan (hft): Domestic securities (A shares, margin trading)

      • OST (ost): Domestic securities (A shares)

      • EMT (emt): Domestic securities (A shares)

      • SGIT (sgit): Gold TD, domestic futures

      • KsGold (ksgold): Gold TD

      • LStar (lstar): Futures asset management

      • Rohon (rohon): Futures asset management

      • Jees (jees): Futures asset management

      • ComStar (comstar): Interbank market

      • GoldMiner (gm): Domestic securities (simulation)

      • UF Cloud (uf): Domestic securities (simulation)

      • TTS (tts): Domestic futures (simulation)

    • Overseas market

      • Interactive Brokers (ib): Global securities, futures, options, forex, etc.

      • Esunny 9.0 (tap): Global futures

      • Direct Futures (da): Global futures

    • Special Applications

      • :arrow_up: RQData Market Data (rqdata): Cross-market (stocks, indices, ETFs, futures) real-time market data

      • XtQuant Market Data (xt): Cross-market (stocks, indices, convertible bonds, ETFs, futures, options) real-time market data

      • RPC service (rpc): Inter-process communication interface for distributed architecture

  3. Out-of-the-box trading applications for various quantitative strategies (vnpy.app):

    • :arrow_up: cta_strategy: CTA strategy engine module, which allows users to perform fine-grained control over the order management during the operation of CTA-type strategies while maintaining ease of use (reducing trading slippage, implementing high-frequency strategies)

    • cta_backtester: CTA strategy backtester module, no need to use Jupyter Notebook, directly use the graphical interface to carry out strategy backtesting analysis, parameter optimization and other related work

    • spread_trading: Spread trading module, supports custom spreads, real-time calculation of spread quotes and positions, supports semi-automatic spread algorithm trading and fully automatic spread strategy trading modes

    • option_master: Option trading module, designed for the domestic options market, supports various option pricing models, implied volatility surface calculation, Greek value risk tracking and other functions

    • portfolio_strategy: Portfolio strategy module, designed for trading multi-contract quantitative strategies (Alpha, option arbitrage, etc.) simultaneously, providing historical data backtesting and live automatic trading functions

    • algo_trading: Algorithm trading module, providing various commonly used intelligent trading algorithms: TWAP, Sniper, Iceberg, BestLimit, etc.

    • script_trader: Script strategy module, designed for multi-asset portfolio trading strategies and computational tasks, also can directly achieve REPL instruction trading in the command line, does not support backtesting functions

    • paper_account: Simulation trading module, pure localized implementation of simulation trading functions, based on real-time quotes obtained from the trading interface for order matching, providing order execution pushing and position records

    • chart_wizard: K-line chart module, based on RQData data service (futures) or trading interface to obtain historical data, and combined with Tick push to display real-time market changes

    • portfolio_manager: Portfolio module, for various fundamental trading strategies, based on separate strategy sub-accounts, providing automatic tracking of trading positions and real-time profit and loss statistics

    • rpc_service: RPC service module, allowing a VeighNa Trader process to be started as a server, serving as a unified routing channel for quotes and trades, allowing multiple clients to connect simultaneously, realizing a multi-process distributed system

    • data_manager: Historical data management module, view existing data in the database through a tree directory, select any time period data to view field details, supports CSV file data import and export

    • data_recorder: Market data recording module, based on the graphical interface for configuration, records Tick or K-line data to the database in real-time according to demand, for strategy backtesting or live initialization

    • excel_rtd: Excel RTD (Real Time Data) real-time data service, based on pyxll module to achieve real-time push updates of various data (quotes, contracts, positions, etc.) in Excel

    • risk_manager: Risk management module, providing statistics and restrictions on rules including trade flow control, number of orders placed, active orders, total number of cancelled orders, etc., effectively implementing front-end risk control functions

    • web_trader: Web service module, designed according to the requirements of B-S architecture, implementing a web server that provides active function calls (REST) and passive data push (WebSocket)

  4. Python trading API interface package (vnpy.api), providing the underlying implementation of the above trading interfaces:

    • REST Client (rest): High-performance REST API client based on coroutine process asynchronous IO which adopts the programming model of event message cycle to support sending high concurrent real-time transaction requests

    • Websocket Client (websocket): High-performance Websocket API client based on coroutine process asynchronous IO, supports sharing event loops with REST Client to avoid multi-threaded performance loss caused by GIL

  5. :arrow_up: Simple and easy-to-use event-driven engine (vnpy.event), which is the core of event-driven trading programs

  6. Standardized management client (vnpy.database) interfacing with various databases:

    • SQL class

      • :arrow_up: SQLite (sqlite): Lightweight single file database, no need to install and configure data service programs, default option of VeighNa, suitable for novice users

      • MySQL (mysql): The world's most popular open source relational database, extremely rich documentation, and can replace other high NewSQL compatible implementations (such as TiDB)

      • PostgreSQL (postgresql): More feature-rich open source relational database, support for new features through extension plug-ins, only recommended for skilled users

    • NoSQL classes

      • DolphinDB (dolphindb): A high-performance distributed temporal database especially suitable for low latency or real-time tasks with high speed requirements

      • Arctic (arctic): High-performance financial temporal database developed by quantitative hedge fund Man AHL based on MongoDB, adopts performance optimization schemes such as partitioned storage and lz4 compression

      • TDengine (taos): Distributed, high-performance, SQL-supporting time-series database with built-in caching, stream computing, data subscription and other system functions that greatly reduce development and maintenance complexity

      • TimescaleDB (timescaledb): Time-series database developed based on PostgreSQL, installed as a plugin extension, supports automatic data partitioning by space and time

      • MongoDB (mongodb): Non-relational database based on distributed file storage (bson format), built-in memory cache of hot data provides faster read and write speeds

      • InfluxDB (influxdb): Non-relational database specially designed for time-series data, columnar data storage provides high read/write efficiency and peripheral analysis applications

      • LevelDB (leveldb): High-performance key/value database launched by Google which implements a process memory storage engine based on LSM algorithm, and supports billions of levels of massive data

  7. Adapter interfaces for various data services (datafeed):

    • XtQuant (xt): Stocks, futures, options, funds, bonds

    • :arrow_up: RQData (rqdata): Stocks, futures, options, funds, bonds, Gold TD

    • VoltTrader (voltrader): Futures, options

    • UData (udata): Stocks, futures, options

    • TuShare (tushare): Stocks, futures, options, funds

    • Wind (wind): Stocks, futures, funds, bonds

    • Tinysoft (tinysoft): Stocks, futures, funds, bonds

    • iFinD (ifind): Stocks, futures, funds, bonds

    • TQSDK (tqsdk): Futures

  8. :arrow_up: Standard component for inter-process communication (vnpy.rpc) for implementing complex trading systems in distributed deployments

  9. :arrow_up: Python high-performance K-line charts (vnpy.chart), supporting large data volume chart display and real-time data update functions

  10. Community Forum and Zhihu Blog, which include the development tutorial of VeighNa project and the research on the application of Python in the field of quantitative trading, etc.

  11. The official communication group 262656087 (QQ), with strict management (regular purging of long-term inactive members), and the membership fee will be donated to the VeighNa community fund.

Note: The above description of functional features is based on the documentation at the time of publication, and subsequent updates or adjustments may exist. If there are discrepancies between the function description and the actual situation, please contact us through Issue for adjustments.

Environment preparation

  • We recommend using the Python distribution VeighNa Studio-4.0.0, which is built with the latest version of VeighNa framework and VeighNa Station quantitative management platform, specifically created by the VeighNa team for quantitative trading. No manual installation required.
  • Supported system versions: Windows 11 or above / Windows Server 2022 or above / Ubuntu 22.04 LTS or above
  • Supported Python version: Python 3.10 or above (64-bit), Python 3.13 recommended

Installation steps

Download the latest version from here, unzip it and run the following command to install it.

Windows

install.bat

Ubuntu

bash install.sh

Macos

bash install_osx.sh

User's Guide

  1. Register a CTP Demo account at SimNow and get the broker code and the trading quotes server address at this page.

  2. Register at VeighNa community forum to get the VeighNa Station account password (the forum account password is used)

  3. Launch VeighNa Station (a shortcut will be created automatically on your desktop after installing VeighNa Studio), enter the account password from the previous step and login

  4. Click on the VeighNa Trader button at the bottom and start your trading!

Attention:

  • Please do not close VeighNa Station during the running of VeighNa Trader (it will exit automatically)

Script Run

In addition to the graphical start-up method based on VeighNa Station, you can also create run.py in any directory and write the following sample code:

from vnpy.event import EventEngine
from vnpy.trader.engine import MainEngine
from vnpy.trader.ui import MainWindow, create_qapp

from vnpy_ctp import CtpGateway
from vnpy_ctastrategy import CtaStrategyApp
from vnpy_ctabacktester import CtaBacktesterApp


def main():
    """Start VeighNa Trader"""
    qapp = create_qapp()

    event_engine = EventEngine()
    main_engine = MainEngine(event_engine)
    
    main_engine.add_gateway(CtpGateway)
    main_engine.add_app(CtaStrategyApp)
    main_engine.add_app(CtaBacktesterApp)

    main_window = MainWindow(main_engine, event_engine)
    main_window.showMaximized()

    qapp.exec()


if __name__ == "__main__":
    main()

Open CMD in that directory (hold Shift->click right mouse button->open command window/PowerShell here) and then run the following command to start VeighNa Trader:

python run.py

Contributing code

VeighNa uses Github to host its source code, if you wish to contribute code please use the PR (Pull Request) process of github:

  1. Create Issue - For larger changes (such as new features, large refactoring, etc.) it is best to first open an issue to discuss, and smaller improvements (such as document improvements, bugfixes, etc.) can be sent directly to PR

  2. Fork VeighNa - Click the Fork button in the upper right corner

  3. Clone your own fork: git clone https://github.com/$userid/vnpy.git

  4. Create your own feature branch from dev: git checkout -b $my_feature_branch dev

  5. Make changes on $my_feature_branch and push the changes to your fork

  6. Create a [Pull Request] from your fork's $my_feature_branch branch to the main project's dev branch - here Click on compare across forks and select the required fork and branch to create the PR

  7. Waiting for review, need to continue to improve, or be Merge!

When submitting code, please observe the following rules to improve the quality of the code:

  • Use ruff to check your code style, ensuring there are no errors and warnings. Just run ruff check . in the project root directory.
  • Use mypy for static type checking, ensuring type annotations are correct. Just run mypy vnpy in the project root directory.

Other content

Copyright statement

MIT

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/vnpy-vnpy.git
git@api.gitlife.ru:oschina-mirror/vnpy-vnpy.git
oschina-mirror
vnpy-vnpy
vnpy-vnpy
master