Python爬蟲回測股票的實例講解
股票和基金一直是熱門的話題,很多周圍的人都選擇不同種類的理財方式。就股票而言,肯定是短時間內(nèi)收益最大化,這里我們需要用python爬蟲的方法,來幫助我們獲取一些股票的數(shù)據(jù),這樣才能更好的買到相應(yīng)的股票。下面我們就python爬蟲獲取股票數(shù)據(jù)的方法帶來詳細的講解。
1.生成上證與深證所有股票的代碼:
#上證代碼 shanghaicode = [] for i in range(600000, 604000, 1): shanghaicode.append(str(i)) #深證代碼 shenzhencode = [] for i in range(1000000, 1005000, 1): i = str(i)[1:] shenzhencode.append(i)
2.定義一個爬取函數(shù),broker創(chuàng)建的實例:
def getalldata(code): if os.path.exists(datapath + code + '.csv'): print(code + 'already existed!') return metadata = broker.get_stock_pro(code) if len(metadata) == 0: return metadata.to_csv('C:/Users/abc/Desktop/' + code + '.csv',index = False) print(code + 'finished!')
3.導(dǎo)入多線程需要的模塊
from concurrent.futures.thread import ThreadPoolExecutor #多線程
4.遍歷所有代碼開始爬取,max_workers可適當調(diào)整
executor = ThreadPoolExecutor(max_workers=3) for datatemp in executor.map(getalldata, shenzhencode): pass executor = ThreadPoolExecutor(max_workers=3) for datatemp in executor.map(getalldata, shanghaicode): pass
到此這篇關(guān)于Python爬蟲回測股票的實例講解的文章就介紹到這了,更多相關(guān)Python爬蟲回測股票的方法內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 使用python爬蟲實現(xiàn)網(wǎng)絡(luò)股票信息爬取的demo
- python基于機器學(xué)習預(yù)測股票交易信號
- 如何用Python中Tushare包輕松完成股票篩選(詳細流程操作)
- python爬取股票最新數(shù)據(jù)并用excel繪制樹狀圖的示例
- python實現(xiàn)馬丁策略回測3000只股票的實例代碼
- 基于Python爬取搜狐證券股票過程解析
- 基于Python爬取股票數(shù)據(jù)過程詳解
- 關(guān)于python tushare Tkinter構(gòu)建的簡單股票可視化查詢系統(tǒng)(Beta v0.13)
- Python爬取股票信息,并可視化數(shù)據(jù)的示例
- python用線性回歸預(yù)測股票價格的實現(xiàn)代碼
- python 簡單的股票基金爬蟲
相關(guān)文章
如何給windows設(shè)置定時任務(wù)并運行python腳本
這篇文章主要介紹了如何給windows設(shè)置定時任務(wù)并運行python腳本,本文給大家介紹的非常詳細,對大家的學(xué)習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-08-08python測試開發(fā)django之使用supervisord?后臺啟動celery?服務(wù)(worker/beat)
Supervisor是用Python開發(fā)的一個client/server服務(wù),是Linux/Unix系統(tǒng)下的一個進程管理工具,不支持Windows系統(tǒng),這篇文章主要介紹了python測試開發(fā)django之使用supervisord?后臺啟動celery?服務(wù)(worker/beat),需要的朋友可以參考下2022-07-07