Add some classifier code
This commit is contained in:
+23
-8
@@ -281,13 +281,18 @@ class ChanLunClassifier:
|
||||
# 使用ChanLun获取bi_list
|
||||
bi_list = self.chan.cal_bi_list(self.chan.get_klc_list(dataframe))
|
||||
klc_list = self.chan.get_klc_list(dataframe)
|
||||
seg_list = self.chan.get_seg_list(bi_list)
|
||||
# 筛选方向为UP的bi的起始klc
|
||||
feature_data = []
|
||||
labels = []
|
||||
|
||||
bi_index = 0
|
||||
sample_list = []
|
||||
for klc in klc_list:
|
||||
if bi_index == len(bi_list):
|
||||
if klc.fx != Chan_FX_TYPE.UNKNOWN:
|
||||
sample_list.append(klc)
|
||||
for klc in sample_list:
|
||||
if bi_index >= len(bi_list):
|
||||
bi_index = len(bi_list) - 1
|
||||
bi = bi_list[bi_index]
|
||||
if klc.end_klu and bi.end_klc and klc.start_klu.index >= bi.start_klc.start_klu.index and klc.end_klu.index <= bi.end_klc.end_klu.index:
|
||||
@@ -306,9 +311,11 @@ class ChanLunClassifier:
|
||||
|
||||
# 判断这个bi是否赚钱(这里简单定义为:如果bi的结束价格高于起始价格,则标记为1,否则为0)
|
||||
# 这个标签定义可以根据实际需求修改
|
||||
if bi.start_klc.index == klc.index:
|
||||
seg = seg_list[bi_index]
|
||||
if bi.start_klc.index == klc.index and bi.dir == Chan_BI_DIR.UP:
|
||||
#if klc.index == seg.start_bi.start_klc.index and seg.dir == Chan_SEG_DIR.UP:
|
||||
label = 1
|
||||
bi_index += 1
|
||||
bi_index += 2
|
||||
else:
|
||||
label = 0
|
||||
|
||||
@@ -325,12 +332,17 @@ class ChanLunClassifier:
|
||||
# 使用ChanLun获取bi_list
|
||||
bi_list = self.chan.cal_bi_list(self.chan.get_klc_list(dataframe))
|
||||
klc_list = self.chan.get_klc_list(dataframe)
|
||||
seg_list = self.chan.get_seg_list(bi_list)
|
||||
# 筛选方向为UP的bi的起始klc
|
||||
feature_data = []
|
||||
labels = []
|
||||
bi_index = 0
|
||||
sample_list = []
|
||||
for klc in klc_list:
|
||||
if bi_index == len(bi_list):
|
||||
if klc.fx != Chan_FX_TYPE.UNKNOWN:
|
||||
sample_list.append(klc)
|
||||
for klc in sample_list:
|
||||
if bi_index >= len(bi_list):
|
||||
bi_index = len(bi_list) - 1
|
||||
bi = bi_list[bi_index]
|
||||
# 提取特征
|
||||
@@ -344,10 +356,11 @@ class ChanLunClassifier:
|
||||
feature_vec.append(value)
|
||||
else:
|
||||
feature_vec.append(0)
|
||||
|
||||
if bi.start_klc.index == klc.index:
|
||||
seg = seg_list[bi_index]
|
||||
if bi.start_klc.index == klc.index and bi.dir == Chan_BI_DIR.UP:
|
||||
#if klc.index == seg.start_bi.start_klc.index and seg.dir == Chan_SEG_DIR.UP:
|
||||
label = 1
|
||||
bi_index += 1
|
||||
bi_index += 2
|
||||
else:
|
||||
label = 0
|
||||
|
||||
@@ -433,6 +446,8 @@ class ChanLunClassifier:
|
||||
dtest = xgb.DMatrix(np.array([feature_vec]))
|
||||
|
||||
# 预测
|
||||
return self.model.predict(dtest)[0]
|
||||
return self.get_decimal(self.model.predict(dtest)[0])
|
||||
|
||||
def get_decimal(self, value):
|
||||
return Decimal("{:.2f}".format(value))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user