⑴ 怎樣用python處理股票
用Python處理股票需要獲取股票數據,以國內股票數據為例,可以安裝Python的第三方庫:tushare;一個國內股票數據獲取包。可以在網路中搜索「Python tushare」來查詢相關資料,或者在tushare的官網上查詢說明文檔。
⑵ 如何使用Python獲取股票分時成交數據
可以使用爬蟲來爬取數據,在寫個處理邏輯進行數據的整理。你可以詳細說明下你的需求,要爬取的網站等等。
希望我的回答對你有幫助
⑶ python獲取一隻股票的行情,為什麼出現這么多問題
首先,你要確定下你的庫文件是否安裝正常,測試方法,就是在交互模式下測試。
其次,不要用別名,在試試。
希望能幫到你。。。。
⑷ python如何獲得股票實時交易數據
使用easyquotation這個庫。(不用重復造輪子了)
github地址是:
https://github.com/shidenggui/easyquotation
你先把價格按日期排序之後變成一個list的話,比如:
price=[70,74, 73, 72, 71,75]
你可以這么辦:
operations=[]
isLong=False
for i in range(len(price)-1):
if(not isLong):
if(price[i]<price[i+1]):
print "Go long on day " + str(i)
operations.append(-1);
isLong=True;
else:
operations.append(0);
else:
if(price[i]>price[i+1]):
print "Go short on day " + str(i)
operations.append(1);
isLong=False;
else:
operations.append(0);
if(isLong):
print "Go short on day " + str(len(price)-1)
operations.append(1)
else:
operations.append(0)
ProfitPerShare=0
for i in range(len(price)):
ProfitPerShare+=price[i]*operations[i]
print "Summary profit per share: "+str(ProfitPerShare)
這裡面就是說,如果你是空倉,那麼如果明天比今天高就買,否則明天買就比今天買更劃算;如果你不空倉,那麼如果明天比今天價低你就要清倉,否則明天賣就會更劃算。然後用一個叫operations的list來記錄你每天的操作,-1表示買,0表示沒有,1表示賣,所以最後可以計算每股獲得的收入price[i]*operations[i]的總和。
⑹ 如何用python代碼判斷一段范圍內股票最高點
Copyright © 1999-2020, CSDN.NET, All Rights Reserved
登錄
python+聚寬 統計A股市場個股在某時間段的最高價、最低價及其時間 原創
2019-10-12 09:20:50
開拖拉機的大寶
碼齡4年
關注
使用工具pycharm + 聚寬數據源,統計A股市場個股在某時間段的最高價、最低價及其時間,並列印excel表格輸出
from jqdatasdk import *
import pandas as pd
import logging
import sys
logger = logging.getLogger("logger")
logger.setLevel(logging.INFO)
# 聚寬數據賬戶名和密碼設置
auth('username','password')
#獲取A股列表,包括代號,名稱,上市退市時間等。
security = get_all_securities(types=[], date=None)
pd2 = get_all_securities(['stock'])
# 獲取股票代號
stocks = list(get_all_securities(['stock']).index)
# 獲取股票名稱
stocknames = pd2['display_name']
start_date = -01-01'
end_date = -12-31'
def get_stocks_high_low(start_date,end_date):
# 新建表,表頭列
# 為:"idx","stockcode","stockname","maxvalue","maxtime","lowvalue","lowtime"
result = pd.DataFrame(columns=["idx", "stockcode", "stockname", "maxvalue", "maxtime", "lowvalue", "lowtime"])
for i in range(0,stocks.__len__()-1):
pd01 = get_price(stocks[i], start_date, end_date, frequency='daily',
fields=None, skip_paused=False,fq='pre', count=None)
result=result.append(pd.DataFrame({'idx':[i],'stockcode':[stocks[i]],'stockname':
[stocknames[i]],'maxvalue':[pd01['high'].max()],'maxtime':
[pd01['high'].idxmax()],'lowvalue': [pd01['low'].min()], 'lowtime':
[pd01['low'].idxmin()]}),ignore_index=True)
result.to_csv("stock_max_min.csv",encoding = 'utf-8', index = True)
logger.warning("執行完畢!
⑺ 如何獲取實時的股票數據
估計你是盤中炒股需要吧?多數股票軟體都有公式系統,例如大智慧、同花順、通達信,都有公式系統,在公式系統中編寫自己的公式,就可以得到自己需要的實時的股票數據了。這些都是免費的。
如果是公司,有專門提供股票行情API介面的,例如微盛的金融實時行情API介面,但這種介面需要程序員才能使用,比較專業。
⑻ 怎麼用python計算股票
作為一個python新手,在學習中遇到很多問題,要善於運用各種方法。今天,在學習中,碰到了如何通過收盤價計算股票的漲跌幅。
第一種:
讀取數據並建立函數:
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import spline
from pylab import *
import pandas as pd
from pandas import Series
a=pd.read_csv('d:///1.csv',sep=',')#文件位置
t=a['close']
def f(t):
s=[]
for i in range(1,len(t)):
if i==1:
continue
else:
s.append((t[i]-t[i-1])/t[i]*100)
print s
plot(s)
plt.show()
f(t)
第二種:
利用pandas裡面的方法:
import pandas as pd
a=pd.read_csv('d:///1.csv')
rets = a['close'].pct_change() * 100
print rets
第三種:
close=a['close']
rets=close/close.shift(1)-1
print rets
總結:python是一種非常好的編程語言,一般而言,我們可以運用構建相關函數來實現自己的思想,但是,眾所周知,python中裡面的有很多科學計算包,裡面有很多方法可以快速解決計算的需要,如上面提到的pandas中的pct_change()。因此在平時的使用中應當學會尋找更好的方法,提高運算速度。