Open source quantitative trading research framework based on C++/Python

Open source quantitative trading research framework based on C++/Python

2022-09-05 0 1,638
Resource Number 38056 Last Updated 2025-02-24
¥ 0HKD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

This issue recommends hikyuu, an open source quantitative trading research framework based on C++Python.

Open source quantitative trading research framework based on C++/Python插图

Hikyuu is a high performance open source quantitative trading research framework based on C++/Python for strategy analysis and backtesting (currently used in the domestic securities market). Its core idea is based on the current mature systematic trading method, the entire systematic trading is abstracted into seven components: market environment judgment strategy, system effective condition, signal indicator, stop loss/stop profit strategy, fund management strategy, profit target strategy, slip spread algorithm. You can build the strategic asset library of these components respectively. In practical research, they are combined freely to observe the effectiveness, stability and effect of a single type of strategy.

Advantages of Hikyuu

1. The combination is flexible and the strategic asset library is constructed by classification : Hikyuu has carried out a good abstraction of the systematic trading method, including nine strategic components: Market environment judgment strategy, system effective condition, signal indicator, stop loss/stop profit strategy, fund management strategy, profit target strategy, sliding spread algorithm, trading object selection strategy, fund allocation strategy. On this basis, you can build your own policy library, and perform flexible combination and testing. When conducting strategy exploration, we can pay more attention to the performance and impact of a certain aspect of the strategy. Its main functional modules are as follows:

Open source quantitative trading research framework based on C++/Python插图1

2. Performance guarantee, create your own exclusive application : The current project contains three main components: core library based on C++, Python library wrapped in C++ (hikyuu), interactive tools based on Python.

  • C++ core library, provides the overall policy framework, while ensuring performance, has considered the support for multi-threading and multi-core processing, in the future to pursue higher computing speed to provide convenience. C++ core library, you can separate use, build their own client tools.
  • Python library (hikyuu), provides the packaging of C++ library, while integrating talib library (such as TA_SMA, corresponding to talib.sma), can be converted with numpy, pandas data structure. It is convenient to use other mature python data analysis tools.
  • hikyuu.interactive Interactive exploration tool, which provides basic mapping functions of K-lines, indicators, system signals, etc., for exploration and backtesting of quantitative strategies.

3. multi-paradigm support, more convenient and free to explore : support both object-oriented and command line programming paradigm. Among them, the command line is more simple, convenient, and free for policy exploration.

4. data storage is extensible : Currently supports local HDF5 format and MySQL storage. HDF5 is used by default, and the data file size is small, the speed is faster, and the backup is convenient.

Example

# Create a mock trading account for backtesting, initial capital of 300,000 
my_tm = crtTM(init_cash = 300000)

# Create a signal indicator (the 5-day EMA is the fast line, the 5-day EMA itself is the 10-day EMA slowest line, buy when the fast line crosses the slow line upward, sell vice versa) 
my_sg = SG_Flex(OP(EMA(n=5)), slow_n=10)

# Fixed buying 1000 shares at a time 
my_mm = MM_FixedCount(1000)

# Create trading system and run 
sys = SYS_Simple(tm = my_tm, sg = my_sg, mm = my_mm)
sys.run(sm['sz000001'], Query(-150))

Open source quantitative trading research framework based on C++/Python插图2

Complete reference:
https://nbviewer.org/github/fasiondog/hikyuu/blob/master/hikyuu/examples/notebook/000-Index.ipynb?flush_cache=True

Installation

  • Preparation before installation

Supported operating system: 64-bit Windows7 and above version, Linux please use the source code to compile and install.

Python environment: > = Python3.5

