Skip to content

Commit 7f76271

Browse files
committed
add function
Conflicts: pandas_test.py tushare_case.py
1 parent c47ded3 commit 7f76271

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed

pandas_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#-*-coding=utf-8-*-
2+
#author: Rocky Chen
3+
import pandas as pd
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
7+
def base_case():
8+
9+
10+
dates = pd.date_range("20160516",periods=5)
11+
print dates
12+
13+
df=pd.DataFrame(np.random.randn(5,5),index = dates,columns=list("ABCDE"))
14+
print df
15+
print df.describe()
16+
print df.dtypes
17+
print "Check the head 5"
18+
print df.head()
19+
20+
print "check tail 5"
21+
print df.tail()
22+
23+
print df.index
24+
print df.columns
25+
26+
print df.T
27+
28+
print df['B']
29+
print df[0:2]
30+
print df.loc['20160517':'20160519','A':'C']
31+
ts= pd.Series(np.random.randn(1000),index=pd.date_range('1/1/2000',periods=1000))
32+
ts=ts.cumsum()
33+
print "*"
34+
print ts.plot()
35+
36+
df_11=pd.DataFrame(np.random.randn(1000,4),index=ts.index,columns=['A','B','C','D'])
37+
df_11 =df-df_11.cumsum()
38+
plt.figure()
39+
df_11.plot()
40+
41+
#base_case()

tushare_case.py

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def main():
104104
sb = StockBox()
105105
# sb.looper(id)
106106
id = '300333'
107-
#sb.realtime(id)
107+
# sb.realtime(id)
108108
sb.base_function("300333")
109109
# pandas_test=Pandas_test()
110110
# pandas_test.test_function()
@@ -196,15 +196,101 @@ def fund(self):
196196

197197

198198
def main():
199+
# 获取历史数据 近3年的数据
200+
history = ts.get_hist_data(id)
201+
202+
print u"历史3年的数据"
203+
204+
print history.head(10)
205+
206+
history_all = ts.get_h_data(id, '20015101', '20160101')
207+
208+
print u'所有的历史数据'
209+
print history_all
210+
211+
212+
213+
# print type(stockInfo)
214+
# print stockInfo.head()
215+
# print stockInfo.dtypes
216+
# df = ts.get_stock_basics()
217+
#data = df.ix[id]['timeToMarket']
218+
#print data
219+
#ts.get_today_all()
220+
221+
222+
def get_info(self, id):
223+
# 获取一些股票的基本信息
224+
df = ts.get_stock_basics()
225+
print df.ix['300333']['timeToMarket']
226+
227+
228+
def realtime(self, id):
229+
# all_stock=ts.get_today_all()
230+
# print all_stock
231+
df = ts.get_realtime_quotes(id)
232+
# print df[['time','name','price','bid','ask','volume']]
233+
# print df.head()
234+
235+
price_change = ts.get_today_ticks(id)
236+
print price_change[['time', 'change', 'type', 'volume']]
237+
big_share = ts.get_sina_dd(id, date='2016-04-01')
238+
print big_share[['time', 'code', 'price', 'preprice', 'volume', 'type']]
239+
240+
241+
def looper(self, id):
242+
while (1):
243+
self.realtime(id)
244+
time.sleep(30)
245+
246+
247+
def getNews(self):
248+
token = '60517739976b768e07823056c6f9cb0fee33ed55a1709b3eaa14a76c6a1b7a56'
249+
ts.set_token(token)
250+
print ts.get_token()
251+
mkt = ts.Market()
252+
df = mkt.TickRTSnapshot(securityID='000001.XSHE')
253+
print df
254+
255+
256+
def longhuban(self, date):
257+
print ts.top_list(date)
258+
print ts.cap_tops()
259+
260+
261+
def get_stock_chengfeng(self):
262+
df = ts.get_sz50s()
263+
# print df
264+
terminal_stock = ts.get_terminated()
265+
print terminal_stock
266+
267+
268+
def fund(self):
269+
fd = ts.Fund()
270+
df = fd.FundDiv(ticker='184688', adjustedType='D', beginDate='20000101',
271+
field='secShortName,effectDate,publishDate,dividendAfTax,dividendBfTax')
272+
print df
273+
dd = ts.fund_holdings(2015, 4)
274+
print dd[['name', 'nums', 'clast', 'amount']]
275+
276+
277+
'''
278+
def main():
279+
199280
token = '60517739976b768e07823056c6f9cb0fee33ed55a1709b3eaa14a76c6a1b7a56'
200281
id = '300333'
201282
# id=sys.argv[1]
202283
203284
sb = StockBox()
285+
204286
# sb.base_function(id)
205287
sb.get_info(id)
206288
207289
290+
#sb.base_function(id)
291+
sb.get_info(id)
292+
'''
293+
208294
# sb.looper(id)
209295
# sb.realtime(id)
210296
# stockBox.base_function("300333")
@@ -216,6 +302,7 @@ def main():
216302
# sb.get_stock_chengfeng()
217303

218304

305+
219306
class Pandas_test:
220307
def test_function(self):
221308
dates = pd.date_range("20160501", periods=10)

0 commit comments

Comments
 (0)