Position: Home page » Bitcoin » Quantitative trading Python open source BTC

Quantitative trading Python open source BTC

Publish: 2021-04-06 18:14:18
1. Python digital currency quantitative trading advanced course, has been learned, generally mastered.
2. 1. A powerful n-dimensional array object array
2. Relatively mature (broadcast) function library
3. Toolkit for integrating C / C + + and FORTRAN code
4. Practical linear algebra, Fourier transform and random number generating function. Numpy is more convenient to use with the sparse matrix operation package SciPy.
3. Python quantitative investment framework: back testing + simulation + firm offer
Python quantitative investment simulation trading platform 1. Stock Quantitative Investment Framework 1.1 before back testing firm offer trading, quantitative trading strategy must be back tested and simulated to determine whether the strategy is effective, and improve and optimize. As an ordinary person, you can think of, generally someone has done. So is the back testing framework. At present, Xiao mainly sees the following five backtesting frameworks: zipline: event driven framework, which is very popular abroad. The defect is that it is not suitable for the domestic market. Pyalgotrade: event driven framework, the latest update date is August 17, 2016. It supports the domestic market and uses Python 2.7 to develop. The biggest bug is that it does not support the version 3.5 and the powerful panda. Pybacktest: back test is concted by processing vector data. The latest update date is 2 months ago, and the update is unstable. Tradingwithpython: Refactoring based on pybacktest. There are few references. Ultra Finance: the project of GitHub stopped updating two years ago. The latest project is on Google platform, but can't open the website. If you are interested, please check it by yourself. Rqalpha: event driven framework, suitable for A-share market, with daily data. It's an open source framework for backtesting of rice basket. Relatively speaking, I prefer this platform. 2. Simulation trading is also an important step before real trading. In order to prevent similar to the current incident of a securities company, the loss of hundreds of millions within half an hour has had a bad impact on the whole stock market. Simulation transaction, the key consideration is whether the transaction logic of the program is reliable, whether all kinds of data transmission conditions are taken into account. At present, the open source platform I like to use is snowball simulation trading, followed by the simulation trading interface provided by wind. For example, those provided by youkuang, mizuan and jukuan can only be tested on the online platform, so they are not very free and don't feel much. Snowball simulation trading: in the follow-up trading mole, we will focus on the introction, and the main application is an open source easytrader series. Wind simulation transaction: if there is no institutional version, the student free version can be considered. Please refer to the following links for specific simulation transaction interfaces: http://www.dajiangzhang.com/document 3. Firm offer is undoubtedly our ultimate goal. Stock program trading has been restricted. But for all of us, there is always a solution. At present, the most important thing is to crack the trading interface of the website version of securities companies, or to use crawlers to operate. For me, I prefer the open source platform of easytrader series. For institutional users, e to the large amount of funds, it is not recommended for security and reliability. At present, easytrader series mainly consists of three parts: easytrader: providing funds for securities companies Huatai / lijinbao / Yinhe / Guangfa / xueqiu, and automatic programmed trading of stocks, Quantitative trading component easyquotation: real time access to Sina / leverfun's free stocks and level 2's ten quotations / classified fund quotations with ideas. Easyhistory: used to obtain and maintain the historical data of stocks. Easyquant: stock quantitative framework, which supports quotation acquisition and trading. 2, I'm not familiar with futures, but I'm familiar with stocks. Let's make a brief summary according to what we know. 2.1 back testing back testing, it seems that there is no very popular open source framework. There are two possible reasons: compared with stocks, futures have higher threshold, more institutional trading and less open source; So far last year, the futures regulatory control is relatively strict, so far it has not been liberalized, so we can only do some CTA strategies, and many other people are in great interest. In terms of personal understanding, maybe wind is a relatively appropriate choice. 2.2 simulation + real vn.py is the most popular open source platform in China. The independent trading system, which originated from domestic private placement, was just a python encapsulation of the trading API interface when it was launched in early 2015. With the increasing attention of the instry and the continuous contribution of the community, it has graally grown into a comprehensive trading program development framework. As the official website said, the framework focuses on the transaction mole, which is not supported by the back testing mole. The ability is limited. If you are interested in the related framework, please refer to the related links. My personal expectation is to build a backtest framework based on rqalpha, a simulation framework based on snowball or wind, and trade with easy series.
4. Find some tutorials that contain Python quantitative analysis and python quantitative trading, and learn along with them. If self-study is difficult, you can apply for classes. Anyway, the method is always more difficult than the difficulty!
5.