< p data – track = “34” > note: it is recommended to install package integrates common data science Python release: Anaconda (https://www.anaconda.com/). Domestic users advice from tsinghua mirror site < a class = “PGC – link” href = “https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/” target = “_blank” rel=”noopener noreferrer” data-content=”mp” data-source=”outerLink”>anaconda | The mirror station help| The mirror station | Tsinghua Open Source Mirror Download.

  • pip installation

Installation:

pip install hikyuu

Version upgrade:

pip install hikyuu -U

Note:

1. The talib package cannot be installed in Windows by pip
Download the corresponding wheel package from https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib/ and install it manually.

2. Linux needs to install dependent libraries: libhdf5, libmysqlclient, libsqlite3

Getting started

  • Download data to start

Note: The data download tool needs to use the unrar command. In Linux, install unrar.

pip After Hikyuu is installed, run the hikyuutdx command in the command line terminal to start the data download tool, and download the data as prompted:

Open source quantitative trading research framework based on C++/Python插图3

Note: If the HikyuuTDX command cannot be executed in the command line terminal, go to the Scripts subdirectory in the python installation directory and select the execution file (hikyuutdx.exe).

If you do not want to download the file using the GUI, run the importdata command on the CLI, as shown in the following figure:

Open source quantitative trading research framework based on C++/Python插图4

Note: Because the importdata command uses the configuration file generated by HikyuuTDX, you need to run HikyuuTDX at least once before you execute importdata for the first time.

  • Learn through code examples

You can access the latest code examples from the following URL, which will help you gradually understand and master the use of Hikyuu and the related concepts of systematic trading. During the daily use of Hikyuu, you can find detailed descriptions of the corresponding built-in indicators, policies, and functions in this help to obtain more information.

https://nbviewer.jupyter.org/github/fasiondog/hikyuu/blob/master/hikyuu/examples/notebook/000-Index.ipyn b?flush_cache=True

The above sample code is edited and run using a Jupyter notebook, you can download the sample code from the top right corner of each sample URL and run it directly in the Jupyter notebook open.

Open source quantitative trading research framework based on C++/Python插图5

or find all the examples from “examples/notebook” in the installation directory.

Open source quantitative trading research framework based on C++/Python插图6

If you are not used to using Jupyter notebook, you can also use your favorite Python client tools (such as shell, Spyder, PyCharm, idle, etc.) and learn to run according to the sample code.

  • Run from Python Shell

You can run Hikyuu using any Python client tool. As shown in the following figure, run hikyuu in a Python shell environment in cmd. When copying code from the above example, should be careful to remove code that starts with a “%”, such as “%time” , these are ipython magic code that only works in ipython environments, not normal shells.

Open source quantitative trading research framework based on C++/Python插图7

To run the Hikyuu interactive tool, you need to introduce it first, as follows:

# To use hikyuu in an interactive environment, the first need to introduce hikyuu interactive tools 
from hikyuu.interactive.interactive import  *

Note: Hikyuu itself is a normal Python package, while
Hikyuu. Interactive. Interactive for hikyuu package contains an interactive tool. If you want to develop your own other programs based on the hikyuu package instead of using it as an interactive program, you can refer to it
Hikyuu/interactive/interactive. Py hikyuu normal initialization.

    • Edit and run

with Jupyter notebook

To start Jupyter notebook, just enter the desired working directory in cmd and type the Jupyter notebook command, as shown below:

Open source quantitative trading research framework based on C++/Python插图8

The above command will start the local web service. At this time, you can open a browser (Chrome or Firefox is recommended) and enter the following address:
http://127.0.0.1:8888/tree according to the menu commands in the interface can be like normal code editor editing and running the code.

Open source quantitative trading research framework based on C++/Python插图9

You can read more on your own.

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free Source Code Open source quantitative trading research framework based on C++/Python https://ictcoder.com/open-source-quantitative-trading-research-framework-based-on-c-python/

Share free open-source source code

Q&A
  • 1. Automatic: After making an online payment, click the (Download) link to download the source code; 2. Manual: Contact the seller or the official to check if the template is consistent. Then, place an order and make payment online. The seller ships the goods, and both parties inspect and confirm that there are no issues. ICTcoder will then settle the payment for the seller. Note: Please ensure to place your order and make payment through ICTcoder. If you do not place your order and make payment through ICTcoder, and the seller sends fake source code or encounters any issues, ICTcoder will not assist in resolving them, nor can we guarantee your funds!
View details
  • 1. Default transaction cycle for source code: The seller manually ships the goods within 1-3 days. The amount paid by the user will be held in escrow by ICTcoder until 7 days after the transaction is completed and both parties confirm that there are no issues. ICTcoder will then settle with the seller. In case of any disputes, ICTcoder will have staff to assist in handling until the dispute is resolved or a refund is made! If the buyer places an order and makes payment not through ICTcoder, any issues and disputes have nothing to do with ICTcoder, and ICTcoder will not be responsible for any liabilities!
View details
  • 1. ICTcoder will permanently archive the transaction process between both parties and snapshots of the traded goods to ensure the authenticity, validity, and security of the transaction! 2. ICTcoder cannot guarantee services such as "permanent package updates" and "permanent technical support" after the merchant's commitment. Buyers are advised to identify these services on their own. If necessary, they can contact ICTcoder for assistance; 3. When both website demonstration and image demonstration exist in the source code, and the text descriptions of the website and images are inconsistent, the text description of the image shall prevail as the basis for dispute resolution (excluding special statements or agreements); 4. If there is no statement such as "no legal basis for refund" or similar content, any indication on the product that "once sold, no refunds will be supported" or other similar declarations shall be deemed invalid; 5. Before the buyer places an order and makes payment, the transaction details agreed upon by both parties via WhatsApp or email can also serve as the basis for dispute resolution (in case of any inconsistency between the agreement and the description of the conflict, the agreement shall prevail); 6. Since chat records and email records can serve as the basis for dispute resolution, both parties should only communicate with each other through the contact information left on the system when contacting each other, in order to prevent the other party from denying their own commitments. 7. Although the probability of disputes is low, it is essential to retain important information such as chat records, text messages, and email records, in case a dispute arises, so that ICTcoder can intervene quickly.
View details
  • 1. As a third-party intermediary platform, ICTcoder solely protects transaction security and the rights and interests of both buyers and sellers based on the transaction contract (product description, agreed content before the transaction); 2. For online trading projects not on the ICTcoder platform, any consequences are unrelated to this platform; regardless of the reason why the seller requests an offline transaction, please contact the administrator to report.
View details

Related Source code

ICTcoder Customer Service

24-hour online professional services