Python爬虫回测股票的实例讲解
股票和基金一直是热门的话题,很多周围的人都选择不同种类的理财方式。就股票而言,肯定是短时间内收益最大化,这里我们需要用python爬虫的方法,来帮助我们获取一些股票的数据,这样才能更好的买到相应的股票。下面我们就python爬虫获取股票数据的方法带来详细的讲解。
1.生成上证与深证所有股票的代码:
#上证代码 shanghaicode=[] foriinrange(600000,604000,1): shanghaicode.append(str(i)) #深证代码 shenzhencode=[] foriinrange(1000000,1005000,1): i=str(i)[1:] shenzhencode.append(i)
2.定义一个爬取函数,broker创建的实例:
defgetalldata(code):
ifos.path.exists(datapath+code+'.csv'):
print(code+'alreadyexisted!')
return
metadata=broker.get_stock_pro(code)
iflen(metadata)==0:
return
metadata.to_csv('C:/Users/abc/Desktop/'+code+'.csv',index=False)
print(code+'finished!')
3.导入多线程需要的模块
fromconcurrent.futures.threadimportThreadPoolExecutor#多线程
4.遍历所有代码开始爬取,max_workers可适当调整
executor=ThreadPoolExecutor(max_workers=3) fordatatempinexecutor.map(getalldata,shenzhencode): pass executor=ThreadPoolExecutor(max_workers=3) fordatatempinexecutor.map(getalldata,shanghaicode): pass
到此这篇关于Python爬虫回测股票的实例讲解的文章就介绍到这了,更多相关Python爬虫回测股票的方法内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下