本文程式實現以下功能:獲取若干個行業指數(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)]