因子的量化选择
基于IC值 相关系数 计算方法
多因子模型得打分法,指得是选用若干能够对股票未来时间段收益产生预测作用的因子,根据每个因子在对应位置的状况给出股票在该位置上的得分,然后按照一定的权重将各个因子的得分相加,从而得到该股票各个因子的最终得分。
r
12
=
∑
k
=
1
n
(
x
1
k
−
x
ˉ
1
)
(
x
2
k
−
x
ˉ
2
)
∑
k
=
1
n
(
x
1
k
−
x
ˉ
1
)
2
(
x
2
k
−
x
ˉ
2
)
2
r_{12}=\frac{\sum_{k=1}^n(x_{1k}-\bar{x}_1)(x_{2k}-\bar{x}_2)}{\sqrt{\sum_{k=1}^{n}(x_{1k}-\bar{x}_1)^2(x_{2k}-\bar{x}_2)^2}}
r12=∑k=1n(x1k−xˉ1)2(x2k−xˉ2)2∑k=1n(x1k−xˉ1)(x2k−xˉ2)
IC值为因子与对应的下期收益率之间的关系
因子 | 下期收益率 | |
---|---|---|
股票a | 6 | 0.02 |
股票b | 1 | 0.004 |
股票c | 2 | 0.005 |
股票d | 7 | 0.007 |
import numpy as np
factor_A = [6,1,2,7]
return_profit = [0.02, 0.004, 0.005, 0.007]
corr = np.corrcoef(factor_A, return_profit)
print(corr)
[[1. 0.593641]
[0.593641 1. ]]
基于IC值 回归法 计算方法
回归法: 用该期的股票收益率对上期的因子值做回归,并用该期的因子值预测下期股票的收益率,取下期预测的收益率和下期实际收益率的相关系数
计算回归系数
import statsmodels.api as sm
import numpy as np
factor_1 = [6,1,2,7]
return_profit = [0.02,0.004,0.005,0.007]
x_ = sm.add_constant(factor_1)
model = sm.OLS(return_profit, x_)
results = model.fit()
print(results.params)
[0.003 0.0015] # 第一个为noise值,第二个为 weight值
计算预期收益率
pre_return_profit = results.params[0] + np.asarray(factor_1) * results.params[1]
array([0.012 , 0.0045, 0.006 , 0.0135])
计算预期收益率与真实收益率的相关系数
corr = np.corrcoef(pre_return_profit, return_profit)
array([[1. , 0.593641],
[0.593641, 1. ]])
基于IC值 等权因子值得合成
对因子进行合成,生成一个新的数量因子
因子A | 因子B | 因子C | 下期收益率 | |
---|---|---|---|---|
股票a | 6 | 2 | 1 | 0.02 |
股票b | 1 | 4 | 5 | 0.004 |
股票c | 2 | 8 | 6 | 0.005 |
股票d | 7 | 9 | 2 | 0.007 |
import numpy as np
factor_A = [6, 1, 2, 7]
factor_B = [2, 4, 8, 9]
factor_C = [1, 5, 6, 2]
return_profit = [0.02,0.004,0.005,0.007]
corr = np.corrcoef(factor_A, return_profit)
print("factor_A: ", corr[0][1])
corr = np.corrcoef(factor_B, return_profit)
print("factor_B: ", corr[0][1])
corr = np.corrcoef(factor_C, return_profit)
print("factor_C: ", corr[0][1])
factor_A: 0.5936410014092834
factor_B: -0.6510008283736514
factor_C: -0.7906254420727481
将两个因子组成一个新的因子
factor_total = np.asarray(factor_A) + np.asarray(factor_C) * -1
corr = np.corrcoef(return_profit, factor_total)
print(corr[0][1])
0.6985354731356994
基于成长因子的模型测试
msci_tools.py
from gm.api import *
import numpy as np
import pandas as pd
from sklearn import preprocessing
#这段代码是获取MSCI成分股,返回一个list
def read_MSCI():
symbol_list = []
f2 = open("../MSCI_tools/MSCI成分股.txt", "r")
lines = f2.readlines()
for line3 in lines:
symbol_list.append(line3.strip())
return symbol_list
#这段代码是获取返回的data数据中的对应因子的list
def get_data_value(data,factor):
result = []
for _ in data:
result.append(_[factor])
return result
def get_symbol_list(index,now):
symbol_list = get_history_constituents(index=index, start_date=now)[0].get("constituents").keys()
symbol_list_not_suspended = get_history_instruments(symbols=symbol_list, start_date=now, end_date=now)
symbol_list = [item['symbol'] for item in symbol_list_not_suspended if not item['is_suspended']]
_symbol_list = symbol_list
symbol_list = []
for _ in _symbol_list:
symbol_list.append(_)
return symbol_list
def from_df_get_df_score(df, weight, start, end=0):
"""
归一化是在列的方向对行数据进行操作:比如调用sklearn.preprocessing里的MinMaxscaler;
标准化是在行的方向对列数据进行操作:比如调用sklearn.preprocessing里的Normalizer;
因为是对 每行 求和,这里建议对建立的矩阵使用MinMaxscaler
"""
if end == 0:
df_factor = df.iloc[:, start:]
else:
df_factor = df.iloc[:, start:end]
df_factor = np.asmatrix(df_factor)
# 先进行列归一化,然后在对每行进行标准化处理
df_factor = preprocessing.MinMaxScaler().fit_transform(df_factor)
df_factor = preprocessing.Normalizer().fit_transform(df_factor)
_weight = []
for _ in weight:
_weight.append([_])
weight_mat = np.asmatrix(_weight) # 这里设置的beta值偏低,选择不太活跃的股
res = np.dot(df_factor, weight_mat)
df["score"] = (res)
return df
def from_df_get_symbol_list_by_score(df,weight,start,end=0,ascending=True):
"""
归一化是在列的方向对行数据进行操作:比如调用sklearn.preprocessing里的MinMaxscaler;
标准化是在行的方向对列数据进行操作:比如调用sklearn.preprocessing里的Normalizer;
因为是对 每行 求和,这里建议对建立的矩阵使用MinMaxscaler
"""
if end == 0:
df_factor = df.iloc[:, start:]
else:
df_factor = df.iloc[:, start:end]
df_factor = np.asmatrix(df_factor)
#先进行列归一化,然后在对每行进行标准化处理
df_factor = preprocessing.MinMaxScaler().fit_transform(df_factor)
df_factor = preprocessing.Normalizer().fit_transform(df_factor)
_weight = []
for _ in weight:
_weight.append([_])
weight_mat = np.asmatrix(_weight)
res = np.dot(df_factor, weight_mat)
df["score"] = (res)
df.index = df.score
df = df.sort_index(ascending=ascending) #这里是将最后的趋势有小到大排列
_symbol_list = df["symbol"].values
symbol_list = []
for _ in _symbol_list:
symbol_list.append(_)
return symbol_list
# coding=utf-8
from __future__ import print_function, absolute_import
from gm.api import *
import os
import msci_tools as tools
import pandas as pd
import numpy as np
from sklearn import preprocessing
def growth_model(index,now):
symbol_list = tools.get_symbol_list(index,now)
last_day = get_previous_trading_date("SHSE",now)
day_time = last_day
#symbol_list = tools.read_MSCI()
df = pd.DataFrame([])
df["symbol"] = symbol_list
df["EBITG"] = -999
df["NPG"] = -999
df["TAG"] = -999 #MPG取不到,用TAG代替
df["GPG"] = -999
df["OPG"] = -999
df["OCG"] = -999
#求出EBITG
for number in range(len(symbol_list)):
try:
_df = get_fundamentals_n(table='deriv_finance_indicator', symbols=symbol_list[number],end_date=day_time, count=2,fields="EBITMARGIN")
now_EBITMARGIN = _df[0]["EBITMARGIN"]
last_EBITMARGIN = _df[1]["EBITMARGIN"]
EBITG = ((now_EBITMARGIN-last_EBITMARGIN)/last_EBITMARGIN)
df.iloc[number,1] = EBITG
except:df.iloc[number,1] = -999
#求NPG
_df = get_fundamentals(table='deriv_finance_indicator', symbols=symbol_list, start_date=day_time,end_date=day_time, fields="NPGRT",df=True)
if len(_df) == len(symbol_list):
df["NPG"] = _df["NPGRT"]
else:
for number in range(len(symbol_list)):
try:
_df = get_fundamentals(table='deriv_finance_indicator', symbols=symbol_list[number], start_date=day_time,
end_date=day_time, fields="NPGRT")
_NPG = tools.get_data_value(_df,"NPGRT")
df.iloc[number, 2] = _NPG[0]
except:
df.iloc[number, 2] = -999
#求出TAG
_df = get_fundamentals(table='deriv_finance_indicator', symbols=symbol_list, start_date=day_time,end_date=day_time, fields="TAGRT",df=True)
if len(_df) == len(symbol_list):
df["TAG"] = _df["TAGRT"]
else:
for number in range(len(symbol_list)):
try:
_df = get_fundamentals(table='deriv_finance_indicator', symbols=symbol_list[number], start_date=day_time,
end_date=day_time, fields="TAGRT")
_NPG = tools.get_data_value(_df,"TAGRT")
df.iloc[number, 2] = _NPG[0]
except:
df.iloc[number, 2] = -999
#求GPG
for number in range(len(symbol_list)):
try:
_df = get_fundamentals_n(table='deriv_finance_indicator', symbols=symbol_list[number],end_date=day_time, count=2,fields="OPGPMARGIN")
now_EBITMARGIN = _df[0]["OPGPMARGIN"]
last_EBITMARGIN = _df[1]["OPGPMARGIN"]
EBITG = ((now_EBITMARGIN-last_EBITMARGIN)/last_EBITMARGIN)
df.iloc[number,4] = EBITG
except:df.iloc[number,4] = -999
#求OPG
for number in range(len(symbol_list)):
try:
_df = get_fundamentals_n(table='deriv_finance_indicator', symbols=symbol_list[number],end_date=day_time, count=2,fields="OPPRORT")
now_EBITMARGIN = _df[0]["OPPRORT"]
last_EBITMARGIN = _df[1]["OPPRORT"]
EBITG = ((now_EBITMARGIN-last_EBITMARGIN)/last_EBITMARGIN)
df.iloc[number,5] = EBITG
except:df.iloc[number,5] = -999
#求OCG
for number in range(len(symbol_list)):
try:
_df = get_fundamentals_n(table='deriv_finance_indicator', symbols=symbol_list[number],end_date=day_time, count=2,fields="NCFPS")
now_EBITMARGIN = _df[0]["NCFPS"]
last_EBITMARGIN = _df[1]["NCFPS"]
EBITG = ((now_EBITMARGIN-last_EBITMARGIN)/last_EBITMARGIN)
df.iloc[number,6] = EBITG
except:df.iloc[number,6] = -999
df = df.dropna()
df_factor = df.iloc[:,1:]
df_factor = np.asmatrix(df_factor)
#先进行列归一化,然后在对每行进行标准化处理
df_factor = preprocessing.MinMaxScaler().fit_transform(df_factor)
weight = [[-1],[-1],[-1],[-1],[-1],[-1]]
weight_mat = np.asmatrix(weight)
res = np.dot(df_factor, weight_mat)
df["score"] = (res)
df = (df.sort_values(["score"]))
print(df)
symbol_list = []
for _ in df["symbol"].values:
symbol_list.append(_)
return symbol_list
# 策略中必须有init方法
def init(context):
schedule(schedule_func=algo, date_rule='1d', time_rule='09:31:00')
context.index = "SHSE.000016"
context.num = 5
def algo(context):
now = context.now
last_day = get_previous_trading_date("SHSE", now)
order_close_all()
"""核心选股代码"""
_symbol_list = growth_model(context.index, now)
"""核心选股代码"""
symbol_list = []
for symbol in _symbol_list:
symbol_list.append(symbol)
# 取前多少个标的
target_list = symbol_list[:context.num] # 无黑名单存在,卖掉以后又可以买回
for symbol in target_list:
order_target_percent(symbol=symbol, percent=1. / context.num, order_type=OrderType_Market, position_side=PositionSide_Long)
def on_backtest_finished(context, indicator):
print(indicator)
print("finish...............")
if __name__ == '__main__':
run(strategy_id='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
filename='main.py',
mode=MODE_BACKTEST,
token='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
backtest_start_time="2016-01-10 09:30:00",
backtest_end_time='2018-06-10 15:00:00',
backtest_initial_cash=10000000,
backtest_adjust=ADJUST_PREV)
代码流畅解读
获取指数成分股历史数据
from gm.api import *
set_token("xxxxxxxxxxxxxxxxxxxxx")
index = "SHSE.000016"
now = "2016-01-11"
symbol_list = get_history_constituents(index=index, start_date=now)
print(symbol_list)
[{'trade_date': datetime.datetime(2016, 1, 29, 0, 0, tzinfo=tzfile('PRC')), 'constituents': {'SHSE.600111': 0.75, 'SHSE.601901': 0.8299999833106995, 'SHSE.600030': 3.4100000858306885, 'SHSE.600050': 1.0299999713897705, 'SHSE.601390': 1.3300000429153442, 'SHSE.601398': 2.640000104904175, 'SHSE.601166': 5.760000228881836, 'SHSE.600150': 0.46000000834465027, 'SHSE.601669': 0.7799999713897705, 'SHSE.600958': 0.5699999928474426, 'SHSE.600887': 2.4200000762939453, 'SHSE.601857': 1.0800000429153442, 'SHSE.601211': 0.7900000214576721, 'SHSE.600018': 0.44999998807907104, 'SHSE.601601': 2.190000057220459, 'SHSE.600109': 0.6100000143051147, 'SHSE.601668': 2.299999952316284, 'SHSE.601818': 1.7000000476837158, 'SHSE.600104': 1.840000033378601, 'SHSE.600010': 0.8600000143051147, 'SHSE.600028': 1.3799999952316284, 'SHSE.600585': 0.7900000214576721, 'SHSE.600837': 2.930000066757202, 'SHSE.600000': 4.710000038146973, 'SHSE.601169': 2.8299999237060547, 'SHSE.601088': 0.7900000214576721, 'SHSE.601985': 0.9900000095367432, 'SHSE.600016': 7.590000152587891, 'SHSE.600519': 3.009999990463257, 'SHSE.601336': 0.6899999976158142, 'SHSE.601186': 1.0399999618530273, 'SHSE.601766': 2.7200000286102295, 'SHSE.600795': 0.8500000238418579, 'SHSE.600893': 0.8299999833106995, 'SHSE.601328': 3.7699999809265137, 'SHSE.600637': 1.409999966621399, 'SHSE.601989': 1.7000000476837158, 'SHSE.601288': 3.4200000762939453, 'SHSE.601688': 1.4199999570846558, 'SHSE.601006': 1.2100000381469727, 'SHSE.601800': 0.49000000953674316, 'SHSE.601318': 9.770000457763672, 'SHSE.601998': 0.5099999904632568, 'SHSE.601628': 1.0199999809265137, 'SHSE.600036': 4.619999885559082, 'SHSE.600015': 1.5199999809265137, 'SHSE.600518': 1.2000000476837158, 'SHSE.600048': 1.6799999475479126, 'SHSE.600999': 1.2999999523162842, 'SHSE.601988': 2.0299999713897705}},'SHSE.601229': 1.1799999475479126, 'SHSE.600340': 0.9399999976158142, 'SHSE.600276': 3.700000047683716, 'SHSE.601800': 0.46000000834465027, 'SHSE.601318': 17.040000915527344, 'SHSE.601628': 0.8799999952316284, 'SHSE.600031': 1.4800000190734863, 'SHSE.600036': 6.739999771118164, 'SHSE.600309': 1.2300000190734863, 'SHSE.601888': 1.5800000429153442, 'SHSE.600029': 0.44999998807907104, 'SHSE.600048': 1.809999942779541, 'SHSE.601988': 1.399999976158142, 'SHSE.603259': 0.17000000178813934, 'SHSE.600030': 3.2699999809265137, 'SHSE.601111': 0.47999998927116394, 'SHSE.600050': 0.9900000095367432, 'SHSE.601138': 0.28999999165534973, 'SHSE.601390': 0.8500000238418579, 'SHSE.601398': 2.1700000762939453, 'SHSE.601166': 4.96999979019165, 'SHSE.601319': 0.17000000178813934, 'SHSE.600019': 1.0199999809265137, 'SHSE.600887': 3.4000000953674316, 'SHSE.600690': 1.100000023841858, 'SHSE.601857': 0.9399999976158142, 'SHSE.601211': 1.4600000381469727, 'SHSE.601601': 2.1700000762939453, 'SHSE.601668': 2.2100000381469727, 'SHSE.600703': 0.5, 'SHSE.600104': 1.559999942779541, 'SHSE.601818': 1.1200000047683716, 'SHSE.600028': 1.2599999904632568, 'SHSE.600585': 1.409999966621399, 'SHSE.600000': 2.490000009536743, 'SHSE.600837': 2.0, 'SHSE.601088': 1.1299999952316284, 'SHSE.603993': 0.46000000834465027}},
{'trade_date': datetime.datetime(2020, 10, 30, 0, 0, tzinfo=tzfile('PRC')), 'constituents': {'SHSE.601318': 13.010000228881836, 'SHSE.603160': 0.47999998927116394, 'SHSE.600000': 1.6799999475479126, 'SHSE.600196': 1.0099999904632568, 'SHSE.601138': 0.41999998688697815, 'SHSE.600276': 5.090000152587891, 'SHSE.601688': 1.850000023841858, 'SHSE.601628': 1.1799999475479126, 'SHSE.601088': 0.8500000238418579, 'SHSE.600028': 0.800000011920929, 'SHSE.601857': 0.6100000143051147, 'SHSE.601888': 3.0, 'SHSE.600519': 12.949999809265137, 'SHSE.601818': 0.9599999785423279, 'SHSE.601066': 0.3400000035762787, 'SHSE.601398': 2.6600000858306885, 'SHSE.600547': 0.6700000166893005, 'SHSE.601989': 0.5899999737739563, 'SHSE.601328': 1.9199999570846558, 'SHSE.601288': 1.399999976158142, 'SHSE.600104': 1.25, 'SHSE.601336': 0.8299999833106995, 'SHSE.601012': 3.0999999046325684, 'SHSE.600703': 0.7699999809265137, 'SHSE.601166': 3.4200000762939453, 'SHSE.603259': 1.7999999523162842, 'SHSE.601319': 0.2199999988079071, 'SHSE.600588': 1.0800000429153442, 'SHSE.601668': 1.649999976158142, 'SHSE.601658': 0.1899999976158142, 'SHSE.600309': 1.899999976158142, 'SHSE.600016': 1.7300000190734863, 'SHSE.600585': 1.8799999952316284, 'SHSE.600690': 1.4500000476837158, 'SHSE.600745': 0.5799999833106995, 'SHSE.601816': 0.25, 'SHSE.603993': 0.4300000071525574, 'SHSE.600887': 3.7200000286102295, 'SHSE.601211': 1.2799999713897705, 'SHSE.601988': 1.0299999713897705, 'SHSE.601601': 1.340000033378601, 'SHSE.600009': 0.9800000190734863, 'SHSE.601186': 0.5899999737739563, 'SHSE.600837': 2.0899999141693115, 'SHSE.600048': 1.7000000476837158, 'SHSE.600030': 3.759999990463257, 'SHSE.600031': 2.359999895095825, 'SHSE.601236': 0.10999999940395355, 'SHSE.600036': 6.340000152587891, 'SHSE.600050': 0.6800000071525574}}
symbol_list = get_history_constituents(index=index, start_date=now)[0].get("constituents").keys()
symbol_list
dict_keys(['SHSE.600795', 'SHSE.601288', 'SHSE.601989', 'SHSE.601186', 'SHSE.601688', 'SHSE.601766', 'SHSE.601006', 'SHSE.601328', 'SHSE.600893', 'SHSE.600637', 'SHSE.601800', 'SHSE.601318', 'SHSE.601998', 'SHSE.601628', 'SHSE.600036', 'SHSE.600999', 'SHSE.600015', 'SHSE.600111', 'SHSE.601901', 'SHSE.600030', 'SHSE.600518', 'SHSE.600048', 'SHSE.600050', 'SHSE.601390', 'SHSE.601988', 'SHSE.601398', 'SHSE.600887', 'SHSE.601857', 'SHSE.601211', 'SHSE.600018', 'SHSE.601668', 'SHSE.601166', 'SHSE.600150', 'SHSE.600104', 'SHSE.601669', 'SHSE.600958', 'SHSE.600010', 'SHSE.601601', 'SHSE.600109', 'SHSE.601818', 'SHSE.601169', 'SHSE.601088', 'SHSE.600028', 'SHSE.601985', 'SHSE.600585', 'SHSE.600837', 'SHSE.600000', 'SHSE.600016', 'SHSE.600519', 'SHSE.601336'])
交易标的历史信息数据
symbol_list_not_suspended = get_history_instruments(symbols=symbol_list, start_date=now, end_date=now)
pprint.pprint(symbol_list_not_suspended)
[{'symbol': 'SHSE.600000', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 17.489999771118164, 'upper_limit': 19.24, 'lower_limit': 15.74, 'adj_factor': 8.1856186501361, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600010', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 3.549999952316284, 'upper_limit': 3.91, 'lower_limit': 3.2, 'adj_factor': 5.9498093244834, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600015', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 10.829999923706055, 'upper_limit': 11.91, 'lower_limit': 9.75, 'adj_factor': 3.3184785878215, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600016', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 8.699999809265137, 'upper_limit': 9.57, 'lower_limit': 7.83, 'adj_factor': 19.3298282201282, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600018', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 5.829999923706055, 'upper_limit': 6.41, 'lower_limit': 5.25, 'adj_factor': 1.2638119476271, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600028', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 4.769999980926514, 'upper_limit': 5.25, 'lower_limit': 4.29, 'adj_factor': 2.4729014482433, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600030', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 16.829999923706055, 'upper_limit': 18.51, 'lower_limit': 15.15, 'adj_factor': 5.0094354994803, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600036', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 16.809999465942383, 'upper_limit': 18.49, 'lower_limit': 15.13, 'adj_factor': 4.3533661798053, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600048', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 9.489999771118164, 'upper_limit': 10.44, 'lower_limit': 8.54, 'adj_factor': 17.8182161581631, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600050', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 5.460000038146973, 'upper_limit': 6.01, 'lower_limit': 4.91, 'adj_factor': 1.5337947384257, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600104', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 19.510000228881836, 'upper_limit': 21.46, 'lower_limit': 17.56, 'adj_factor': 7.4022061390352, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600109', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 14.020000457763672, 'upper_limit': 15.42, 'lower_limit': 12.62, 'adj_factor': 8.4306938926756, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600111', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 12.899999618530273, 'upper_limit': 14.19, 'lower_limit': 11.61, 'adj_factor': 19.4466634379578, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600150', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 31.600000381469727, 'upper_limit': 34.76, 'lower_limit': 28.44, 'adj_factor': 3.2781078673277, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600518', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 14.640000343322754, 'upper_limit': 16.1, 'lower_limit': 13.18, 'adj_factor': 43.5175370923769, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600519', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 204.6300048828125, 'upper_limit': 225.09, 'lower_limit': 184.17, 'adj_factor': 7.0437697482282, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600585', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 16.110000610351562, 'upper_limit': 17.72, 'lower_limit': 14.5, 'adj_factor': 4.0218004541918, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600637', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 31.600000381469727, 'upper_limit': 34.76, 'lower_limit': 28.44, 'adj_factor': 3.5186924188407, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600795', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 3.569999933242798, 'upper_limit': 3.93, 'lower_limit': 3.21, 'adj_factor': 231.29941465739, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600837', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 13.510000228881836, 'upper_limit': 14.86, 'lower_limit': 12.16, 'adj_factor': 20.8395181771412, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600887', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 14.920000076293945, 'upper_limit': 16.41, 'lower_limit': 13.43, 'adj_factor': 76.6532450996154, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600893', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 38.43000030517578, 'upper_limit': 42.27, 'lower_limit': 34.59, 'adj_factor': 3.5526583415026, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600958', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 19.540000915527344, 'upper_limit': 21.49, 'lower_limit': 17.59, 'adj_factor': 1.009833617686, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.600999', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 18.510000228881836, 'upper_limit': 20.36, 'lower_limit': 16.66, 'adj_factor': 1.4603986779805, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601006', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 8.220000267028809, 'upper_limit': 9.04, 'lower_limit': 7.4, 'adj_factor': 1.4386573805349, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601088', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 15.619999885559082, 'upper_limit': 17.18, 'lower_limit': 14.06, 'adj_factor': 1.2960255506844, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601166', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 16.440000534057617, 'upper_limit': 18.08, 'lower_limit': 14.8, 'adj_factor': 3.5294826376043, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601169', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 10.239999771118164, 'upper_limit': 11.26, 'lower_limit': 9.22, 'adj_factor': 2.0471701619805, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601186', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 11.449999809265137, 'upper_limit': 12.6, 'lower_limit': 10.31, 'adj_factor': 1.1351432828151, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601211', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 21.040000915527344, 'upper_limit': 23.14, 'lower_limit': 18.94, 'adj_factor': 1.0049504950495, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601288', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 3.1600000858306885, 'upper_limit': 3.48, 'lower_limit': 2.84, 'adj_factor': 1.2860928165514, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601318', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 33.939998626708984, 'upper_limit': 37.33, 'lower_limit': 30.55, 'adj_factor': 2.2028310552555, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601328', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 6.03000020980835, 'upper_limit': 6.63, 'lower_limit': 5.43, 'adj_factor': 1.5223302928608, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601336', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 45.380001068115234, 'upper_limit': 49.92, 'lower_limit': 40.84, 'adj_factor': 1.0268004967766, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601390', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 9.300000190734863, 'upper_limit': 10.23, 'lower_limit': 8.37, 'adj_factor': 1.0967888497906, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601398', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 4.460000038146973, 'upper_limit': 4.91, 'lower_limit': 4.01, 'adj_factor': 1.481558848256, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601601', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 26.549999237060547, 'upper_limit': 29.21, 'lower_limit': 23.9, 'adj_factor': 1.1477863013836, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601628', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 25.440000534057617, 'upper_limit': 27.98, 'lower_limit': 22.9, 'adj_factor': 1.1428356749041, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601668', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 5.900000095367432, 'upper_limit': 6.49, 'lower_limit': 5.31, 'adj_factor': 1.160238484838, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601669', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 7.010000228881836, 'upper_limit': 7.71, 'lower_limit': 6.31, 'adj_factor': 1.1230000464661, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601688', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 16.479999542236328, 'upper_limit': 18.13, 'lower_limit': 14.83, 'adj_factor': 1.0812416980157, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601766', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 11.010000228881836, 'upper_limit': 12.11, 'lower_limit': 9.91, 'adj_factor': 1.1205745897563, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601800', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 11.489999771118164, 'upper_limit': 12.64, 'lower_limit': 10.34, 'adj_factor': 1.1553621128414, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601818', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 4.03000020980835, 'upper_limit': 4.43, 'lower_limit': 3.63, 'adj_factor': 1.2139966565942, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601857', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 7.989999771118164, 'upper_limit': 8.79, 'lower_limit': 7.19, 'adj_factor': 1.2599456640085, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601901', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 8.239999771118164, 'upper_limit': 9.06, 'lower_limit': 7.42, 'adj_factor': 1.019022046124, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601985', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 8.4399995803833, 'upper_limit': 9.28, 'lower_limit': 7.6, 'adj_factor': 1.0, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601988', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 3.799999952316284, 'upper_limit': 4.18, 'lower_limit': 3.42, 'adj_factor': 1.490734777881, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601989', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 8.569999694824219, 'upper_limit': 9.43, 'lower_limit': 7.71, 'adj_factor': 1.6786728874306, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}, {'symbol': 'SHSE.601998', 'sec_level': 1, 'multiplier': 1.0, 'margin_ratio': 1.0, 'pre_close': 6.53000020980835, 'upper_limit': 7.18, 'lower_limit': 5.88, 'adj_factor': 1.2704364624812, 'info': {'symbol': '', 'sec_type': 0, 'exchange': '', 'sec_id': '', 'sec_name': '', 'sec_abbr': '', 'sec_asset': '', 'price_tick': 0.0, 'trade_n': 0, 'board': 0, 'option_type': '', 'call_or_put': '', 'underlying_symbol': '', 'is_strike_price_adjusted': False, 'listed_date': None, 'delisted_date': None}, 'is_suspended': 0, 'settle_price': 0.0, 'position': 0, 'pre_settle': 0.0, 'strike_price': 0.0, 'trade_date': datetime.datetime(2016, 1, 11, 0, 0, tzinfo=tzfile('PRC'))}]
symbol_list = [item['symbol'] for item in symbol_list_not_suspended if not item['is_suspended']]
symbol_list
['SHSE.600000','SHSE.600010','SHSE.600015','SHSE.600016','SHSE.600018','SHSE.600028','SHSE.600030','SHSE.600036','SHSE.600048','SHSE.600050','SHSE.600104','SHSE.600109','SHSE.600111','SHSE.600150','SHSE.600518','SHSE.600519','SHSE.600585','SHSE.600637','SHSE.600795','SHSE.600837','SHSE.600887','SHSE.600893','SHSE.600958','SHSE.600999','SHSE.601006','SHSE.601088','SHSE.601166','SHSE.601169','SHSE.601186','SHSE.601211','SHSE.601288','SHSE.601318','SHSE.601328','SHSE.601336','SHSE.601390','SHSE.601398','SHSE.601601','SHSE.601628','SHSE.601668','SHSE.601669','SHSE.601688','SHSE.601766','SHSE.601800','SHSE.601818','SHSE.601857','SHSE.601901','SHSE.601985','SHSE.601988','SHSE.601989','SHSE.601998']
_symbol_list = symbol_list
symbol_list = []
for _ in _symbol_list:
symbol_list.append(_)
symbol_list
['SHSE.600000',
'SHSE.600010',
'SHSE.600015',
'SHSE.600016',
'SHSE.600018',
'SHSE.600028',
'SHSE.600030',
'SHSE.600036',
'SHSE.600048',
'SHSE.600050',
'SHSE.600104',
'SHSE.600109',
'SHSE.600111',
'SHSE.600150',
'SHSE.600518',
'SHSE.600519',
'SHSE.600585',
'SHSE.600637',
'SHSE.600795',
'SHSE.600837',
'SHSE.600887',
'SHSE.600893',
'SHSE.600958',
'SHSE.600999',
'SHSE.601006',
'SHSE.601088',
'SHSE.601166',
'SHSE.601169',
'SHSE.601186',
'SHSE.601211',
'SHSE.601288',
'SHSE.601318',
'SHSE.601328',
'SHSE.601336',
'SHSE.601390',
'SHSE.601398',
'SHSE.601601',
'SHSE.601628',
'SHSE.601668',
'SHSE.601669',
'SHSE.601688',
'SHSE.601766',
'SHSE.601800',
'SHSE.601818',
'SHSE.601857',
'SHSE.601901',
'SHSE.601985',
'SHSE.601988',
'SHSE.601989',
'SHSE.601998']
定义分析事项
df = pd.DataFrame([])
df["symbol"] = symbol_list
df["EBITG"] = -999
df["NPG"] = -999
df["TAG"] = -999 #MPG取不到,用TAG代替
df["GPG"] = -999
df["OPG"] = -999
df["OCG"] = -999
df
获取财务数据
print("now_time: " + now)
last_day = get_previous_trading_date("SHSE",now)
day_time = last_day
print("last_time: "+day_time)
now_time: 2016-01-11
last_time: 2016-01-08
计算EBIT
EBITMARGIN
息税折旧摊销前利润率
number = 0
_df = get_fundamentals_n(table='deriv_finance_indicator', symbols=symbol_list[number],end_date=day_time, count=2,fields="EBITMARGIN")
_df
[{'symbol': 'SHSE.600000',
'pub_date': datetime.datetime(2016, 4, 7, 0, 0, tzinfo=tzfile('PRC')),
'end_date': datetime.datetime(2015, 12, 31, 0, 0, tzinfo=tzfile('PRC')),
'EBITMARGIN': 0.0},
{'symbol': 'SHSE.600000',
'pub_date': datetime.datetime(2015, 10, 30, 0, 0, tzinfo=tzfile('PRC')),
'end_date': datetime.datetime(2015, 9, 30, 0, 0, tzinfo=tzfile('PRC')),
'EBITMARGIN': 0.0}]
try:
_df = get_fundamentals_n(table='deriv_finance_indicator', symbols=symbol_list[number],end_date=day_time, count=2,fields="EBITMARGIN")
now_EBITMARGIN = _df[0]["EBITMARGIN"]
last_EBITMARGIN = _df[1]["EBITMARGIN"]
EBITG = ((now_EBITMARGIN-last_EBITMARGIN)/last_EBITMARGIN)
df.iloc[number,1] = EBITG # pandas DataFrame 第0行第1列赋值
except:df.iloc[number,1] = -999
计算NPG
NPGRT
归属母公司净利润增长率
_df = get_fundamentals(table='deriv_finance_indicator', symbols=symbol_list, start_date=day_time,end_date=day_time, fields="NPGRT",df=True)
for col in _df.select_dtypes(['datetimetz']).columns:
_df[col] = _df[col].dt.tz_convert(None)
_df.to_excel("NPGRT.xls")
计算TAG
TAGRT
营业总收入增长率
_df = get_fundamentals(table='deriv_finance_indicator', symbols=symbol_list, start_date=day_time,end_date=day_time, fields="TAGRT",df=True)
for col in _df.select_dtypes(['datetimetz']).columns:
_df[col] = _df[col].dt.tz_convert(None)
_df.to_excel("TAGRT.xls")
计算GPG
OPGPMARGIN
营业毛利润
_df = get_fundamentals_n(table='deriv_finance_indicator', symbols=symbol_list[number],end_date=day_time, count=2,fields="OPGPMARGIN")
_df
[{'symbol': 'SHSE.600000',
'pub_date': datetime.datetime(2016, 4, 7, 0, 0, tzinfo=tzfile('PRC')),
'end_date': datetime.datetime(2015, 12, 31, 0, 0, tzinfo=tzfile('PRC')),
'OPGPMARGIN': 66067001344.0},
{'symbol': 'SHSE.600000',
'pub_date': datetime.datetime(2015, 10, 30, 0, 0, tzinfo=tzfile('PRC')),
'end_date': datetime.datetime(2015, 9, 30, 0, 0, tzinfo=tzfile('PRC')),
'OPGPMARGIN': 48361000960.0}]
for number in range(len(symbol_list)):
try:
_df = get_fundamentals_n(table='deriv_finance_indicator', symbols=symbol_list[number],end_date=day_time, count=2,fields="OPGPMARGIN")
now_EBITMARGIN = _df[0]["OPGPMARGIN"]
last_EBITMARGIN = _df[1]["OPGPMARGIN"]
EBITG = ((now_EBITMARGIN-last_EBITMARGIN)/last_EBITMARGIN)
df.iloc[number,4] = EBITG
except:df.iloc[number,4] = -999
计算OPG
OPPRORT
营业利润率
_df = get_fundamentals_n(table='deriv_finance_indicator', symbols=symbol_list[number],end_date=day_time, count=2,fields="OPPRORT")
_df
[{'symbol': 'SHSE.601998',
'pub_date': datetime.datetime(2016, 3, 24, 0, 0, tzinfo=tzfile('PRC')),
'end_date': datetime.datetime(2015, 12, 31, 0, 0, tzinfo=tzfile('PRC')),
'OPPRORT': 37.64590072631836},
{'symbol': 'SHSE.601998',
'pub_date': datetime.datetime(2015, 10, 28, 0, 0, tzinfo=tzfile('PRC')),
'end_date': datetime.datetime(2015, 9, 30, 0, 0, tzinfo=tzfile('PRC')),
'OPPRORT': 40.697792053222656}]
for number in range(len(symbol_list)):
try:
_df = get_fundamentals_n(table='deriv_finance_indicator', symbols=symbol_list[number],end_date=day_time, count=2,fields="OPPRORT")
now_EBITMARGIN = _df[0]["OPPRORT"]
last_EBITMARGIN = _df[1]["OPPRORT"]
EBITG = ((now_EBITMARGIN-last_EBITMARGIN)/last_EBITMARGIN)
df.iloc[number,5] = EBITG
except:df.iloc[number,5] = -999
计算OCG
NCFPS
每股现金流量净额
_df = get_fundamentals_n(table='deriv_finance_indicator', symbols=symbol_list[number],end_date=day_time, count=2,fields="NCFPS")
_df
[{'symbol': 'SHSE.601998',
'pub_date': datetime.datetime(2016, 3, 24, 0, 0, tzinfo=tzfile('PRC')),
'end_date': datetime.datetime(2015, 12, 31, 0, 0, tzinfo=tzfile('PRC')),
'NCFPS': -0.04109499976038933},
{'symbol': 'SHSE.601998',
'pub_date': datetime.datetime(2015, 10, 28, 0, 0, tzinfo=tzfile('PRC')),
'end_date': datetime.datetime(2015, 9, 30, 0, 0, tzinfo=tzfile('PRC')),
'NCFPS': -0.1751980036497116}]
for number in range(len(symbol_list)):
try:
_df = get_fundamentals_n(table='deriv_finance_indicator', symbols=symbol_list[number],end_date=day_time, count=2,fields="NCFPS")
now_EBITMARGIN = _df[0]["NCFPS"]
last_EBITMARGIN = _df[1]["NCFPS"]
EBITG = ((now_EBITMARGIN-last_EBITMARGIN)/last_EBITMARGIN)
df.iloc[number,6] = EBITG
except:df.iloc[number,6] = -999
结果汇总
对多因子评分并排序
df = df.dropna() #滤除所有包含NaN
df_factor = df.iloc[:,1:] # 取第二列之后的数据用于计算
df_factor = np.asmatrix(df_factor) # 将每行元素转成矩阵
#先进行列归一化,然后在对每行进行标准化处理
df_factor = preprocessing.MinMaxScaler().fit_transform(df_factor)
# 不仅计算训练数据的均值和方差,还会基于计算出来的均值和方差来转换训练数据,从而把数据转换成标准的正太分布
weight = [[-1],[-1],[-1],[-1],[-1],[-1]]
weight_mat = np.asmatrix(weight)
res = np.dot(df_factor, weight_mat) # 矩阵相乘
df["score"] = (res)
df = (df.sort_values(["score"]))