Five months

With its outstanding language advantages and characteristics, python has been integrated into every field of all walks of life. Generally speaking, python training requires about 5 months of off-the-job study, which can enable students to master the skills required for work and accumulate certain project experience. Of course, if you want to go further and further on the road of artificial intelligence, you need to constantly accumulate and learn

in the five months of Python training, quite a large part of the time is in the actual combat projects. The first stage is a month long learning of the core programming of python, mainly the language foundation and advanced application of python, to help students acquire preliminary software engineering knowledge and establish molar programming ideas. After learning the content of this stage, the students are qualified for the position of junior development engineer of Python

extended materials:

Python development foundation course contents include: computer hardware, operating system principle, installation of Linux operating system, common commands for Linux operating system maintenance, python language introction, environment installation, basic grammar, basic data type, binary operation, process control, character coding, file processing, data type User authentication, three-level menu program, shopping cart program development, function, built-in method, recursion, iterator, decorator, built-in method, employee information table development, mole cross directory import, common standard library learning, B encryption, regular logging mole, software development specification learning, calculator program, ATM program development, etc

6.

Here are eight steps to write a quantitative trading strategy - single stock moving average strategy

1 determine the content and framework of the strategy

If yesterday's closing price is higher than the average price of the past 20 days, open today to buy stocks
If yesterday's closing price is lower than the average price of the past 20 days, open today to sell stocks

only operate one stock, right, But how to code it to the computer

think about how people operate, which should include such two parts

since it is a single stock strategy, decide which stock to trade in advance

check whether yesterday's closing price is higher than the average price of the past 20 days every day. If so, buy at the opening, not sell at the opening. Do it every day, cycle

the corresponding code is also the two parts

< pre t = "code" L = "Python" > define (context):
used to write what to do at the beginning
defhandle_ Data (context, data):
used to write what to do in daily circulation < / pre >

2 initialization

we need to write the code of the stock to be traded, such as Bunny (002043)

< pre t = "code" L = "Python" > define (context):
g.security = & 39; 002043.XSHE'# First, get the closing price of yesterday's stock

< pre t = "code" L = "Python" >. Usage: variable = data [Stock Code]. Close
last_ Price = data [g.security]. Close # get the latest closing price, named last_ Price < / pre >

then, get the average price of the stock closing price in the past 20 days

< pre t = "code" L = "Python" > # usage: variable = data [Stock Code]. Mavg (days, 'close')
# get the average price of the stock closing price in the past 20 days, named average_ price
average_ price=data[g.security].mavg(20,' close') iflast_ price> average_ Price:
buy
eliflash_ price< average_ Price:
sell < / pre >

here comes the problem. Now it's time to write down the order, but we haven't told the computer how much we will take to buy it, so we still need to get the amount of cash in the account every day

Usage: variable = context. Portfolio. Cash
cash = context. Portfolio. Cash ᦇ get the current amount of cash, named cash < / pre >

5 buy sell

< pre t = "code" L = "Python" > ᦇ usage: order_ Value (how much do you want to buy the stock code)
order_ Value (g.security, cash) # buy stocks with all current funds
# usage: order_ Target (stock code of the stock to be traded, target position amount)
order_ Target (g.security, 0) # adjust the stock position to 0, that is, write the strategy code for all sell < / pre >

6, and conct a back test

write the code for buy and sell, and the strategy is finished, as follows

< pre t = "code" L = "Python" > define (context): # initialize
g.security = &# 39; 002043.XSHE'# Stock Name: Bunny
defhandle_ Data (context, data): # daily cycle
last_ Price = data [g.security]. Close # get the closing price of the latest day
# get the average price of the past 20 days
average_ price=data[g.security].mavg(20,' close')
cash = context. Portfolio. Cash # get the current cash
# if yesterday's closing price is higher than the 20 day average price, buy, otherwise sell< br />iflast_ price> average_ price:
order_ Value (g.security, cash) #
eliflash_ price< average_ price:
order_ Target (g.security, 0) # adjust the stock position to 0, that is, sell all < / pre >

now, in the upper right part of the strategy back test interface, set the back test time from 20140101 to 20160601, set the initial capital 100000, set the back test frequency, and then click run back test

7 set up a simulated transaction to make the real-time connection between the strategy and the market run automatically.

