⑴ 怎樣使用tushare的提供的數據與庫talib計算macd
安裝TuShare
方式1:pip install tushare
方式2:訪問https://pypi.python.org/pypi/tushare/下載安裝
方式3:將源代碼下載到本地python setup.py install
升級TuShare
1、先查看本地與線上的版本版本號:
pip search tushare
2、升級TuShare:
pip install tushare --upgrade
確認安裝成功
import tushare as ts
print ts.__version__
獲取歷史交易數據
import tushare as ts
df = ts.get_hist_data('600848')
ts.get_hist_data('600848',ktype='W') #獲取周k線數據
ts.get_hist_data('600848',ktype='M') #獲取月k線數據
ts.get_hist_data('600848',ktype='5') #獲取5分鍾k線數據
ts.get_hist_data('600848',ktype='15') #獲取15分鍾k線數據
ts.get_hist_data('600848',ktype='30') #獲取30分鍾k線數據
ts.get_hist_data('600848',ktype='60') #獲取60分鍾k線數據
ts.get_hist_data('sh')#獲取上證指數k線數據,其它參數與個股一致,下同
ts.get_hist_data('sz')#獲取深圳成指k線數據 ts.get_hist_data('hs300')#獲取滬深300指數k線數據
ts.get_hist_data('sz50')#獲取上證50指數k線數據
ts.get_hist_data('zxb')#獲取中小板指數k線數據
ts.get_hist_data('cyb')#獲取創業板指數k線數據
Python財經數據介麵包TuShare的使用
獲取歷史分筆數據
df = ts.get_tick_data('000756','2015-03-27')
df.head(10)
Python財經數據介麵包TuShare的使用
獲取實時分筆數據
df = ts.get_realtime_quotes('000581')
print df[['code','name','price','bid','ask','volume','amount','time']]
返回值說明:
0:name,股票名字
1:open,今日開盤價
2:pre_close,昨日收盤價
3:price,當前價格
4:high,今日最高價
5:low,今日最低價
6:bid,競買價,即「買一」報價
7:ask,競賣價,即「賣一」報價
8:volumn,成交量 maybe you need do volumn/100
9:amount,成交金額(元 CNY)
10:b1_v,委買一(筆數 bid volume)
11:b1_p,委買一(價格 bid price)
12:b2_v,「買二」
13:b2_p,「買二」
14:b3_v,「買三」
15:b3_p,「買三」
16:b4_v,「買四」
17:b4_p,「買四」
18:b5_v,「買五」
19:b5_p,「買五」
20:a1_v,委賣一(筆數 ask volume)
21:a1_p,委賣一(價格 ask price)
...
30:date,日期
31:time,時間
⑵ python用什麼方法或者庫可以拿到全部股票代碼
首先你需要知道哪個網站上有所有股票代碼,然後分析這個網站股票代碼的存放方式,再利用python寫一個爬蟲去爬取所有的股票代碼
⑶ 如何從tushare獲取所有A股編號數組
stock_info=ts.get_stock_basics()
def get_all_stock_id():
#獲取所有股票代碼
for i in stock_info.index:
print i
⑷ 如何從tushare獲取所有A股編號數組
stock_info=ts.get_stock_basics()
def get_all_stock_id():
#獲取所有股票代碼
for i in stock_info.index:
print i