本文代码实现以下功能:获取若干个行业指数(index_list)过去 20 个交易日的收益率,并选取了收益率最高的指数,主要是使用了 numpy 的 argmax 函数的功能。所有代码基于 JoinQuant 编译测试。
import numpy as np
index_list = ['000912.XSHG', #消费
'000913.XSHG', #医药
'000908.XSHG',
'000914.XSHG',
'000915.XSHG',
'000922.XSHG']
return_index = []
for index in index_list:
return_index_his = attribute_history(index, 20, unit='1d',
fields=['close'],skip_paused=True,
df=True, fq='pre')
return_index_his=return_index_his['close'].values
return_index.append(return_index_his[-1] / return_index_his[0] - 1)
sector = index_list[np.argmax(return_index)]