4. Python quantitative trading - Double average strategy
編輯:Python
Catalog
One 、 Data preparation
Two 、5 The daily average and 30 ma
1 - Concept of moving average
2 - Calculation 5 The daily average and 30 ma
3 - Draw MA5 and MA30
3、 ... and 、 Golden fork and dead fork
1 - The concept of golden fork and dead fork
2 - Analyze all golden cross dates and dead cross dates
Four 、 Use the golden fork and dead fork strategy to back test
1 - Demand analysis
2 - Data processing
3 - Income back test calculation
5、 ... and 、jupyter note
One 、 Data preparation
Use tushare Package to get the historical market data of a stock : We've been 3、Python Quantitative trading - Stock data preprocessing & Analysis of trading income of decline The historical data information of the stock is obtained in , Here we just need to csv Just read it out
Two 、5 The daily average and 30 ma
1 - Concept of moving average
What is a moving average : For every trading day , Can be calculated before N Day moving average , Then connect these moving averages , Become a line , It's called N Daily moving average . Moving averages are commonly used 5 God 、10 God 、30 God 、60 God 、120 Days and 240 Day indicators
5 Days and 10 Days is the reference index for short-term operation , It's called the daily average ;
30 Days and 60 Days is the medium-term moving average index , It's called the quarterly average ;
120 Days and 240 Days is the long-term moving average index , It's called the annual average
The method of calculating the moving average :MA=(C1+C2+C3+…+Cn)/N C: The closing price of a day N: Moving average period ( Days )
Moving average diagram
2 - Calculation 5 The daily average and 30 ma
3 - Draw MA5 and MA30
3、 ... and 、 Golden fork and dead fork
1 - The concept of golden fork and dead fork
Golden fork and dead fork in stock analysis technology , It can be simply explained as
Two lines in the analysis index , One is the indicator line in a short time , The other is a long-term indicator line .
If the indicator line turns upward for a short time , And it has crossed the indicator line for a long time , This state is called “ kdj ”;
If the indicator line turns downward for a short time , And it has crossed the indicator line for a long time , This state is called “ Dead fork ”;
In general , After the golden fork , Operation tends to buy ; Dead forks tend to sell . Of course , The golden fork and the dead fork are just one of the analysis indicators , It should be used in conjunction with many other indicators , To increase the accuracy of the operation
Diagram of golden fork and dead fork
2 - Analyze all golden cross dates and dead cross dates
Cut out invalid data
The calculation algorithm of golden fork and dead fork
Four 、 Use the golden fork and dead fork strategy to back test
1 - Demand analysis
demand : If I from if I from 2010 year 1 month 1 The day begins , The initial funding is 100000 element , Jincha tries to buy , All the dead forks are sold , So far , How about my stock return ?
analysis :
The unit price for buying and selling stocks is the opening price
The timing of buying and selling stocks
In the end, there will be surplus stocks in hand that have not been sold
There will be . If the last day is a golden fork , Then buy stocks . Estimate the value of the remaining shares and calculate the total income
The unit price of the remaining shares is the closing price of the last day
2 - Data processing
1 It stands for golden fork ,0 It stands for dead cross
Merge s1 and s2, Sort by date
Filter out as required 2010 Year to 2020 The data of