From QuantCon 2017: Running a quantitative trading business in China used to be very difficult and require strong IT skills, however it's getting much easier nowadays, when traders with no professional IT training can also do all the tasks in quantitative trading using Python.
In this sharing session, Xiaoyou will share his experience in using Python for data collection, strategy development and automated trading. He will also introduce some related open source projects including TuShare, quantOS, vn.py and so on.
"Deep Reinforcement Learning for Optimal Order Placement in a Limit Order Boo...
Similar to "How to Run a Quantitative Trading Business in China with Python" by Xiaoyou Chen, Head of Option Trading at Shanghai Junzhi Asset Management Ltd.
Technology Edge in Algo Trading: Traditional Vs Automated Trading System Arch...QuantInsti
Similar to "How to Run a Quantitative Trading Business in China with Python" by Xiaoyou Chen, Head of Option Trading at Shanghai Junzhi Asset Management Ltd. (20)
(DIYA) Bhumkar Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
"How to Run a Quantitative Trading Business in China with Python" by Xiaoyou Chen, Head of Option Trading at Shanghai Junzhi Asset Management Ltd.
1. CONFIDENTIAL
How to run a quantitative trading
business in China using Python
QuantCon Singapore
2017-09-29
2. CONFIDENTIALCONFIDENTIAL
Overview of Chinese Market
Data Management - TuShare
Strategy Development
Automated Trading - vn.py
Summary and QA
www.junzhiam.com 3
3. CONFIDENTIALCONFIDENTIAL
About Me
My name is Xiaoyou Chen.
Head of Option Trading at Junzhi Asset Management (均直
资管)
Creator of vn.py project
www.junzhiam.com 4
4. CONFIDENTIALCONFIDENTIAL
About Junzhi Asset Management
Multi-strategy Quant Fund
Equity Long-Short
Trend Following
Statistical Arbitrage
Volatility Trading
Fixed Income Arbitrage
Several billion AUM in CNY
In-house Developed Trading Software
www.junzhiam.com 5
5. CONFIDENTIALCONFIDENTIAL
Chinese Financial Market Overview
Market Overview
Stock
• Over 3300 stocks and 160 ETFs
• World No.2 by Market Cap
• World No.2 by Turnover
Futures
• 43 commodity, 3 equity index and 2 bond futures
• World No. 2 by Turnover
Options
• 1 ETF option: SZ50 ETF
• 2 commodity options: soybean meal, sugar
www.junzhiam.com 6
Data from www.world-exchanges.org (August 2017):
• Stock Market Cap: China $6.6 trillion vs US $29.7 trillion
• Stock Monthly Turnover: China $1.78 trillion vs US $2.28 trillion
• Commodity Monthly Turnover: China $1.23 trillion vs US $4.98 trillion
6. CONFIDENTIALCONFIDENTIAL
Market Features
www.junzhiam.com 7
Exchange markets instead of dealer markets
Stocks only trading on one exchange, no ECN or dark pools
API available, with restrictions on stocks trading
Margin trading with leverage ratio < 2
Short selling available but difficult to find shares
7. CONFIDENTIALCONFIDENTIAL
Traditional vs New Methods for Quant Trading
Automated Trading
C++ Python
Strategy Development
Matlab/R Python
Data Management
SQL Python
www.junzhiam.com 8
12. CONFIDENTIALCONFIDENTIAL
Choice of Database
Database Features Suitable For
HDF5
• Fast reading performance
• Hierachical structure
• Data compression
High Frequency Market Data
(Tick, Minute Bar)
MongoDB
• Document-based data
model, similar to Python
dictionaries
• Deep query-ability
• Horizontal scalability
Low Frequency Market Data
(Daily Bar)
MySQL
• Relationship database
• ACID compliance
Reference Data
www.junzhiam.com 13
13. CONFIDENTIALCONFIDENTIAL
TuShare Overview
www.junzhiam.com 14
Open-source financial data tool for Python created by Jimmy
Liu (my colleague)
100k+ community users, including over 500 financial
institutions (August 2017)
Free data feeds including: Sina Finance, Tenccent Finance,
Shanghai Stock Exchange, etc.
Commercial data feeds including: Datayes, JZData, etc.
14. CONFIDENTIALCONFIDENTIAL
TuShare Features
www.junzhiam.com 15
• Market Data/Fundamental Data/Economic
DataData Available
• Pandas DataFrame/SeriesData Structure
• MySQL/MongoDB/HDF5/CSV
Database
Supported
• Well documented/easy to find support.
Active
Community
15. CONFIDENTIALCONFIDENTIAL
TuShare Data
Data Type Data Example
Market Data
• Equity Tick
• Equity Original/Forward Adjusted Daily Bar
• Equity Intraday Bar
• Index Snapshot
Fundamental Data
• Equity Industry/Concept/Area
• PE/PB Ratio
• Total/Liquid Assets
• Growth Rate
Economic Data
• GDP/CPI
• Depsit Reserve Ratio
• Shibor Rate
• Margin Trading Statistics
www.junzhiam.com 16
17. CONFIDENTIALCONFIDENTIAL
Overview of Chinese Market
Data Management - TuShare
Strategy Development
Automated Trading - vn.py
Summary and QA
www.junzhiam.com 18
18. CONFIDENTIALCONFIDENTIAL
Jupyter Notebook
Powerful IPython shell, perfect tool for strategy development
Rapid prototyping and easy managing data-related projects
Can be used as front-end for automated trading system
www.junzhiam.com 19
19. CONFIDENTIALCONFIDENTIAL
Strategy Development
www.junzhiam.com 20
Data Analysis
• Test for
auto-
correlation
• Test for
Stationary
Time Series
• Plot return
distribution
Strategy
Backtesting
• Array-based
backtesting
• Event-driven
backtesting
• Result
anlyisis
Parameter
Optimization
• Exhaustive
optimization
• Genetic
optimization
• Walk-
Forward
Testing
Various backtesting tools similar in concept to Zipline
20. CONFIDENTIALCONFIDENTIAL
Overview of Chinese Market
Data Management - TuShare
Strategy Development
Automated Trading - vn.py
Summary and QA
www.junzhiam.com 21
21. CONFIDENTIALCONFIDENTIAL
Automated Trading
www.junzhiam.com 22
• For receiving latest market price
update
Realtime Data
Feed
• For sending orders and receiving
execution information
Broker
Connection
• For monitoring order status and
position pnl
Order and
Position Tracking
• For managing strategy life cycle:
initialization, start, stop, etc.Strategy Engine
22. CONFIDENTIALCONFIDENTIAL
vn.py Project
Open-source quantitative trading framework created by
Xiaoyou Chen (me)
Developed by traders, for traders.
Targeting the problem that most vendors and brokers have no
Python support for automated trading
Python and uses C++ for low-layer and performance sensitive
infrastructure.
www.junzhiam.com 23
23. CONFIDENTIALCONFIDENTIAL
Architecture of VnTrader
www.junzhiam.com 24
Main Engine
Event Engine
Order Router
Risk Manager
Data Engine
MongoDB
Database
Data Feeds
• CTP
• FEMAS
• XTP
• SGIT
• IB
• OANDA
• WIND
Broker
Connection
• Equity
• Futures
• Options
• Precious Metal
• Forex
• Cryptocurrency
Management Apps
• GUI Client
• Web Client
• RPC Service
Strategy Apps
• CTA Strategy
• Spread Trading
• Volatility Trading
• Electronic Eye
• Algo Execution
26. CONFIDENTIALCONFIDENTIAL
EventEngine and Complex Trading Strategy
Institutional investors and professional traders can easily
develop complex trading strategies with the Event Engine(EE),
and automatically route their orders to the most desired
destinations:
1. A strategy register event handlers with EE
2. EE receives event update from data feed, broker connection or other
strategies.
3. EE notifies the strategy about new events through handler
4. After doing some trading logic calculations with new data, the
strategy place or cancel orders
5. Strategy can be an algo instance, a GUI front-end or any other
modules
www.junzhiam.com 27
28. CONFIDENTIALCONFIDENTIAL
Overview of Chinese Market
Data Management - TuShare
Strategy Development
Automated Trading - vn.py
Summary and QA
www.junzhiam.com 29
29. CONFIDENTIALCONFIDENTIAL
Summary
Chinese market is becoming increasingly attractive for quant
trading.
Global quant hedge funds obtain fund management license in
China (Bridgewater and Man Group).
With open-source tools in Python, running a quant trading
business in China is getting much easier now.
www.junzhiam.com 30
My name is Xiaoyou Chen.
Today I’m going to share some experience about …
First, let’s try to get a brief overview of Chinese financial market.
My name is …
I am the head of …
Our option trading strategies include volatility trading, low-latency arbitrage, portfolio hedging, cross market arbitrage and so on.
I am also the creator of the vn.py project which is an open-source quantitative trading platform and we will talk about it later.
Then, some background about my company.
Junzhi Asset Management is a leading multi-strategy quantitative trading hedge fund based in Shanghai and we focus on Chinese local markets.
We have trading strategies in almost all local financial markets except forex which is restricted in China.
Our trading strategies include …
We have several billions asset under management in Chinese yuan at the moment.
In order to manage our very big portfolio, we also developed in-house tradng software for broker connection, oms, colocated algo server and so on.
Here is the overview of Chinese financial market.
For the stock market, we have … and is …
For the futures …
For the options …
In China, most financial products are traded on exchanges rather than OTC.
There is no ECN or dark pools in China, every stock can only be traded on the exchange where it’s listed. Block trading is also completed on exchanges.
For futures and options trading, investors are free to use API for sending orders to brokers. However, for stock trading, most brokers do not provide API connection. And those who do provide API will ask for a minimum capital, normally 10 million CNY and also a background check.
Margin trading is available through a service called RongZi. The maximum leverage ratio is 2 and the financing rate is normally is over 7% annually.
Short selling is also available through a service called RongQuan. However, due to the low willingness of Chinese investors to lend their stock for short selling, it’s quite difficult to find those shares which you want to short.
So, the three main steps in Quant Trading…
Traditionally, we need different programming languages for different jobs. However, each of them has its own limitation.
SQL is not optimized to handle time series data.
As a commercial software, Matlab is not cheap to use.
Even with years of experience, writing automated trading programme in C++ is not a easy job.
Besides, most traders do not want to learn 3 programming languages.
Luckily, now we can use just one language for completing all jobs, that is Python.
Created by Guido van Rossum and first released in 1991, Python is an interpreted language with a design philosophy that emphasizes code readability.
Using whitespace indentation to delimit code blocks rather than curly brackets or keywords), and a syntax that allows programmers to express concepts in fewer lines of code, Python is very easy to write.
Python has a large standard library , as well as huge amounts of third-party libraries, offering a wide range of functionality.
Python is also an open-source software, which makes it free to use and gives full control over the programming language if users want.
Here is a table of some popular open-source quant trading projects on Github, ranked by Github stars
First column… Second… Third… Last…
5 Backtesting framework, 3 trading system, 1 data tool and 1 strategy Demo.
Among the 10 projects, 8 are written in Python, 2 in C#. So maybe we can say that Python is dominating the world of open-source quant trading projects.
After getting the overview of the market, let’s have a look at the first step of Quant Trading, which is Data Management.
In quantitative trading, data can be seperated into 2 group: market data and reference data.
Market data refers to the trading price data of financial products.
The most widely used is daily bar data, which is consisted of open/high/low/close price and trading volume and maybe open interest for futures and options.
Daytrading traders or strategies require intraday data such as 1-minute bar or 5-minute bar.
For high frequency strategies, tick data which includes market depth information is necessary.
Reference data is more about those information that comes outside trading, such as fundamental data of equities, economic data of a country and also alternative data (railway freight volume).
The most widely used open-source database solution for quant trading in China are HDF5, MongoDB and MySQL. Here is a table for comparing there features and suitable tasks.
For HDF5,
For MongoDB,
For MySQL,
TuShare is an …
First released in 2014, now it has a large community with more than 100,000 community users, which includes over 500 financial institutions.
As a data tool, TuShare does not provide data by itself, but instead using data from differenct data feeds. As an example, users can get Daily Bar data from Sina Finance or Tencent Finance and get fundamental data of equity from Shanghai Stock Exchange.
For high frequency market data or more detailed reference data, TuShare also support commercial datafeeds such as Datayes and JZData.
Let’s have a look at TuShare features.
First, data available on TuShare includes market data … We will see more detail on the next slide.
TuShare uses Pandas dataframe and series for data structure, which makes it very easy to use. You don’t need to download data into a csv file and then read it into the memory. Just one line of code, you get the dataframe you need for data analysis.
TuShare also provides io tools based on Pandas, which allow users to easily save data into the format they want to use. This includes MySQL/MongoDB/HDF5 and CSV.
The community of TuShare project is very active. Instead of mailing list which is widely used in open-source world for discussion, TuShare uses IM groups of the Tencent QQ, in which community members can talk to each other instantly. So when you get a question, it’s always easy to find some support. The community also makes great contribution to the documentation of the project.
This table shows some examples of the data available on TuShare.
A short example for downloading ETF price data using Tushare and run a backtesting of double moving average strategy in about 30 lines of code.
Download data
Calculate moving averages
Calculate pos based on ma crossing, be ware of the shift by one period here.
Calculate daily trading cost and net pnl.
Calculate cumulative pnl and plot the chart.
When talking about strategy development, people have the most freedom:
array based backtesting vs event based backtesting
2. Write backtesting scripts or use backtesting frameworks.
Here, we won’t go into too much details, but introduce some common tools.
Jupyter notbook is one of my favourite tool for conducting data analysis and strategy development.
Its advantages includes:…
Here is the basic steps of strategy development.
In China, there are various backtesting tools similar to Zipline for this purpose..
Now we have the trading signals generated from our strategy, the last step is to send our orders to the market.
To run an automated trading system, we will need these functions.
Realtime data feed:
…
Vn.py project is an …
The design philosophy of vn.py is by traders, for traders. In my early career, with no professinal IT education or training, I experienced lots of difficulties when trying to build automated trading systems. C++ is too difficult to learn for me and matlab is just not suitable for writing event-driven programme. I hope that there can be a platform which is easy enough for None IT professionals to learn and ensures flexibility by allowing users to modify any lower layer functions if they want.
One of the main target of vn.py is to solve the problem that…
Mainly written in Python and uses C++ for low-layer and performance sensitive infrastructure.
Vn.py project is a framework for developing automated trading programmes.
VnTrader is the trading platform developed based on those functions provided in the project.
The CTA strategy function of VnTrader provides event-driven backtesting which can …
The backtesting engine and the live trading engine have the same API functions, which means that traders can use one strategy code for both backtesting and live trading. This can help to avoid extra bugs when converting the strategy from b to t.