In [1]:
%matplotlib inline
%time from hikyuu.interactive.interactive import *
std::cout are redirected to python::stdout
std::cerr are redirected to python::stderr
[2019-03-27 21:33:13.813] [info] Loading market information...
[2019-03-27 21:33:13.816] [info] Loading stock type information...
[2019-03-27 21:33:13.818] [info] Loading stock information...
[2019-03-27 21:33:18.709] [info] Loading KData...
[2019-03-27 21:33:18.720] [info] Preloading all day kdata to buffer!
[2019-03-27 21:33:27.778] [info] 9.068s Loaded Data.
Wall time: 16.6 s

1 全局获取股票对象

1.1 获取股票对象

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

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

1.2 遍历所有股票

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

len(sm)
全部数量: 5517
Out[3]:
5517

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

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

In [4]:
blk = sm.getBlock("指数板块", "上证380")
for s in blk:
    if not s.valid:
        print(s)
Stock(SH, 600270, 外运发展, A股, 0, 2000-12-28 0:0:0, +infinity)

2.1 获取自定义板块

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

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

2.2 板块信息的配置

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

板块配置

3 查看权息信息

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