1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| def get_best_index(performance, higher_better=True): if higher_better: return performance[performance.groupby('split_idx').idxmax()].index return performance[performance.groupby('split_idx').idxmin()].index in_best_index = get_best_index(in_sharpe)
print(in_best_index) #最优参数组 MultiIndex([(21, 35, 0), (21, 35, 1), (11, 14, 2), ,,, (45, 48, 28), (45, 48, 29)], names=['fast_window', 'slow_window', 'split_idx'])
def get_best_params(best_index, level_name): return best_index.get_level_values(level_name).to_numpy() in_best_fast_windows = get_best_params(in_best_index, 'fast_window') in_best_slow_windows = get_best_params(in_best_index, 'slow_window') in_best_window_pairs = np.array(list(zip(in_best_fast_windows, in_best_slow_windows)))
print(in_best_window_pairs) #最优参数组,去掉了时间区间信息 [[21 35] [21 35] [11 14] ,,, [45 48] [45 48]]
|