宽客秀

宽客秀

Quant.Show的Web3站点,Archives from quant.show

【コード例】最高の収益率を持つ指数を取得する

この記事では、次の機能を実装します:複数の業界指数(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)]

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。