This is the 8th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

Survival is the first need of civilization. 2. Civilizations grew and expanded, but the amount of matter in the universe remained roughly the same.

1 introduction

In the previous chapters, we have been using Python crawlers to grab data, and then stored the data information in the database. So far, we have completed the basic processing of basic information, and then we will deal with the advanced content. Today, we will start from the trend analysis of the fund.

2 fund trend analysis

The trend of funds is to choose some strong performance of the fund, what is strong? That is to be steady, step by step all the way north. Generally, funds follow a trend line up or down, and the trend formation of funds is more certain than the trend of stocks. The figure below shows the trend of China Securities New energy Vehicle ETF. It can be seen that the trend of this fund is basically in accordance with the red trend line. What we are going to do today is to calculate the slope of this trend and the reliability of the trend table using mathematical linear regression.

The model used to analyze fund trend here adopts linear regression, assuming that its trend is in line with Y =kx+b{y=kx+ B}y=kx+ B, where Y is the corresponding yield rate and x is time. K is the slope. Now all you need to do is use this set of funds to calculate this k-value, so that you can use this k-value to compare funds.

3. Data capture and analysis

3.1 Fund data capture

Grab the data of historical rate of return of fund data

# grab fund history yield data connection http://api.fund.eastmoney.com/pinzhong/LJSYLZS?fundCode=515030&indexcode=000300&type=y # fundCode parameters Indexcode Fund comparison benchmark data. The default value is 300(000300). Type indicates the data query period, in which M is one month, Q is three months, HY is six months, Y is one year, TRY is three years, FIY is five yearsCopy the code

In the data returned by API interface, 0 represents fund data, 1 is the average value of similar funds, and 2 is the data of Shanghai and Shenzhen 300.The specific implementation code is shown in figure:

3.2 Data Analysis

Matplotlib and Sklear.linear_model are used for data analysis. The first is used for graphical display of data, and the second is a linear analysis tool used to calculate the k value of the fund. For linear analysis, if you are interested, check out the computational details of linear analysis.

The code for data model calculation and graphical presentation is shown below.Taking the data of new energy ETF as an example, we get the trend line of Y = 0.3541x + b, and the score of this linear model is 0.741. In fact, this score is already pretty high, and the higher the yield, the more volatile it is, the less consistent it is with linear programming.

But there is no exception, with tianhong increase interest short debt C(008647) for example, its score is quite high, see graph display can know, but the k value of bond fund than the K value of the stock fund is quite low, high risk, high return, low risk, low return. Return is compensation for risk.

4 summarizes

In this chapter, the linear programming method is used to analyze the trend of funds, and the quantitative analysis method is used to analyze and screen funds. Finally, we can use this method to analyze all the funds and screen out the funds with strong tendency for investment.