From 328dc4a3b0e06caf928b2f60bfb325ce057aeb5d Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 26 Aug 2025 17:22:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=9B=B8=E5=AF=B9?= =?UTF-8?q?=E5=8F=98=E5=8C=96=E7=8E=87=E8=BD=AC=E7=BB=9D=E5=AF=B9=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E7=9A=84=E7=B4=AF=E7=A7=AF=E8=AE=A1=E7=AE=97=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BD=BF=E7=94=A8cumprod=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E8=BF=9E=E7=BB=AD=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui/app.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/webui/app.py b/webui/app.py index 5f36971..47dee38 100644 --- a/webui/app.py +++ b/webui/app.py @@ -156,8 +156,20 @@ def convert_returns_to_price(returns_df, initial_prices, price_cols=['open', 'hi for col in price_cols: if col in price_df.columns: print(f"[DEBUG] convert_returns_to_price: 转换列 {col}") - # 从初始价格开始,逐步计算绝对价格 - price_df[col] = (1 + returns_df[col]) * initial_prices[col] + # 正确的转换逻辑:从初始价格开始,逐步累积计算绝对价格 + # 第一个点:price = initial_price * (1 + return_1) + # 第二个点:price = price_1 * (1 + return_2) + # 第三个点:price = price_2 * (1 + return_3) + # 以此类推... + + # 使用cumprod来累积计算 + price_df[col] = initial_prices[col] * (1 + returns_df[col]).cumprod() + + print(f"[DEBUG] convert_returns_to_price: 列 {col} 转换完成,前3个值:") + print(f" 初始价格: {initial_prices[col]}") + print(f" 相对变化率: {returns_df[col].head(3).tolist()}") + print(f" 累积因子: {(1 + returns_df[col]).cumprod().head(3).tolist()}") + print(f" 最终价格: {price_df[col].head(3).tolist()}") print(f"[DEBUG] convert_returns_to_price: 转换完成,输出绝对价格前3行:") print(price_df[price_cols].head(3))