APP下载

一种基于Python和BP神经网络的股票预测方法

2018-08-21曾武序钱文彬王映龙杨文姬柳军

计算机时代 2018年6期

曾武序 钱文彬 王映龙 杨文姬 柳军

摘 要: 股票预测可以辅助投资者进行正确的金融投资,本文使用Python语言开发网页爬虫爬取真实的股票数据,首先通过requests库获取网页数据,使用BeautifulSoup库解析静态html页面,并通过查找标签获取股票数据,然后对数据进行解析,用xlwt库将数据存入excel文件,并对数据归一化处理,最后,在三层BP神经网络中根据批量梯度下降法调整隐含层结点个数,以获取相对更优的连接权值和阈值,从而对股票的涨跌做出预测,为投资者的投资行为提供参考。

关键词: Python; 网络爬虫; BP神经网络; 股票预测

中图分类号:TP183 文献标志码:A 文章编号:1006-8228(2018)06-72-04

A stock forecasting method based on Python and BP neural network

Zeng Wuxu1, Qian Wenbin1, Wang Yinglong2, Yang Wenji1, Liu Jun2

(1. School of Software, Jiangxi Agricultural University, Nanchang, Jiangxi 330045, China;

2. School of computer and information engineering, Jiangxi Agricultural University)

Abstract: Stock predictions can help investors to make the right financial investment. This article uses Python language to develop web crawlers to crawl real stock data. The web page data is obtained from the requests library first, the static html page is analyzed using the BeautifulSoup library, and the stock data is obtained through searching the tags. Then the data is analyzed, the data is stored in excel file by xlwt library, and the data is normalized. Finally, the number of hidden layer nodes is adjusted according to the batch gradient descent method in the three-layer BP neural network to obtain relatively better connection weights and thresholds, so as to predict the ups and downs of stocks and provide reference for investors' investment behavior.

Key words: Python; Web crawler; BP neural network; stock prediction

0 引言

人工神经网络(Artificial Neural Network)即神经网络,是由具有适应性的简单单元组成的广泛并行互连的网络,它的组织能够模拟生物神经系统对真实世界物体所作出的交互反应[1]。神经细胞接收信息以及处理信息的过程用“线性加权”和“函数映射”来模拟,网络结构和权值调整用优化学习算法实现。这种人工神经网络虽然不能和生物神经网络等价,但在某些方面已经取得了优越的性能[2]。

随着经济的发展,股票市场吸引了众多投资者,如何通过已有的数据来预测股价,从而规避风险,获得更高的收益,是众多投资者所关注的。Lei Lei将粗糙集和小波神经相结合对股票指数进行预测[3];张晶华等人用支持向量机对上证指数进行预测研究[4];李晓青将灰度模型应用于股票预测[5];郝博乾將时间序列应用于股票预测[6];董理等人结合文本分析对股票指数进行预测[7]。……

登录APP查看全文