Add files
Add first batch of files
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
.DS_Store
|
||||||
|
__pycache__/
|
||||||
@@ -53,6 +53,13 @@ class ChanBI():
|
|||||||
def set_next(self, bi):
|
def set_next(self, bi):
|
||||||
self.next = bi
|
self.next = bi
|
||||||
def add_klc(self, klc):
|
def add_klc(self, klc):
|
||||||
|
added = False
|
||||||
|
if len(self.klc_list) > 0:
|
||||||
|
for index in range(0, len(self.klc_list)):
|
||||||
|
if self.klc_list[index].index == klc.index:
|
||||||
|
added = True
|
||||||
|
break
|
||||||
|
if not added:
|
||||||
self.klc_list.append(klc)
|
self.klc_list.append(klc)
|
||||||
def append_klc_list(self, klc_list):
|
def append_klc_list(self, klc_list):
|
||||||
self.klc_list.append(klc_list)
|
self.klc_list.append(klc_list)
|
||||||
|
|||||||
+18
-2
@@ -1,7 +1,7 @@
|
|||||||
import copy
|
import copy
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
|
|
||||||
from ChanEnum import Chan_FX_TYPE, Chan_KLINE_DIR
|
from ChanEnum import Chan_FX_TYPE, Chan_KLINE_DIR, Chan_BI_DIR
|
||||||
import ChanKLU
|
import ChanKLU
|
||||||
import ChanCTime
|
import ChanCTime
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ class ChanKLC():
|
|||||||
self.open = klu.open
|
self.open = klu.open
|
||||||
self.close = klu.close
|
self.close = klu.close
|
||||||
self.volume = klu.volume
|
self.volume = klu.volume
|
||||||
|
self.macdhist = 0
|
||||||
def add_klu(self, klu):
|
def add_klu(self, klu):
|
||||||
self.klus.append(klu)
|
self.klus.append(klu)
|
||||||
def set_end_klu(self, klu):
|
def set_end_klu(self, klu):
|
||||||
@@ -107,8 +108,23 @@ class ChanKLC():
|
|||||||
return Chan_FX_TYPE.BOTTOM
|
return Chan_FX_TYPE.BOTTOM
|
||||||
else:
|
else:
|
||||||
return Chan_FX_TYPE.UNKNOWN
|
return Chan_FX_TYPE.UNKNOWN
|
||||||
def set_bi_data(self, bi):
|
def set_bi(self, bi):
|
||||||
self.bi = bi
|
self.bi = bi
|
||||||
|
self.get_macdhist()
|
||||||
|
for index in range(0, len(self.bi.klc_list)):
|
||||||
|
klc = self.bi.klc_list[index]
|
||||||
|
if klc.index == self.index:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
if bi.dir == Chan_BI_DIR.UP:
|
||||||
|
self.macdhist += klc.get_macdhist()
|
||||||
|
else:
|
||||||
|
self.macdhist -= klc.get_macdhist()
|
||||||
|
def get_macdhist(self):
|
||||||
|
self.macdhist = 0
|
||||||
|
for klu in self.klus:
|
||||||
|
self.macdhist += klu.macdhist
|
||||||
|
return self.macdhist
|
||||||
def cal_klu_features(self):
|
def cal_klu_features(self):
|
||||||
features = dict()
|
features = dict()
|
||||||
feature_sums = dict()
|
feature_sums = dict()
|
||||||
|
|||||||
+42
-1
@@ -148,7 +148,7 @@ class ChanLun():
|
|||||||
state_list.append("00")
|
state_list.append("00")
|
||||||
return state_list
|
return state_list
|
||||||
def get_bi_list(self, dataframe):
|
def get_bi_list(self, dataframe):
|
||||||
bi_list, klc_list = self.cal_bi_list(self.get_klc_list(dataframe))
|
bi_list = self.cal_bi_list(self.get_klc_list(dataframe))
|
||||||
return bi_list
|
return bi_list
|
||||||
def calculate_zs(self, bi_list, seg_list):
|
def calculate_zs(self, bi_list, seg_list):
|
||||||
return self.get_zs_list(bi_list, seg_list)
|
return self.get_zs_list(bi_list, seg_list)
|
||||||
@@ -528,6 +528,9 @@ class ChanLun():
|
|||||||
# Do nothing
|
# Do nothing
|
||||||
if fx == Chan_FX_TYPE.UNKNOWN:
|
if fx == Chan_FX_TYPE.UNKNOWN:
|
||||||
klc.set_fx(Chan_FX_TYPE.UNKNOWN)
|
klc.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||||
|
if len(bi_list) > 0:
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
else:
|
else:
|
||||||
if fx == Chan_FX_TYPE.TOP:
|
if fx == Chan_FX_TYPE.TOP:
|
||||||
if last_top:
|
if last_top:
|
||||||
@@ -538,6 +541,8 @@ class ChanLun():
|
|||||||
if last_top.high > klc.high:
|
if last_top.high > klc.high:
|
||||||
klc.set_fx(Chan_FX_TYPE.TT)
|
klc.set_fx(Chan_FX_TYPE.TT)
|
||||||
klc.set_state("20")
|
klc.set_state("20")
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
#print(klc.start_time, klc.fx, "二类买卖点Sell 1")
|
#print(klc.start_time, klc.fx, "二类买卖点Sell 1")
|
||||||
else:
|
else:
|
||||||
# A new top found
|
# A new top found
|
||||||
@@ -545,12 +550,16 @@ class ChanLun():
|
|||||||
last_top = klc
|
last_top = klc
|
||||||
#print(klc.start_time, klc.fx, "一类买卖点Sell 1")
|
#print(klc.start_time, klc.fx, "一类买卖点Sell 1")
|
||||||
klc.set_state("10")
|
klc.set_state("10")
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
else:
|
else:
|
||||||
# 不满足结合律的分型
|
# 不满足结合律的分型
|
||||||
if last_bottom.index + 4 > klc.index:
|
if last_bottom.index + 4 > klc.index:
|
||||||
if last_top.high > klc.high:
|
if last_top.high > klc.high:
|
||||||
#print(klc.start_time, last_bottom.start_time, klc.fx, "中枢买卖点Sell 1")
|
#print(klc.start_time, last_bottom.start_time, klc.fx, "中枢买卖点Sell 1")
|
||||||
klc.set_fx(Chan_FX_TYPE.UNKNOWN)
|
klc.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
# New TOP Found replace last top
|
# New TOP Found replace last top
|
||||||
else:
|
else:
|
||||||
if last_top.index + 4 < klc.index and len(bi_list) > 1:
|
if last_top.index + 4 < klc.index and len(bi_list) > 1:
|
||||||
@@ -565,8 +574,12 @@ class ChanLun():
|
|||||||
last_bottom = pre_last_bi.start_klc
|
last_bottom = pre_last_bi.start_klc
|
||||||
#print(klc.start_time, last_bi.start_klc.start_time, "New TOP Found reset last bi")
|
#print(klc.start_time, last_bi.start_klc.start_time, "New TOP Found reset last bi")
|
||||||
klc.set_state("10")
|
klc.set_state("10")
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
else:
|
else:
|
||||||
klc.set_fx(Chan_FX_TYPE.UNKNOWN)
|
klc.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
#print(klc.start_time, last_bottom.start_time, klc.fx, "中枢买卖点Sell 2")
|
#print(klc.start_time, last_bottom.start_time, klc.fx, "中枢买卖点Sell 2")
|
||||||
# 满足结合律
|
# 满足结合律
|
||||||
else:
|
else:
|
||||||
@@ -581,6 +594,8 @@ class ChanLun():
|
|||||||
bi_list.append(bi)
|
bi_list.append(bi)
|
||||||
last_top = klc
|
last_top = klc
|
||||||
klc.set_state('30')
|
klc.set_state('30')
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
#print(klc.start_time, last_bottom.start_time, "Normal TOP Found, Confirm down bi 4")
|
#print(klc.start_time, last_bottom.start_time, "Normal TOP Found, Confirm down bi 4")
|
||||||
# last bottom = None
|
# last bottom = None
|
||||||
else:
|
else:
|
||||||
@@ -589,10 +604,14 @@ class ChanLun():
|
|||||||
last_bi.set_start_klc(klc, Chan_BI_DIR.DOWN)
|
last_bi.set_start_klc(klc, Chan_BI_DIR.DOWN)
|
||||||
#last_top.set_fx(Chan_FX_TYPE.UNKNOWN)
|
#last_top.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||||
last_top = klc
|
last_top = klc
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
else:
|
else:
|
||||||
klc.set_fx(Chan_FX_TYPE.TT)
|
klc.set_fx(Chan_FX_TYPE.TT)
|
||||||
klc.set_state('20')
|
klc.set_state('20')
|
||||||
#print(klc.start_time, klc.fx, "二类买卖点Sell 2")
|
#print(klc.start_time, klc.fx, "二类买卖点Sell 2")
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
else:
|
else:
|
||||||
if last_bottom:
|
if last_bottom:
|
||||||
# 不满足结合律的分型
|
# 不满足结合律的分型
|
||||||
@@ -618,6 +637,8 @@ class ChanLun():
|
|||||||
if last_bottom.low < klc.low:
|
if last_bottom.low < klc.low:
|
||||||
klc.set_fx(Chan_FX_TYPE.BB)
|
klc.set_fx(Chan_FX_TYPE.BB)
|
||||||
klc.set_state("-20")
|
klc.set_state("-20")
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
#print(klc.start_time, klc.fx, "二类买卖点Buy 1")
|
#print(klc.start_time, klc.fx, "二类买卖点Buy 1")
|
||||||
else:
|
else:
|
||||||
# A new bottom found
|
# A new bottom found
|
||||||
@@ -625,6 +646,8 @@ class ChanLun():
|
|||||||
last_bottom = klc
|
last_bottom = klc
|
||||||
#print(klc.start_time, klc.fx, "一类买卖点Buy 1")
|
#print(klc.start_time, klc.fx, "一类买卖点Buy 1")
|
||||||
klc.set_state("-10")
|
klc.set_state("-10")
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
else:
|
else:
|
||||||
# 不满足结合律的分型
|
# 不满足结合律的分型
|
||||||
if last_top.index + 4 > klc.index:
|
if last_top.index + 4 > klc.index:
|
||||||
@@ -633,6 +656,8 @@ class ChanLun():
|
|||||||
#klc.set_fx(Chan_FX_TYPE.BB)
|
#klc.set_fx(Chan_FX_TYPE.BB)
|
||||||
#klc.set_state("-100")
|
#klc.set_state("-100")
|
||||||
#print(klc.start_time, klc.fx, "中枢买卖点Buy 1")
|
#print(klc.start_time, klc.fx, "中枢买卖点Buy 1")
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
# Found new bottom
|
# Found new bottom
|
||||||
else:
|
else:
|
||||||
if last_bottom.index + 4 < klc.index and len(bi_list) > 1:
|
if last_bottom.index + 4 < klc.index and len(bi_list) > 1:
|
||||||
@@ -647,8 +672,12 @@ class ChanLun():
|
|||||||
last_top = pre_last_bi.start_klc
|
last_top = pre_last_bi.start_klc
|
||||||
#print(klc.start_time, last_bi.start_klc.start_time, "New BOTTOM Found reset last bi")
|
#print(klc.start_time, last_bi.start_klc.start_time, "New BOTTOM Found reset last bi")
|
||||||
klc.set_state("-10")
|
klc.set_state("-10")
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
else:
|
else:
|
||||||
klc.set_fx(Chan_FX_TYPE.UNKNOWN)
|
klc.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
#print(klc.start_time, klc.fx, "中枢买卖点Buy 2")
|
#print(klc.start_time, klc.fx, "中枢买卖点Buy 2")
|
||||||
# 满足结合律的分型
|
# 满足结合律的分型
|
||||||
else:
|
else:
|
||||||
@@ -663,6 +692,8 @@ class ChanLun():
|
|||||||
bi_list.append(bi)
|
bi_list.append(bi)
|
||||||
last_bottom = klc
|
last_bottom = klc
|
||||||
klc.set_state('-30')
|
klc.set_state('-30')
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
#print(klc.start_time, last_top.start_time, "Normal Bottom Found, Confirm up bi 6")
|
#print(klc.start_time, last_top.start_time, "Normal Bottom Found, Confirm up bi 6")
|
||||||
# last_top = None
|
# last_top = None
|
||||||
else:
|
else:
|
||||||
@@ -671,25 +702,35 @@ class ChanLun():
|
|||||||
last_bi.set_start_klc(klc, Chan_BI_DIR.UP)
|
last_bi.set_start_klc(klc, Chan_BI_DIR.UP)
|
||||||
#last_bottom.set_fx(Chan_FX_TYPE.UNKNOWN)
|
#last_bottom.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||||
last_bottom = klc
|
last_bottom = klc
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
else:
|
else:
|
||||||
klc.set_fx(Chan_FX_TYPE.BB)
|
klc.set_fx(Chan_FX_TYPE.BB)
|
||||||
klc.set_state('-20')
|
klc.set_state('-20')
|
||||||
#print(klc.start_time, klc.fx, "二类买卖点Buy 2")
|
#print(klc.start_time, klc.fx, "二类买卖点Buy 2")
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
# last_bottom = None
|
# last_bottom = None
|
||||||
else:
|
else:
|
||||||
if last_top:
|
if last_top:
|
||||||
# 不满足结合律的分型
|
# 不满足结合律的分型
|
||||||
if last_top.index + 4 > klc.index:
|
if last_top.index + 4 > klc.index:
|
||||||
klc.set_fx(Chan_FX_TYPE.UNKNOWN)
|
klc.set_fx(Chan_FX_TYPE.UNKNOWN)
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
else:
|
else:
|
||||||
# First temp bottom and last top confirmed
|
# First temp bottom and last top confirmed
|
||||||
last_bottom = klc
|
last_bottom = klc
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
# Last top = None, last bottom = None, create first up bi
|
# Last top = None, last bottom = None, create first up bi
|
||||||
else:
|
else:
|
||||||
# First temp bottom and no top yet
|
# First temp bottom and no top yet
|
||||||
last_bottom = klc
|
last_bottom = klc
|
||||||
bi = ChanBI(klc, len(bi_list), Chan_BI_DIR.UP)
|
bi = ChanBI(klc, len(bi_list), Chan_BI_DIR.UP)
|
||||||
bi_list.append(bi)
|
bi_list.append(bi)
|
||||||
|
bi_list[-1].add_klc(klc)
|
||||||
|
klc.set_bi(bi_list[-1])
|
||||||
#print(klc.start_time, 'Create first bottom')
|
#print(klc.start_time, 'Create first bottom')
|
||||||
#print(klc.time, klc.fx, klc.state)
|
#print(klc.time, klc.fx, klc.state)
|
||||||
for klc in klc_list:
|
for klc in klc_list:
|
||||||
|
|||||||
@@ -290,6 +290,9 @@ class ChanLunClassifier:
|
|||||||
if bi_index == len(bi_list):
|
if bi_index == len(bi_list):
|
||||||
bi_index = len(bi_list) - 1
|
bi_index = len(bi_list) - 1
|
||||||
bi = bi_list[bi_index]
|
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:
|
||||||
|
klc.set_bi(bi)
|
||||||
|
|
||||||
# 提取特征
|
# 提取特征
|
||||||
features = klc.get_feature_data()
|
features = klc.get_feature_data()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user