2015-10-20 14:50:56 +00:00
|
|
|
# encoding: UTF-8
|
|
|
|
import tushare as ts
|
|
|
|
import pandas as pd
|
2015-11-04 16:28:12 +00:00
|
|
|
#import ipdb
|
|
|
|
import datetime
|
2015-10-20 14:50:56 +00:00
|
|
|
|
2015-11-04 16:28:12 +00:00
|
|
|
#data = ts.get_hist_data('600848', start='2015-04-01', end='2015-10-20') #一次性获取全部日k线数据
|
|
|
|
#
|
|
|
|
#print data.tail(10)
|
|
|
|
#
|
|
|
|
#data.plot()
|
|
|
|
#
|
|
|
|
#data.high.plot()
|
|
|
|
#
|
|
|
|
#with pd.plot_params.use('x_compat',True):
|
|
|
|
# data.open.plot(color = 'g')
|
|
|
|
# data.close.plot(color = 'y')
|
|
|
|
# data.high.plot(color = 'r')
|
|
|
|
# data.low.plot(color = 'b')
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#with pd.plot_params.use('x_compat',True):
|
|
|
|
# data.high.plot(color ='r', figsize = (10,4), grid ='on')
|
|
|
|
# data.low.plot(color ='b', figsize = (10,4), grid ='on')
|
|
|
|
#
|
|
|
|
#ipdb.set_trace()
|
|
|
|
#
|
2015-10-20 14:50:56 +00:00
|
|
|
|
2015-11-04 16:28:12 +00:00
|
|
|
ts.set_token('21768410ff5c2acb686264fa97635fa917a2ba1ae5122fa187b45849d92cfc70')
|
2015-10-20 14:50:56 +00:00
|
|
|
|
2015-11-04 16:28:12 +00:00
|
|
|
md = ts.Market()
|
2015-10-20 14:50:56 +00:00
|
|
|
|
2015-11-04 16:28:12 +00:00
|
|
|
#data = md.MktFutd(ticker='au1512',beginDate='20151008', endDate='20151028',
|
|
|
|
# field='tradeDate,ticker,openPrice,highestPrice,lowestPrice,closePrice,preClosePrice,CHG,CHG1,CHGPct')
|
2015-10-20 14:50:56 +00:00
|
|
|
|
2015-11-04 16:28:12 +00:00
|
|
|
data = md.MktFutd(tradeDate='20140201',
|
|
|
|
field='tradeDate,ticker,openPrice,highestPrice,lowestPrice,closePrice,preClosePrice,CHG,CHG1,CHGPct')
|
2015-10-20 14:50:56 +00:00
|
|
|
|
|
|
|
|
2015-11-04 16:28:12 +00:00
|
|
|
#data['TR'] = abs(data['closePrice']-data['openPrice'])
|
|
|
|
|
|
|
|
#atr = data.tail(10)['TR'].sum()/10
|
|
|
|
|
|
|
|
tradeDate= str(data.tail(1)['tradeDate'].values[0])
|
|
|
|
|
|
|
|
predate = datetime.datetime.strptime(tradeDate, '%Y-%m-%d')
|
|
|
|
|
|
|
|
preOpen = float(data.tail(1)['openPrice'])
|
|
|
|
preHigh = float(data.tail(1)['highestPrice'])
|
|
|
|
preLow = float(data.tail(1)['lowestPrice'])
|
|
|
|
preClose = float(data.tail(1)['closePrice'])
|
|
|
|
|
|
|
|
print data
|
|
|
|
|
|
|
|
#print atr
|
|
|
|
|
|
|
|
print predate
|
|
|
|
print preOpen
|
|
|
|
print preHigh
|
|
|
|
print preLow
|
|
|
|
print preClose
|
|
|
|
|
|
|
|
print data.columns
|
|
|
|
|
2015-10-20 14:50:56 +00:00
|
|
|
|