The third part realizes the simple quantization frame
Framework content:
- Start time, end time, cash, position data
- Get Historical data
- Trading functions
- Calculate and draw the yield curve
- Backtesting Main Frame
- Calculate the indicators
- User-Pending code: initialization, daily processing function
Part IV online platform and quantitative investment
The content of this section:
- First simple strategy (understanding the platform)
- Double moving Average strategy
- Factor stock selection Strategy
- Multi-factor stock selection strategy
- Small market capitalization strategy
- Turtle Trading Rules
- Mean reversion strategy
- Momentum Strategy
- Reversal Policy
- Alpaca Trading Rules
- Peg Strategy
- Alligator Trading Rules
Joinquant Platform
- Main framework
- Initialize
- Handle_data
- ......
- Get Historical data
- Trading functions
- Back Test frequency:
- By day backtesting
- Back to test by minute
- Risk indicators
Double moving Average strategy
- EMA: For each trading day, you can calculate the moving average of the first n days, and then connect the moving averages to become a line, called the N-day moving average.
- Common lines for moving averages are 5-day, 10-day, 30-day, 60-day, 120-day, and 240-day indicators. 5-day and 10-day is the short-term operation of the reference indicators, known as the daily average line indicator, 30 days and 60 days is the medium-term moving average indicator, called the index of the seasonal average, 120 days, 240 days is the long-term average indicator, called the annual average line indicator.
- Golden Fork: Long-term moving average on short moving average
- Dead fork: Long-term EMA under short-term EMA
Factor stock selection Strategy
- Factor:
- Standard growth rate, market capitalization, ROE, ...
- Stock Selection Strategy:
- Select the maximum (or minimum) number of n stock positions for this factor
- Multi-Factor stock selection: How to consider multiple factors at the same time?
The theory of Mean value regression
- Mean reversion: "Sooner or later the fall will rise."
- The theory of mean reversion is based on the following observations: Price fluctuations are generally centered on its moving average. That is, when the underlying price deviates from the moving average due to fluctuations, it adjusts and is re-attributed to the moving average.
- Degree of deviation: (ma-p)/ma
- Strategy: On each warehouse day (once a month)
- Calculates the N-day moving average of a stock in a pool;
- Calculates the deviation of all stock prices in the pool from the moving averages;
- Select the Num_stocks stock with the highest deviation and make a position adjustment.
Bollinger bands Strategy
- Bollinger Bands/Bollinger bands/Poly Plus channel (Bollinger Band): consists of three track lines, where the upper and lower lines can be regarded as the price of the pressure line and the support line, between the two lines is a price average line.
- Calculation formula:
- Median line =20 daily average line
- Up line =20 daily average +N*SD (20th closing price)
- Down Line =20 daily average-N*SD (20th closing price)
Peg Strategy
- Peter Lynch: If the price of any company is reasonable, the P/E ratio will be equal to the rate of return.
- Earnings per share (EPS)
- Share price (P)
- P/E (PE) = P/eps
- Revenue Growth (G) = (epsi–epsi-1)/EPSi-1
- PEG = pe/g/100
- The lower the peg, the more likely it is to be undervalued, and the more likely it is to rise.
- Peg is a comprehensive index, both to examine the value and to take into account the growth. Peg valuation method is suitable for growing companies.
- Note: Filter out the price-earnings ratio or earnings growth is negative situation
Alpaca Trading Rules
- At the beginning of the random buy n stocks, sell the lowest yield m per day, and then randomly buy the remaining stock pool of M.
Turtle Trading Rules
- Donchian Channel:
- Online =max (highest price for the first n trading days)
- Downline =min (lowest price for the first n trading days)
- midline = (on line + downline)/2
Minute backtesting
- Market entry: If the current price is higher than the previous high of 20th, buy a unit
- Added: If the stock price increases by 0.5N on the basis of the last buy (or increase), a unit
- Take profit: Empty the position when the stock price falls below the lowest price within 10th (Donchian Channel, 10th)
- Stop loss: Sell all position stop loss (no more than 2%) when the price falls 2N from the last buy price
Day33 Python and financial Quantitative Analysis (iii)