“This is the 17th day of my participation in the First Challenge 2022.

A gentleman to suppress good, shun the day to rest.

preface

The previous part describes the theoretical part of the model of price guarantee stock selection. In this part, we will conduct practical modeling according to the theory to select stocks, and find the corresponding stock information according to the results of the model to verify the accuracy of the model. This paper has two aspects of content, one is graphical display of moving average information, the other is to build a model to select the stock.

Average show

The average chart is the result of simple moving average calculation, as shown in the figure below:

Matplotlib.pyplot. plot method is used to plot the graph. The following parameters need to be set in the graph display:

import matplotlib.pyplot as plt
import matplotlib as mpl
# Set the font to avoid Chinese garbled characters
mpl.rcParams['font.sans-serif'] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False
Set the width and height of the image in inches
plt.rcParams['figure.figsize'] = (20.0.8.0)
Copy the code

The core code for drawing a moving average is shown in the figure below:

# plot Plot (date_list, cl_list, label="close") plt.plot(date_list, m5_list, label="close") label="m5") plt.plot(date_list, ma10_list, label="m10") plt.plot(date_list, ma20_list, Plt.title (' average line ', fontsize=20) plt.xlabel(" time ", fontsize=20) plt.ylabel(" price ", Fontsize =20) # display coordinates every 30 units, because date units take up space, MultipleLocator(30) ax = plt.gca() # ax = MultipleLocator(30) ax = plt.gca() # ax = MultipleLocator(30) ax = plt.gca() # Rotation =-15, fontsize=15 plt.yticks(fontsize=15) plt.yticks(fontsize=15) plt.grid() Plt.show () # Save at specified resolution # plt.savefig('plot123_2.png', dpi=300)Copy the code

The drawing display results are as follows:

Model structures,

The calculation steps of the model are as follows:

  • 1 loop through the data, here the date, date line data using ZIP compression, this can be multiplelistordictIterate at the same time, and ensure that data on each node is not empty.
  • 2 Check whether the current node and the next node meet the daily line crossing condition. Returns 0 if the crossover case is not satisfied, or 1 or -1 depending on the crossover case.
# return 1 if the condition is met, -1 if the condition is met, 0 otherwise
def line_cross(m1, m1_next, m2, m2_next) :
    if m1 < m2 and m1_next > m2_next:
        return 1
    if m1 > m2 and m1_next < m2_next:
        return -1
    return 0
Copy the code
  • 3 points can only cross from 1 point to 2 point, 2 point to 3 point. If the previous condition is satisfied and the next crossing point still cannot be found after 7 cycles, the calculation will be repeated. The final code is shown below:According to the above model, the stock selection isChina Direct (600038), the output results are as follows:

Combined with the daily chart of the figure above and the daily chart search of the stock software, we can confirm that the node is sought to meet the conditions.

conclusion

It has been completed to build the model to find the technical form of stock price support. In the example, the data of the selected rising form can also be verified by the falling form. As for how to verify all the data, the existing stock information can be captured according to the previous method of capturing fund data, and the data of the recent occurrence of price support can be analyzed by traversing one by one. The specific code has been uploaded to Github, welcome your attention.