请 [注册] 或 [登录]  | 返回主站

量化交易吧 /  量化平台 帖子:3364737 新帖:1

量化学习第五天——获取数据

爱德华发表于:7 月 24 日 16:00回复(1)
df = get_price('000001.XSHE') # 获取000001.XSHE的2015年的按天数据
df.head(3)
open close high low volume money
2015-01-05 10.69 10.71 10.89 10.43 427806630 4565387776
2015-01-06 10.60 10.55 10.96 10.40 324009801 3453446144
2015-01-07 10.40 10.35 10.58 10.23 254269894 2634796288
df1 = get_price('000001.XSHE', start_date='2015-01-01', end_date='2015-01-31 23:00:00', frequency='minute', 
                fields=['open', 'close']) # 获得000001.XSHG的2015年01月的分钟数据, 只获取open+close字段
df1.head(3)
open close
2015-01-05 09:31:00 10.69 10.73
2015-01-05 09:32:00 10.73 10.70
2015-01-05 09:33:00 10.69 10.70
df2 = get_price('000001.XSHE', count = 2, end_date='2015-01-31', frequency='daily', 
                fields=['open', 'close']) # 获取获得000001.XSHG在2015年01月31日前2个交易日的数据
df2
open close
2015-01-29 9.24 9.29
2015-01-30 9.31 9.31
df3 = get_price('000001.XSHE', start_date='2015-12-01 14:00:00', end_date='2015-12-02 12:00:00', 
                frequency='1m') # 获得000001.XSHG的2015年12月1号14:00-2015年12月2日12:00的分钟数据
df3.head(3)
open close high low volume money
2015-12-01 14:00:00 9.56 9.54 9.56 9.54 252537 2412856
2015-12-01 14:01:00 9.56 9.56 9.58 9.56 978148 9353134
2015-12-01 14:02:00 9.56 9.55 9.58 9.55 360273 3444622
panel = get_price(get_index_stocks('000903.XSHG')) # 获取中证100的所有成分股的2015年的天数据, 返回一个[pandas.Panel]
df_open = panel['open'] # 获取开盘价的[pandas.DataFrame], 行索引是[datetime.datetime]对象, 列索引是股票代号
df_open[:2]
000001.XSHE 000002.XSHE 000063.XSHE 000069.XSHE 000166.XSHE 000333.XSHE 000538.XSHE 000625.XSHE 000651.XSHE 000725.XSHE ... 601800.XSHG 601818.XSHG 601857.XSHG 601881.XSHG 601899.XSHG 601901.XSHG 601985.XSHG 601988.XSHG 601989.XSHG 601998.XSHG
2015-01-05 10.69 12.91 15.11 8.31 NaN 16.93 61.59 14.77 15.87 3.33 ... 13.53 4.42 10.53 NaN 3.22 13.43 NaN 3.63 9.19 7.62
2015-01-06 10.60 13.10 15.35 8.33 NaN 18.14 63.28 16.30 16.87 3.36 ... 12.98 4.34 11.68 NaN 3.46 12.85 NaN 3.81 9.28 7.48

2 rows × 100 columns

df_volume = panel['volume'] # 获取交易量的[pandas.DataFrame]
df_volume[:2]
000001.XSHE 000002.XSHE 000063.XSHE 000069.XSHE 000166.XSHE 000333.XSHE 000538.XSHE 000625.XSHE 000651.XSHE 000725.XSHE ... 601800.XSHG 601818.XSHG 601857.XSHG 601881.XSHG 601899.XSHG 601901.XSHG 601985.XSHG 601988.XSHG 601989.XSHG 601998.XSHG
2015-01-05 427806630 731112545 177206072 299326181 NaN 160374820 20358618 91174716 256092318 557269885 ... 152535914 1282796993 385934738 NaN 939319054 406242637 NaN 2656567988 839203429 360744954
2015-01-06 324009801 372903124 199162656 147518501 NaN 143447743 23859116 133349094 206908855 524415612 ... 168916539 1020534843 403068786 NaN 878143172 299788267 NaN 2661483171 870633039 309442580

2 rows × 100 columns

df_open['000001.XSHE'][:3] # 获取平安银行的2015年每天的开盘价数据
2015-01-05    10.69
2015-01-06    10.60
2015-01-07    10.40
Name: 000001.XSHE, dtype: float64
 

全部回复

0/140

达人推荐

量化课程

    移动端课程