若N天後收盤價 > 目前收盤價,趨勢為正
若N天後收盤價 < 目前收盤價,趨勢為負
優點:
缺點:
若N天後收盤價 > 目前收盤價 + K%,趨勢為正
若N天後收盤價 < 目前收盤價 - K%,趨勢為負
中間值代表不漲不跌
優點:
缺點:
若N天最高點 > 目前收盤價 + K%,趨勢為正
若N天最低點 < 目前收盤價 - K%,趨勢為負
中間值代表不漲不跌
優點:
缺點:
若N天中某一天 > 目前收盤價 + K%,趨勢為正
若N天中某一天 < 目前收盤價 - K%,趨勢為負
優點:
缺點:
data_df = load_stock(stock_index, start_year=2011, end_year=2021)
shift = {}
for i in range(0, 31):
shift[i] = data_df.loc[:, "Close"].shift(-i)
close30_df = pd.DataFrame(shift).dropna()
Close_Low = close30_df.min(1)
Close_High = close30_df.max(1)
Close_Mean = close30_df.mean(1)
Close_Std = close30_df.std(1)
thresold = 3
tag = {}
for i in range(1, 31):
if i == 1:
up = close30_df[i] > close30_df[0] + thresold * Close_Std
down = close30_df[i] < close30_df[0] - thresold * Close_Std
tag[i] = 1 * up + (-1) * down
else:
up = close30_df[i] > close30_df[0] + thresold * Close_Std
down = close30_df[i] < close30_df[0] - thresold * Close_Std
tag[i] = np.clip(
(tag[i - 1] * 10) + (1 * up + (-1) * down), a_min=-1, a_max=1
)
K = 1 std,對趨勢估計保守,傾向停利停損
K = 3 std,對趨勢估計激進,傾向高報酬