The invention discloses a method for analyzing a stock trend. The method comprises steps of obtaining stock data through the method, and forming a
feature data set; secondly, initializing the speed and position information of the stock
data set, updating a local optimal value point of each particle point and the iteration
step number and the self-adaptive speed value of each particle in each dimension, updating the speeds and positions of all the particle points, and finding a
global optimal value point of the
population from historical local optimal value points of all the particles; and finally, constructing a
data matrix according to the optimal features, performing RF classification on the
data matrix to obtain a
classification result, performing
stock prediction, and comparing the prediction result accuracy with a BPSO-RF
algorithm. According to the method, the optimized discrete binary particle swarm is utilized to improve the
random forest algorithm, remove redundant features, screen optimal features and input the optimal features into the RF
algorithm for
stock prediction, so the prediction precision is improved, the method provided by the invention has a high convergence rate, can find a better optimal value of the target function in the same iteration step, and reduces the
stock prediction time.