change something
This commit is contained in:
+21
-11
@@ -115,9 +115,9 @@ class ChanLun_SOL_5(IStrategy):
|
||||
self.classifier.train_model(dataframe, model_name="1m_model")
|
||||
self.classifier.train_model(dataframe_1d, model_name="1d_model")
|
||||
"""
|
||||
"""
|
||||
model_name = "30m_model"
|
||||
df = dataframe_30
|
||||
|
||||
model_name = "5m_model"
|
||||
df = dataframe_5
|
||||
if self.classifier.model is None:
|
||||
#self.classifier.train_model(df, model_name=model_name, data_file_path=model_name + '_feature_data.csv')
|
||||
self.classifier.load_model(model_name=model_name)
|
||||
@@ -129,14 +129,14 @@ class ChanLun_SOL_5(IStrategy):
|
||||
bottom_count = 0
|
||||
for index in range(int(len(klc_list) * 0.8), len(klc_list)):
|
||||
klc = klc_list[index]
|
||||
if self.classifier.predict(klc) > 0.4 and (klc.klc_fx_type == Chan_KLC_FX.BOTTOM1 or klc.klc_fx_type == Chan_KLC_FX.BOTTOM2):
|
||||
if self.classifier.predict(klc) > 0.37 and (klc.klc_fx_type == Chan_KLC_FX.BOTTOM1 or klc.klc_fx_type == Chan_KLC_FX.BOTTOM2):
|
||||
features = klc.get_feature_data()
|
||||
print(klc.end_time, klc.fx, self.classifier.predict(klc), features['klc_macd'], features['klc_macd_hist'], features['klc_rsi'], features['klc_macd_signal'])
|
||||
print(klc.end_time, klc.fx, self.classifier.predict(klc), features['klc_volume_ratio'], features['klc_macd_hist'], features['klc_rsi'])
|
||||
bottom_avg += self.classifier.predict(klc)
|
||||
bottom_count += 1
|
||||
if self.classifier.predict(klc) > 0.35 and (klc.klc_fx_type == Chan_KLC_FX.TOP1 or klc.klc_fx_type == Chan_KLC_FX.TOP2):
|
||||
if self.classifier.predict(klc) > 0.37 and (klc.klc_fx_type == Chan_KLC_FX.TOP1 or klc.klc_fx_type == Chan_KLC_FX.TOP2):
|
||||
features = klc.get_feature_data()
|
||||
print(klc.end_time, klc.fx, self.classifier.predict(klc), features['klc_macd'], features['klc_macd_hist'], features['klc_rsi'], features['klc_macd_signal'])
|
||||
print(klc.end_time, klc.fx, self.classifier.predict(klc), features['klc_volume_ratio'], features['klc_macd_hist'], features['klc_rsi'])
|
||||
top_avg += self.classifier.predict(klc)
|
||||
top_count += 1
|
||||
if bottom_count > 0:
|
||||
@@ -145,7 +145,7 @@ class ChanLun_SOL_5(IStrategy):
|
||||
top_avg /= top_count
|
||||
print(bottom_avg, top_avg)
|
||||
print("-------------------------------------------------------------------------------")
|
||||
"""
|
||||
|
||||
"""
|
||||
self.print_xgb(dataframe, "1m_model")
|
||||
self.print_xgb(dataframe_5, "5m_model")
|
||||
@@ -350,9 +350,9 @@ class ChanLun_SOL_5(IStrategy):
|
||||
cn3 = 'resample_{}_state'.format(self.get_ticker_indicator()*time)
|
||||
logger.info(f'{df[cn1][index]}, {df[cn2][index]}, {df[cn3][index]}')
|
||||
def add_indicators(self, df):
|
||||
fast = 9
|
||||
slow = 24
|
||||
period = 14
|
||||
fast = 8
|
||||
slow = 16
|
||||
period = 6
|
||||
macd = ta.MACD(df, fastperiod=fast, slowperiod=slow, signalperiod=period)
|
||||
df['macd'] = macd['macd']
|
||||
df['macdsignal'] = macd['macdsignal']
|
||||
@@ -362,7 +362,17 @@ class ChanLun_SOL_5(IStrategy):
|
||||
df['ma30'] = ta.EMA(df, timeperiod=30)
|
||||
df['ma250'] = ta.MA(df, timeperiod=250)
|
||||
df['rsi'] = ta.RSI(df, timeperiod=14)
|
||||
df['volume_ratio'] = self.cal_volume_ratio(df)
|
||||
return df
|
||||
def cal_volume_ratio(self, dataframe, window=10):
|
||||
df = dataframe.copy()
|
||||
# 计算过去N根K线的平均成交量
|
||||
df['avg_volume'] = df['volume'].rolling(window=window).mean()
|
||||
# 计算量比
|
||||
df['volume_ratio'] = df['volume'] / df['avg_volume']
|
||||
# 填充缺失值(前N根K线)
|
||||
df['volume_ratio'] = df['volume_ratio'].fillna(1.0)
|
||||
return df['volume_ratio']
|
||||
def local_print(self, df):
|
||||
fast = 7
|
||||
slow = 14
|
||||
|
||||
Reference in New Issue
Block a user