fix bug for set price_anomaly
This commit is contained in:
parent
d397986bad
commit
ccc5637f9e
Binary file not shown.
|
|
@ -131,7 +131,7 @@ class MarketMonitorMain:
|
|||
)
|
||||
return
|
||||
realtime_row = real_time_data.iloc[-1]
|
||||
real_time_data = self.calculate_price_anomaly(real_time_data, realtime_row)
|
||||
realtime_row = self.calculate_price_anomaly(real_time_data, realtime_row)
|
||||
if only_output_huge_volume:
|
||||
if realtime_row["huge_volume"] == 1:
|
||||
logger.info(f"监控到巨量: {symbol} {bar} 窗口大小: {self.window_size}")
|
||||
|
|
@ -216,16 +216,18 @@ class MarketMonitorMain:
|
|||
def calculate_price_anomaly(self, data: pd.DataFrame, realtime_row: pd.Series):
|
||||
k = 2
|
||||
# 计算均值和标准差
|
||||
data = data.copy()[0:-1]
|
||||
data = data.copy().iloc[:-1]
|
||||
# 避免 SettingWithCopyWarning,先复制一份当前行的独立副本
|
||||
realtime_row = realtime_row.copy()
|
||||
pct_chg = realtime_row["pct_chg"]
|
||||
pct_chg_mean = data['pct_chg'].mean()
|
||||
pct_chg_std = data['pct_chg'].std()
|
||||
pct_chg_upper_bound = pct_chg_mean + k * pct_chg_std
|
||||
pct_chg_lower_bound = pct_chg_mean - k * pct_chg_std
|
||||
if pct_chg > pct_chg_upper_bound or pct_chg < pct_chg_lower_bound:
|
||||
realtime_row["price_anomaly"] = True
|
||||
realtime_row.loc["price_anomaly"] = True
|
||||
else:
|
||||
realtime_row["price_anomaly"] = False
|
||||
realtime_row.loc["price_anomaly"] = False
|
||||
|
||||
return realtime_row
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue