change something

This commit is contained in:
jackyu66git
2025-04-27 18:37:50 +08:00
parent 88701608bd
commit fceb57d2b8
10 changed files with 285 additions and 162 deletions
+16 -3
View File
@@ -117,6 +117,8 @@ class ChanLun_SOL_15(IStrategy):
#self.print_macd_div_list(dataframe)
#self.print_resample_df(dataframe, 1, 50)
#self.chan.get_bi_list(dataframe_30)
#self.chan.plot_dual(dataframe_5, dataframe_30)
self.chan.print_bi_klc(dataframe_5)
#if self.last_time + timedelta(minutes=1) < datetime.now():
#print(informative.iloc[-1])
#self.print_klc(dataframe, "1m: ")
@@ -279,10 +281,11 @@ class ChanLun_SOL_15(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']
df['macdhist'] = macd['macdhist']
@@ -299,7 +302,17 @@ class ChanLun_SOL_15(IStrategy):
df['ma30'] = df['ma30'].fillna(0)
df['ma250'] = df['ma250'].fillna(0)
df['rsi'] = df['rsi'].fillna(0)
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 populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
+21 -11
View File
@@ -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