Quant Python 101: Introduction

I. Quant Investing Background 量化投资背景

Quant is the abbreviation of Quantitative, meaning relating to, measuring, or measured by the quantity of something rather than its quality, according to its definition. Quantitative Investing, or Quant Investing is an investment method that applies mathematics, statistics and computer science to Finance fields.

Recently, Big data, machine learning become a new research field of quant investing. It seems that those techniques are very power. However, the truth is that many machine learning methods are overfit the financial data; since financial data have lots of noise, machine learning methods will always fit the noise instead of meaningful feartures. With more and more advance research in deep learning(ARR,NRR…), some data scientists indeed figure out some methods to overcome the problems of overfitting.

II. Quant Investing Procedures 量化投资的过程

There is no secret formula or strategy for quant investing. Quant trading is a pactical science, like Traditional Chinese Medicine. So Consider yourself as a Phd student! You gotta to research and test again and again. No one knows the answer, even your boss, until you backtest the strategies. Thus, the only way to check whether your strategies work or not is backtesting!

Before you could actually begin you research and investing, you need the following things:

1. Data

Data is the first cornerstone for quant investing. Just as a saying goes, “Garbage in, garbage out”. If the data is unreliable, everything based on the data is garbage. So please pay lots of attention to data and make sure you could process the source data clean and accurate. The quality of your data determines your investing results. I will write more about data in later blogs.<>
A typical data structure like this:

Time open high low close volume P/E
20170101 10.00 10:48 9.89 10.23 121324 25.23

2. Strategy Logic

Select a direction of you strategy. And you gotta know the logic behind the strategies. These strategies comes from differ sources, such as former experience, research assumptions(Brownian Motion), Efficient Markets Hypothesis, and arbitrage theorem. I will expand this discussion in Part III.

3. Trading System(Execute)

For a simple trading system, it consists of at least three parts: order management, order execution, and execute algorithm. Notice that the “execute algorithm” here only refer to order split algorithms. For example, if you want to buy 1 million shares of AAPL, this execute algorithm will divide 1 million shares to lots of small orders, so that other investors cannot observe the strong demand and the order can have a better execution price. Typical execute algo inclues VWAP and TWAP, etc.

4. Visual and evaluation System(GUI)

A typical Quant Investing Procedures are like this:

III. Quant Investing Strategies 量化投资策略分类

Many Quant Strategies are based on original trading strategies, including technical analysis model. Quant(computer scientists) just apply those “Old” strategies in the computer-based system. While thanks to many mathematicians, statistics, and data scientist, many new strategies are invented and works really well. For this generation, everyone could create its own strategies and make a profit, but before that, we still need the building blocks to design our own strategies.

Stock selection 量化择股

Time selection 量化择时

In short, time selection is very similar to Stock selection. Rather, time selection is to figure when to buy in and when to exit one or more stocks. This strategy has a basic assumption: there is market timing in the financial market. For more info about market timing, please refer to Li’s essay.

Assuming market timing exist, this is, we could make a profit by predicting the time to enter/exit market. Logically, when the market works well, we enter; before the market performs poorly, we exit. We mainly use four dimensions to predict the when is a good time to enter: leading macroeconomics index, technical analysis,fundamental analysis, and sentiment level.

A simple example for markting timing strategy is simple moving average, SMA.

Stock Index Futures 股指期货

Commodities Futures 商品期货

Statistics 统计套利

协整性

Options 期权套利

Algo Trading算法交易

Assets Allocation资产配置

Machine Learning and Text Mining (to be continued)

High Frequency 高频策略 (to be continued)

VI. Python Introduction

Basic Element

String -*important

1
mystring
String method
1
mystring

List - *most important

The elements in list are mmutable

1
2
3
4
myList1 = [] #empty list
myList2 = [1,2]
myList2[1] = 3
myList2

#####List Method

1
2
myList1.append()
myList1.extend()

####Tuple
The elements in tuple are immutable.

1
2
3
myTuple1 = () #empty tuple
myTuple2 = (1,'2',3.0)
myTuple2[2]

or

1
2
myTuple3 = 1, '2', 3.0, 4
myTuple3[2]

Since the elements in tuple are immutable, we cannot change the elements. And hence, it would come to an error if you type the following:

1
myTuple2[2]= 2

Tuple Method
1
myTuple2.count(3.0) #

####Set


Set Method
Donate here! Thanks for the support!