Build your own quantification system
Quantitative Stock TradingSystem QTYX is a system that can be used for both learning and practical stock trading analysis.
The purpose of sharing the QTYX system is to provide everyone with a template for building a quantitative system, and ultimately help everyone build their own system. Therefore, we provide source code for secondary development according to your own style.
For QTYX usage guide, please check the link:QTYX usage guide
QTYX has been updated iteratively, the current versionV2.7.4. Subsequent upgrades will update the document content simultaneously.
Functional Overview
For students who are betting on high margin of safety at the bottom (you can also do morphological analysis on ETF data after upgrading later), QTYX has included two stock selection patterns: "double bottom pattern breakthrough" and "box pattern breakthrough" from version 2.7.4 Made an overlay.
Quick to use
Next, let’s talk about how to use it!
On the [Stock Selection Process] page, there are three stock selection ideas: "data-driven", "form-driven" and "RPS-driven", which complement each other.
Here the "Stock Selection Model" selects "Bottom Breakthrough (Box Form & Double Bottom Form)".
Introducing the functions of several key options:
Stock selection date: Select the date for morphological analysis (supports selecting historical dates for backtesting)
Listing time: Filter out sub-new stocks based on listing time (the tool will filter out sub-new stocks after the set time). After the listing of new stocks, they are in a state of rapid rise and fall. The trend is not stable, and there is not enough data for backtesting. When selecting stocks, you should eliminate such stocks in advance.
Eliminate ST/*ST: ST stocks face a very high risk of delisting and investors should avoid them. Such stocks should be eliminated in advance when selecting stocks.
Overlay analysis data: Currently supports "Quarterly Profit Statement" and "Daily Fundamental Indicators". After checking, the corresponding data will be superimposed in the generated stock list.
Stock pool: Select the stock pool to scan, the whole market stock pool, the self-selected stock pool, the concept sector pool, and the industry sector pool
Stock selection model: Choose a stock selection model, such as main rising wave (long moving average & breaking through the previous high), bottom breakthrough (box shape & double bottom shape)
Many times we pay more attention to stocks in currently popular sectors. Therefore, the QTYX system stock selection function has added classification options for concept sectors and industry sectors. In this way, we can specifically select stocks in the sectors we care about, and stock selection becomes very fast.
For example, after selecting "Concept Stock Pool", a list dialog box appears. The left side is the unselected concept section, and the right side is the selected one. Clicking on a sector in the list on the left will add it to the stock selection list on the right. Clicking on a sector in the stock selection list on the right will cancel it and return to the left. The same applies to "industry stock pools". After closing the sector selection dialog box, the stock pool takes effect.
Click "Confirm" to configure the pattern stock selection parameters. By enabling the switch, the two previously independent models of "box pattern breakthrough" and "double bottom pattern breakthrough" are superimposed.
The key parameters of "box shape" and "double bottom shape" will be introduced in detail below.
Note: The two models "Box Form" and "Double Bottom Form" can be used together or separately. Just check the "Enable" box.
Note: This version starts before morphological analysis, so there is no need to update the stock market data in advance! ! !
After starting stock selection, the log bar in the upper left corner will automatically switch to the [Stock Selection Log] to display stocks that meet the characteristics.
After starting to select stocks, for example, if you find that the parameter configuration is wrong, you can stop and modify the parameters, and then start again. If you want to cancel stock selection, just click [Stop Stock Selection]->[Form-driven Stock Selection].
The list of stocks after filtering is as shown below. You can see that the stocks in the pink box chart are in line with the double bottom form, and the stocks in the red box chart are in line with the box form. If a stock meets both forms at the same time, the corresponding data column is The data will be identified.
After the stock selection is completed, the stock selection results will be saved under the "ConfigFiles/Full Market Stock Selection Results" path. After selecting, you can proceed to the next step of stock selection.
double bottom pattern breakout
The double bottom pattern is formed by market forces. We just need to follow the trend. Especially the double bottom pattern formed by large cycles and multiple K lines has better effects!
A double bottom, also known as a "W bottom", means that after a period of decline, the stock price forms a low point and then rebounds, then falls again, forming a new low near the previous low point, and then the stock price moves upward again. This forms two bottoms and becomes a double bottom.
The line connecting the two lowest points is called a "support line."
The high price between the two lows is called the "neckline" price.
Usually when heavy volume breaks through the neckline, it is a good buying point.
There will be two forms after a breakthrough: the first is to pull up quickly immediately after the breakthrough; the second is to shrink back to near the neckline after the breakthrough, and then pull up quickly after confirming that the breakthrough is effective.
As shown in the figure above, we use the closing price time series of individual stocks as analysis data. The current trading date is the end point, and two consecutive intervals are selected from the historical trading days.
The two intervals are first set in exactly equal ranges, and then an interval superposition variable is added. The function of this variable is to further filter out patterns such as head-and-shoulders bottoms or V-shaped bottoms.
Of course, it can also be divided dynamically, and the rules of division can be set according to the overall trend of the market.
Then analyze according to the following steps:
Find the minimum value of interval 1, which is the left bottom
Find the minimum value of interval 2, which is the right bottom
Find the maximum value of the area between the left bottom and the right bottom
Compare the increases of the left bottom and the right bottom, whether the difference is <3%
Whether the closing price on the current date breaks through the neckline >3%
The source code for pattern recognition is stored in StrategyGath/PattenGath.py. Interested friends can study it.
Click "Confirm" in the stock selection data dialog box, and the configuration interface for parameters related to the pattern recognition algorithm will appear.
A total of these parameters are open: the selection of the K-line range, the selection of the middle area error, the error between the double bottom lows, the range of effective breakthrough confirmation, the increase or decrease of the effective breakthrough on the day, and the effective breakthrough of the trading volume threshold.
The meaning of most parameters can be understood in conjunction with algorithm principles. The meanings of some special parameters are explained as follows:
"Judgment of whether it is the first breakthrough." For example, today we used the tool QTYX to search for stocks that meet the form conditions in the entire market, and found the following stock. This stock conforms to a double bottom pattern, but it has broken through for several days (note: if you use the tool to screen it every day, you can find the day of the first breakthrough), so the buying position is not very suitable now.
We prefer to choose stocks that break through the neckline for the first time, which is the perfect time to buy.
For example, for Wasu Media, it has been 5 trading days since the breakthrough day, which is not the first breakthrough!
For example, like Tongcheng Holdings, since we have set the effective breakthrough range to be more than 3% greater than the neckline, today is the first breakthrough day!
In addition, we also combine the trading volume and the day's rise and fall to superimpose the judgment. After all, when there is a large-volume jump at the bottom, it means that the stock is stronger, making the rise after the double bottom pattern breaks through a greater success rate.
(1) For example, when a double bottom pattern breaks through, whether the trading volume is enlarged will be used to determine whether it is an effective breakthrough. An effective breakthrough of the trading volume threshold indicates that the trading volume on the day of the breakthrough is more than X percent higher than the average trading volume within the "selected K-line range".
(2) For example, while identifying the double bottom pattern, determine whether the stock has an upward jump gap in the near future. If so, it can illustrate the strength of the stock.
Box bottom pattern breakthrough
Big bull stocks often have some characteristic signals in the early stages of their rise. Based on these characteristics, you can filter out targets that may become bull stocks, and then focus on tracking them. This is undoubtedly a very effective way to select stocks.
Let’s take a look at the characteristics of Huanrui Century in the early stages of its rise. The stock price fluctuates up and down within the range, and the 20-day, 30-day, 60-day, and 120-day moving averages gradually converge. When a long Yang reaches a recent high, the moving averages begin to diverge rapidly, thus starting an unstoppable rise.
Usually we call the early characteristics of bull stocks - "Bottom moving average sticking, Changyang breakthrough" a box breakthrough pattern. The stock selection function of the quantitative stock analysis tool QTYX supports the screening of stocks in this form.
On the [Stock Selection Process] page, select the "Form-driven" stock selection strategy, and select "Bottom Breakthrough (Box Form & Double Bottom Form)" for "Stock Selection Model".
Then you can see the dedicated configuration interface for box shape breakthrough.
Select parameters corresponding to the morphological characteristics of the cabinet. The parameters here indicate that the stock price fluctuates no more than 15% above and below the 40-day moving average, the convergence range of the 20-day, 30-day, and 60-day moving average is less than 5%, the day's increase exceeds 5%, and the stock price reaches a new 40-day high.
Pattern Stock Picking Backtest
After buying a stock that matches the pattern, whether it is a loss or a profit, we have added a backtest function to make it clear at a glance. For example, during the holding period, the profit can exceed 10%, while the loss is only 3%, then we can design our strategy from the perspective of profit-loss ratio.
For usage of the backtest function, please refer to the usage guide:
In principle, the backtesting function takes two pieces of data, one piece of data is used to identify the pattern (buy when the pattern conditions are met), and the other piece of data is used to calculate the profit and loss after buying the stock.
Follow-up stock selection analysis
Since "data-driven stock selection" and "form-driven stock selection" have been integrated in QTYX, click "Start Stock Selection" -> "Start Conditional Stock Selection", and then you can use conditional expressions to select stocks.
For example, select stocks with good fundamentals based on performance data (need to superimpose "quarterly profit statement"),
You can also select individual stocks that belong to recent popular sectors based on industry sector rotation ideas (need to superimpose "daily fundamental indicators").
Other advanced QTYX analysis features can also be used by double-clicking a stock name or symbol:
Summarize
In terms of use, the stock pool we identified is a stock pool that has a "high probability" of producing bull stocks. Then add your own analysis factors from other dimensions and further narrow down to a few stocks as your trading targets.
At the same time, set the stop-profit and stop-loss points to ensure the overall profit-loss ratio. When you lose a little, stop the loss, and when you make a profit, you make a lot of money. This is the core gameplay of the bottom form!
Trading is actually very simple. Sometimes we lose money because we think about it too complicated!
illustrate
Friends who want to join Knowledge Planet's "Fun with Stock Quantitative Trading" remember to call me on WeChat to get benefits!
Click for introduction to Knowledge Planet:Overview of the essence of Knowledge Planet’s "Fun with Stock Quantitative Trading"