支持手动指定品种和日期进行打分
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
import pandas as pd
|
||||
|
||||
from .models import ScoreDetail, ScoreResult
|
||||
@@ -116,11 +118,21 @@ def _interpret(composite: float) -> str:
|
||||
return "强烈看空区域 — 资金主动且持续地打压价格"
|
||||
|
||||
|
||||
def score_daily(df: pd.DataFrame) -> ScoreResult:
|
||||
"""对 DataFrame 中最新一条记录打分。"""
|
||||
def score_daily(df: pd.DataFrame, trade_date: Optional[str] = None) -> ScoreResult:
|
||||
"""对 DataFrame 中指定日期或最新一条记录打分。"""
|
||||
if len(df) < 31:
|
||||
raise ValueError(f"数据量不足(仅 {len(df)} 行),需要至少 31 行")
|
||||
|
||||
if trade_date:
|
||||
trade_date_str = str(trade_date)
|
||||
mask = df["trade_date"].astype(str) == trade_date_str
|
||||
if not mask.any():
|
||||
raise ValueError(f"指定日期 {trade_date_str} 不在数据中")
|
||||
pos = mask.idxmax()
|
||||
df = df.iloc[:pos + 1].copy()
|
||||
if len(df) < 31:
|
||||
raise ValueError(f"指定日期 {trade_date_str} 之前数据不足(仅 {len(df)} 行),需要至少 31 行")
|
||||
|
||||
latest = df.iloc[-1]
|
||||
|
||||
short, short_details = calc_short_term(df, 7)
|
||||
|
||||
Reference in New Issue
Block a user