diff --git a/core/biz/__pycache__/market_monitor.cpython-312.pyc b/core/biz/__pycache__/market_monitor.cpython-312.pyc index 9ad5f25..406f390 100644 Binary files a/core/biz/__pycache__/market_monitor.cpython-312.pyc and b/core/biz/__pycache__/market_monitor.cpython-312.pyc differ diff --git a/market_monitor_main.py b/market_monitor_main.py index d289417..bbbae87 100644 --- a/market_monitor_main.py +++ b/market_monitor_main.py @@ -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