Define entry styles: trend/reversal x 3 patterns, plus messy other.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -304,6 +304,28 @@ def list_trades(
|
||||
return rows
|
||||
|
||||
|
||||
# 入场形式:顺势/反转各含三种结构手法;其它=乱作
|
||||
ENTRY_PATTERN_TYPES = ("窄幅区间突破", "宽幅区间假突破", "波段高低点假突破")
|
||||
ENTRY_STYLES = (
|
||||
[f"顺势 · {p}" for p in ENTRY_PATTERN_TYPES]
|
||||
+ [f"反转 · {p}" for p in ENTRY_PATTERN_TYPES]
|
||||
+ ["其他 · 乱作"]
|
||||
)
|
||||
|
||||
|
||||
def entry_category(style: str) -> str:
|
||||
s = (style or "").strip()
|
||||
if not s:
|
||||
return "未标注"
|
||||
if s.startswith("顺势"):
|
||||
return "顺势"
|
||||
if s.startswith("反转"):
|
||||
return "反转"
|
||||
if s.startswith("其他") or "乱作" in s:
|
||||
return "其他"
|
||||
return "旧分类"
|
||||
|
||||
|
||||
def _hold_seconds(open_time: Any, close_time: Any, now_ts: Optional[float] = None) -> Optional[float]:
|
||||
if open_time in (None, ""):
|
||||
return None
|
||||
@@ -410,6 +432,10 @@ def trade_stats(
|
||||
by_hold = {k: _empty_group(v) for k, v in bucket_labels.items()}
|
||||
by_machine: dict[str, dict[str, Any]] = {}
|
||||
by_side: dict[str, dict[str, Any]] = {}
|
||||
by_category: dict[str, dict[str, Any]] = {
|
||||
k: _empty_group(k) for k in ("顺势", "反转", "其他", "未标注", "旧分类")
|
||||
}
|
||||
by_style: dict[str, dict[str, Any]] = {s: _empty_group(s) for s in ENTRY_STYLES}
|
||||
|
||||
total = len(rows)
|
||||
closed = 0
|
||||
@@ -447,9 +473,20 @@ def trade_stats(
|
||||
hold_sum += hold
|
||||
hold_n += 1
|
||||
|
||||
if (t.get("entry_style") or "").strip():
|
||||
style = (t.get("entry_style") or "").strip()
|
||||
if style:
|
||||
annotated += 1
|
||||
|
||||
cat = entry_category(style)
|
||||
_accumulate(by_category[cat], profit, hold)
|
||||
if style in by_style:
|
||||
_accumulate(by_style[style], profit, hold)
|
||||
elif style:
|
||||
key = f"旧 · {style}"
|
||||
if key not in by_style:
|
||||
by_style[key] = _empty_group(key)
|
||||
_accumulate(by_style[key], profit, hold)
|
||||
|
||||
bk = _bucket_key(hold)
|
||||
_accumulate(by_hold[bk], profit, hold)
|
||||
|
||||
@@ -467,6 +504,7 @@ def trade_stats(
|
||||
|
||||
decided = wins + losses
|
||||
avg_hold = (hold_sum / hold_n) if hold_n else None
|
||||
style_order = list(ENTRY_STYLES) + [k for k in by_style if k not in ENTRY_STYLES]
|
||||
return {
|
||||
"total": total,
|
||||
"closed": closed,
|
||||
@@ -491,6 +529,16 @@ def trade_stats(
|
||||
reverse=True,
|
||||
),
|
||||
"by_side": [_finalize_group(g) for g in by_side.values()],
|
||||
"by_category": [
|
||||
_finalize_group(by_category[k])
|
||||
for k in ("顺势", "反转", "其他", "未标注", "旧分类")
|
||||
if by_category[k]["count"] or k in ("顺势", "反转", "其他", "未标注")
|
||||
],
|
||||
"by_style": [
|
||||
_finalize_group(by_style[k])
|
||||
for k in style_order
|
||||
if k in by_style and (by_style[k]["count"] or k in ENTRY_STYLES)
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user