trade-pool / trade_pool /seed_principles.py
tosi-n's picture
Upload folder using huggingface_hub
ce6b50a verified
Raw
History Blame Contribute Delete
3.11 kB
"""Distil tradewatch's 618 real trading decisions into grounded principles + exemplars
that ground the strategy-writing prompt.
These are NOT invented discipline rules β€” they are mined from actual BUY/AVOID decisions
the tradewatch agent made on live Base-chain tokens, so the discipline the coding agent
encodes into strategy logic is traceable to real prior trading, not a paraphrase. The
distilled block is baked into the wheel (committed below as a constant) so it ships with
the env and needs no runtime access to the tradewatch repo.
Regenerate with: python -m trade_pool.seed_principles --rebuild (dev only)
"""
from __future__ import annotations
import json
from pathlib import Path
# Baked-in distillation (committed). Mined from data/seed/decisions.jsonl:
# 94 BUY / 489 WATCH / 35 AVOID across 9 tokens, all with reasoning.
SEED_PRINCIPLES = """\
Trading discipline distilled from 618 real prior trading decisions (94 BUY, 489 WATCH, 35 AVOID):
Patterns that earned a BUY (translate these into your strategy's entry logic):
- "Post-dip curl": a 24h drop followed by a 1h recovery with a strong short-term buy/sell
ratio (>1.5). Enter on the curl, not the dip. β†’ buy when recent return turns up after a
drawdown and momentum (rsi rising from oversold, macd_hist turning positive) confirms.
- "Healthy momentum continuation": positive 1h AND 24h change with buy pressure and
volume/liquidity > 1. β†’ trend-follow when sma_10 > sma_20 and macd > macd_signal.
- Size up only with liquidity + volume backing the move; size down when volatility is high.
Conditions that earned WATCH/AVOID (translate into your exits and risk limits):
- Already +30% on the day β†’ entry timing is poor; do not chase. β†’ avoid full long when
ret_1 is extremely high or price is far above bb_mid.
- Volume/liquidity < 1.0 or thin liquidity β†’ lower conviction; reduce exposure.
- Sell-heavy short-term flow after entry β†’ cut quickly; don't wait for a vague recovery.
Capital-protection rules (every BUY required these):
- Always define a stop below entry and a target above; favor reward:risk >= 2:1.
- Protect capital first: control drawdown over chasing upside.
- Don't average down losers; don't let a winner round-trip β€” tighten when flow weakens.
"""
def principles_block() -> str:
return SEED_PRINCIPLES
# ── Dev-only: regenerate the constant from the raw journal extraction ──
def _rebuild() -> str:
seed = Path(__file__).resolve().parents[3] / "data" / "seed" / "decisions.jsonl"
rows = [json.loads(l) for l in seed.read_text().splitlines() if l.strip()]
buys = [r for r in rows if r.get("verdict") == "BUY"]
patterns = {}
for r in buys:
p = (r.get("pattern") or "unlabeled").strip()
patterns[p] = patterns.get(p, 0) + 1
print(f"{len(rows)} decisions | BUY patterns: {patterns}")
print("Edit SEED_PRINCIPLES by hand from these β€” keep it compact and strategy-actionable.")
return ""
if __name__ == "__main__":
import sys
if "--rebuild" in sys.argv:
_rebuild()
else:
print(principles_block())