In [3]:
%matplotlib inline
%time from hikyuu.interactive import *
std::cout are redirected to python::stdout
std::cerr are redirected to python::stderr
2020-08-05 23:36:46.811 [HKU-I] - Loading market information... [loadBaseInfo]
2020-08-05 23:36:46.812 [HKU-I] - Loading stock type information... [loadBaseInfo]
2020-08-05 23:36:46.813 [HKU-I] - Loading stock information... [loadBaseInfo]
2020-08-05 23:36:47.093 [HKU-I] - Loading KData... [init]
2020-08-05 23:36:47.116 [HKU-I] - Preloading all day kdata to buffer! [setKDataDriver]
2020-08-05 23:36:52.246 [HKU-I] - 5.15s Loaded Data. [init]
CPU times: user 5.3 s, sys: 359 ms, total: 5.66 s
Wall time: 5.65 s

1 全局获取股票对象

1.1 获取股票对象

通过全局管理对象 sm,或使用函数 get_stock。股票标识格式“市场标识+股票代码”,市场标识:沪市sh,深市sz。

In [4]:
#s = getStock('sh000001')
s = sm['sh000001']
print(s)
Stock(SH, 000001, 上证指数, 指数, 1, 1990-12-19 00:00:00, +infinity)

1.2 遍历所有股票

In [5]:
i = 0
#遍历所有股票
for s in sm:
    i += 1
    #print(s)
print("全部数量:", i)

len(sm)
全部数量: 5848
Out[5]:
5848

2 通过板块(Block)遍历股票对象

2.1 通过 sm.get_stock("板块分类", "板块名称") 获取相应板块

In [6]:
blk = sm.get_block("指数板块", "上证380")
for s in blk:
    if not s.valid:
        print(s)
Stock(SH, 600270, 外运发展, A股, 0, 2000-12-28 00:00:00, +infinity)
Stock(SH, 603959, 百利科技, A股, 0, 2016-05-17 00:00:00, +infinity)
Stock(SH, 603899, 晨光文具, A股, 0, 2015-01-27 00:00:00, +infinity)
Stock(SH, 603898, 好莱客, A股, 0, 2015-02-17 00:00:00, +infinity)
Stock(SH, 603895, 天永智能, A股, 0, 2018-01-22 00:00:00, +infinity)
Stock(SH, 600614, *ST鹏起, A股, 0, 1992-08-28 00:00:00, +infinity)
Stock(SH, 603888, 新华网, A股, 0, 2016-10-28 00:00:00, +infinity)
Stock(SH, 603989, 艾华集团, A股, 0, 2015-05-15 00:00:00, +infinity)
Stock(SH, 600240, *ST华业, A股, 0, 2000-06-28 00:00:00, +infinity)
Stock(SH, 603929, 亚翔集成, A股, 0, 2016-12-30 00:00:00, +infinity)
Stock(SH, 603939, 益丰药房, A股, 0, 2015-02-17 00:00:00, +infinity)
Stock(SH, 603997, 继峰股份, A股, 0, 2015-03-02 00:00:00, +infinity)

2.1 获取自定义板块

自定义板块的板块分类固定为 “self”

In [7]:
blk = sm.get_block("self", "1")
for s in blk:
    print(s)
Stock(SH, 601018, 宁波港, A股, 1, 2010-09-28 00:00:00, +infinity)
Stock(SH, 600601, 方正科技, A股, 1, 1990-12-19 00:00:00, +infinity)
Stock(SH, 601098, 中南传媒, A股, 1, 2010-10-28 00:00:00, +infinity)
Stock(SH, 600050, 中国联通, A股, 1, 2002-10-09 00:00:00, +infinity)
Stock(SZ, 000001, 平安银行, A股, 1, 1991-01-02 00:00:00, +infinity)
Stock(SZ, 000958, 东方能源, A股, 1, 1999-12-23 00:00:00, +infinity)
Stock(SZ, 002339, 积成电子, A股, 1, 2010-01-22 00:00:00, +infinity)
Stock(SZ, 002685, 华东重机, A股, 1, 2012-06-12 00:00:00, +infinity)
Stock(SZ, 000728, 国元证券, A股, 1, 1997-05-22 00:00:00, +infinity)

2.2 板块信息的配置

板块信息在数据存放路径中 “block” 子目录下,目前采用的是钱龙的格式,你也可从钱龙相应的目录下拷贝最新的板块配置信息。

板块配置

3 查看权息信息

