Skip to content

Latest commit

 

History

History
288 lines (157 loc) · 17.8 KB

README_ENG.md

File metadata and controls

288 lines (157 loc) · 17.8 KB

By Traders, For Traders.

vn.py is a Python-based open source quantitative trading system development framework, officially released in January 2015, has grown step by step into a full-featured quantitative trading platform with 6 years of continuous contributions from the open source community, and currently has many users from domestic and international financial institutions, including: hedge funds, investment banks, futures brokers, university research institutions, proprietary trading companies, etc.

The new "vn.py Full Practical Advance" online course series has been launched on the official WeChat account [vnpy-community], covering CTA strategies (completed), options volatility trading (being updated) and more. To purchase, please scan the QR code below and click the [Advanced Course] button in the menu bar to.

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

For financial institution users of vn.py, a special [vn.py Institutional Users Group] (QQ group number: 676499931) has been created to share issues related to institutional applications, such as: interbank market access, asset management O32 system, distributed deployment, etc. Please note that this group is only open to financial institution users, please specify: Name - Institution - Department when joining the group.

Functional Features

  1. Full-featured quantitative trading platform (vnpy.trader) that integrates a variety of 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

      • CTP (ctp): Domestic futures and options

      • CTP Mini (mini): domestic futures, options

      • CTP Securities (sopt): ETF options

      • Pegasus (femas): domestic futures

      • UFT (uft): domestic futures, ETF options

      • Esunny (esunny): domestic futures, Gold TD

      • XSpeed Securities (sec): ETF options

      • NHTD (nhtd): domestic futures, ETF options

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

      • Guotai Junan (hft): domestic securities (A shares)

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

      • SGIT (sgit): spot precious metal, domestic futures

      • KsGold (ksgold): spot precious metal

      • Rohon (rohon): futures management

      • ComStar (comstar): interbank fixed-income market

      • TTS (tts): domestic futures (simulation)

    • Overseas market

      • Interactive Brokers (ib): global securities, futures, options, foreign exchange, etc.

      • Esunny 9.0 (tap): global futures

      • Direct Futures (da): global futures

    • Special Applications

      • RPC service (rpc): inter-process communication interface for distributed architecture
  3. Out-of-the-box trading applications for various quantitative strategies (vnpy.app).

    • cta_strategy: CTA strategy engine module, which allows users to perform fine-grained control over the withdrawal behavior of delegates 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 directly carry out strategy backtester analysis, parameter optimization and other related work

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

    • option_master: option trading module, designed for the domestic options market, supports a variety of 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.) at the same time, providing historical data backtesting and live automatic trading functions

    • algo_trading: algorithm trading module, providing a variety of commonly used intelligent trading algorithms: TWAP, Sniper, Iceberg, BestLimit, etc.

    • script_trader: script strategy module, designed for multi-standard portfolio trading strategies, also can be directly in the command line to achieve REPL instructions in the form of trading, does not support the backtest function

    • paper_account: Simulation trading module, pure localization of simulation trading functions, based on the real-time quotes obtained from the trading interface for commission aggregation, providing commission transaction push and position records

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

    • portfolio_manager: portfolio module, for all kinds of 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 at the same time, realizing a multi-process distributed system

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

    • data_recorder: Quotes recording module, based on the graphical interface for configuration, according to the demand for real-time recording Tick or K-line quotes to the database, 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 realizing front-end risk control functions

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

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

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

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

  5. simple and easy-to-use event-driven engine (vnpy.event), which is the core of event-driven trading program

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

    • SQL class

      • SQLite (sqlite): lightweight single file database, no need to install and configure data service programs, default option of vnpy.py, 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 developed by Zhejiang Zhiyu Technology Co., Ltd. is especially suitable for low latency or real-time tasks with high speed requirements

      • Arctic (arctic): The high-performance financial temporal database developed by quantitative hedge fund Man AHL based on mongodb which adopts performance optimization schemes such as partitioned storage and lz4 compression to achieve higher reading and writing efficiency than mongodb

      • 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): The high-performance key/value database launched by Google which realizes the process memory storage engine based on LSM algorithm, and supports billions of levels of massive data

  7. Adapter interfaces for various data services:

    • RQData (rqdata): stocks, futures, options, funds, bonds, gold spot

    • UData (udata): stock, futures, options

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

    • Wind (wind): stocks, futures, options, funds, bonds

    • Tinysoft (tinysoft): stocks, futures, options, funds, bonds

    • iFinD (ifind): stocks, futures, options, funds, bonds

    • TQSDK (tqsdk): futures

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

  9. 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 vn.py 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 diving members), and the membership fee will be donated to the vn.py community fund.

Environment preparation

  • We recommend using the Python distribution Veighna Studio-2.9.0, which is built with the latest version of vn.py framework and Veighna Station quantitative management platform, specifically created by the vn.py team for quantitative trading. Manual installation
  • Supported system versions: Windows 10 or above/Windows Server 2016 or above/Ubuntu 20.04 LTS
  • Supported Python version: Python 3.7 64-bit (Note that it must be Python 3.7 64-bit version)

Installation steps

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

Windows

install.bat

Ubuntu

. 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 vn.py community forum to get the Veighna Station account password (the forum account password is)

  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)
  • For flexible configuration of quantitative trading application components, please use Veighna Trader

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():
    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

vn.py 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 the 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 vn.py - Click the Fork button in the upper right corner

  3. CloneYour 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:

  • Check your code with flake8 to make sure there are no errors and warnings. Just run flake8 in the project root directory.

Other content

Copyright statement

MIT