after the strategy is written and the back test is completed, click the red simulated transaction button at the top right of the back test result interface (as shown in the figure above) to create a new simulated transaction, as shown in the figure below. Write the name of the transaction, set the initial capital, data frequency, here is every day, and submit after setting

8 open wechat notification, receive transaction signal

click my transaction in jukuan navigation bar to see the created simulated transaction, as shown in the figure below. Click the wechat notification switch on the right, turn off to on, scan the QR code according to the instructions, bind wechat, and wechat will receive the transaction signal

7. More mature libraries can refer to the following:
pybacktest
pyalgotrrader
zipline
BT
backtrade

pybacktest is based on vector, not event based, which is much faster and has obvious disadvantages.
8. This paper will explain the basic process of quantitative investment process, quantitative investment is nothing more than these processes, data input --- strategy writing --- back test output
the strategy writing part also involves the choice of programming language, if you don't want to worry about data input and back test output, you should also choose the back test platform< First of all, data is the basis of quantitative investment

wind: the most complete data source is wind, but students can have a free trial if they have to pay. Later, they will share with you how to extract data from wind. Wind has many software excuses, such as Excel, MATLAB, Python and C + +<
forecaster.com: unexpectedly, we found that forecaster.com, a website that provides stock data for free, downloads CSV format
TB trading Pioneer: tradeblazer, thank you @ sun cunhao for providing data source
tushare: tushare - financial data interface package, which is based on python, and uses Python to extract
how to store data
MySQL
how to preprocess data

null value processing: use the fill. Na() function of dataframe to replace the null value (Nan) with the average, median or mode of the column
data standardization
how to classify the data
market data
financial data
macro data
Second, computing language & software

many people have asked online what language to choose? At the beginning, the author used Matlab, but finally chose Python
Python: there are many libraries, only you can't find, not you can't think of, which are closely combined with quantification:
numpy & SciPy: scientific calculation library, matrix calculation
pandas: financial data analysis artifact, a library written by the former AQR capital staff, The standard configuration of processing time series

Matplotlib: Drawing Library
scikit learn: Machine Learning Library
statsmodes: statistical analysis mole
tushare: free and open source Python financial data interface package

zip line: back testing system
Talib: technical index library
MATLAB: mainly matrix operation and scientific operation are very powerful, The main advantage is that workspace variable visualization

Python's numpy + SciPy library can completely replace Matlab's matrix operation
MATLAB's drawing function
Python has many other functions
pychar (an ide of Python) has great debugging function, Can replace Matlab's workspace variable visualization
recommended Python learning documents and books
on the basis of python, suggest Liao Xuefeng Python 2.7 tutorial, suitable for people without program foundation to see first, involving the basic data types, loop statements, conditional statements, functions, classes and objects, file reading and writing and other very important basic knowledge of Python

when it comes to data operation, there is no application for the basic course. All kinds of packages in Python have been written for you. The best learning material is its official document. In the document, there are not only APIs, but also examples
pandas document
statsmodel document
SciPy and numpy document
Matplotlib document

tushare document
Second, It is recommended to use Python for data analysis. The original intention of panda is to process financial data.
3. Backtest framework and website are two open source backtest frameworks.
pyalgotrade - algorithmic trading

zip line, a python algorithmic trading library
9. Python is a scripting language, which is the code language used by programmers
Python's function can't be said to be small, and it has a very convenient application in financial data analysis
but you need to study python, otherwise you will be confused when you see a lot of code.
10. where? Yes, as long as you have the ability, you can learn how
Hot content
Inn digger Publish: 2021-05-29 20:04:36 Views: 341
Purchase of virtual currency in trust contract dispute Publish: 2021-05-29 20:04:33 Views: 942
Blockchain trust machine Publish: 2021-05-29 20:04:26 Views: 720
Brief introduction of ant mine Publish: 2021-05-29 20:04:25 Views: 848
Will digital currency open in November Publish: 2021-05-29 19:56:16 Views: 861
Global digital currency asset exchange Publish: 2021-05-29 19:54:29 Views: 603
Mining chip machine S11 Publish: 2021-05-29 19:54:26 Views: 945
Ethereum algorithm Sha3 Publish: 2021-05-29 19:52:40 Views: 643
Talking about blockchain is not reliable Publish: 2021-05-29 19:52:26 Views: 754
Mining machine node query Publish: 2021-05-29 19:36:37 Views: 750