In [8]:
ws = sm['sz000001'].get_weight()
for w in ws:
    print(w)
Weight(1991-04-03 00:00:00, 0, 0, 0, 0, 0, 150, 68)
Weight(1993-05-24 00:00:00, 3.5, 1, 16, 3, 5, 26941, 17912)
Weight(1994-07-11 00:00:00, 3, 1, 5, 5, 2, 43106, 28659)
Weight(1994-09-02 00:00:00, 0, 0, 0, 0, 0, 43106, 29707)
Weight(1995-09-25 00:00:00, 2, 0, 0, 3, 0, 51728, 35721)
Weight(1996-05-27 00:00:00, 5, 0, 0, 0, 5, 103456, 71393)
Weight(1997-08-25 00:00:00, 5, 0, 0, 2, 0, 155184, 107163)
Weight(1999-10-18 00:00:00, 0, 0, 0, 6, 0, 155184, 107163)
Weight(2000-11-06 00:00:00, 0, 3, 8, 0, 0, 194582, 139312)
Weight(2002-07-23 00:00:00, 0, 0, 0, 1.5, 0, 194582, 140936)
Weight(2003-09-29 00:00:00, 0, 0, 0, 1.5, 0, 194582, 140936)
Weight(2007-06-20 00:00:00, 1, 0, 0, 0, 0, 208676, 155019)
Weight(2008-01-21 00:00:00, 0, 0, 0, 0, 0, 229341, 175682)
Weight(2008-06-26 00:00:00, 0, 0, 0, 0, 0, 229341, 204652)
Weight(2008-06-27 00:00:00, 0, 0, 0, 0, 0, 238880, 214200)
Weight(2008-10-31 00:00:00, 3, 0, 0, 0.335, 0, 310543, 278461)
Weight(2009-06-22 00:00:00, 0, 0, 0, 0, 0, 310543, 292367)
Weight(2009-10-15 00:00:00, 0, 0, 0, 0, 0, 310543, 292411)
Weight(2010-06-28 00:00:00, 0, 0, 0, 0, 0, 310543, 310537)
Weight(2010-09-17 00:00:00, 0, 0, 0, 0, 0, 348501, 310537)
Weight(2007-12-31 00:00:00, 0, 0, 0, 0, 0, 229341, 175682)
Weight(2009-06-30 00:00:00, 0, 0, 0, 0, 0, 310543, 292376)
Weight(2011-08-05 00:00:00, 0, 0, 0, 0, 0, 512335, 310536)
Weight(2011-12-31 00:00:00, 0, 0, 0, 0, 0, 512335, 310536)
Weight(2012-10-19 00:00:00, 0, 0, 0, 1, 0, 512335, 310536)
Weight(2012-12-31 00:00:00, 0, 0, 0, 0, 0, 512335, 310536)
Weight(2013-06-20 00:00:00, 6, 0, 0, 1.7, 0, 819736, 496857)
Weight(2013-11-12 00:00:00, 0, 0, 0, 0, 0, 819736, 557590)
Weight(2014-01-09 00:00:00, 0, 0, 0, 0, 0, 952075, 557590)
Weight(2014-06-12 00:00:00, 0, 0, 0, 1.6, 2, 1.14249e+06, 669106)
Weight(2014-09-01 00:00:00, 0, 0, 0, 0, 0, 1.14249e+06, 983671)
Weight(2015-04-13 00:00:00, 0, 0, 0, 1.74, 2, 1.37099e+06, 1.1804e+06)
Weight(2015-05-21 00:00:00, 0, 0, 0, 0, 0, 1.43087e+06, 1.1804e+06)
Weight(2016-05-23 00:00:00, 0, 0, 0, 0, 0, 1.43087e+06, 1.21926e+06)
Weight(2016-06-16 00:00:00, 0, 0, 0, 1.53, 2, 1.71704e+06, 1.46312e+06)
Weight(2017-01-09 00:00:00, 0, 0, 0, 0, 0, 1.71704e+06, 1.6918e+06)
Weight(2017-07-21 00:00:00, 0, 0, 0, 1.58, 0, 1.71704e+06, 1.6918e+06)
Weight(2017-12-31 00:00:00, 0, 0, 0, 0, 0, 1.71704e+06, 1.6918e+06)
Weight(2018-05-21 00:00:00, 0, 0, 0, 0, 0, 1.71704e+06, 1.71702e+06)
Weight(2018-07-12 00:00:00, 0, 0, 0, 1.36, 0, 1.71704e+06, 1.71702e+06)
In [ ]: