gaurv007 commited on
Commit
8b6847c
·
verified ·
1 Parent(s): 62adb1b

Upload alpha_factory/schemas/__init__.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. alpha_factory/schemas/__init__.py +131 -0
alpha_factory/schemas/__init__.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Pydantic schemas — typed contracts between every agent.
3
+ No free-text. Every LLM output is schema-constrained.
4
+ """
5
+ from pydantic import BaseModel, Field
6
+ from typing import Optional
7
+ from enum import Enum
8
+
9
+
10
+ class Neutralization(str, Enum):
11
+ SECTOR = "sector"
12
+ INDUSTRY = "industry"
13
+ SUBINDUSTRY = "subindustry"
14
+ NONE = "none"
15
+
16
+
17
+ class AnomalyTag(str, Enum):
18
+ PEAD = "pead"
19
+ VALUE = "value"
20
+ MOMENTUM = "momentum"
21
+ REVERSAL = "reversal"
22
+ LOW_VOL = "low_vol"
23
+ QUALITY = "quality"
24
+ LIQUIDITY = "liquidity"
25
+ SENTIMENT = "sentiment"
26
+ ANALYST = "analyst"
27
+ OPTION_SURFACE = "option_surface"
28
+ SOCIAL = "social"
29
+ FUNDAMENTAL = "fundamental"
30
+ TECHNICAL = "technical"
31
+ EVENT = "event"
32
+ OTHER = "other"
33
+
34
+
35
+ class Component(BaseModel):
36
+ """A single component of a multi-factor alpha."""
37
+ name: str = Field(description="Descriptive name for this component")
38
+ fields: list[str] = Field(description="BRAIN data fields used")
39
+ operators: list[str] = Field(description="BRAIN operators applied")
40
+ horizon_days: int = Field(ge=1, le=252, description="Lookback horizon")
41
+ weight: float = Field(ge=-2.0, le=2.0, description="Weight in composite")
42
+ sign_direction: str = Field(description="Expected cross-sectional sign: 'long_high' or 'long_low'")
43
+
44
+
45
+ class Blueprint(BaseModel):
46
+ """Output of the Hypothesis Hunter. A structured factor idea."""
47
+ theme: str = Field(description="High-level theme/anomaly category")
48
+ archetype: str = Field(description="Known archetype name or 'novel'")
49
+ components: list[Component] = Field(min_length=1, max_length=5)
50
+ neutralization: Neutralization
51
+ decay: int = Field(ge=0, le=20, default=5)
52
+ novelty_claim: str = Field(min_length=10, description="Why this is different from existing alphas")
53
+ academic_anchor: Optional[str] = Field(default=None, description="arXiv ID or DOI")
54
+ anomaly_tag: AnomalyTag
55
+
56
+
57
+ class Expression(BaseModel):
58
+ """Output of the Expression Compiler. A valid BRAIN expression."""
59
+ expression: str = Field(min_length=10, description="The BRAIN expression string")
60
+ fields_used: list[str]
61
+ operators_used: list[str]
62
+ archetype_used: str = Field(description="Which template/archetype was used")
63
+
64
+
65
+ class LintResult(BaseModel):
66
+ """Output of the Static Lint layer."""
67
+ passed: bool
68
+ errors: list[str] = Field(default_factory=list)
69
+ warnings: list[str] = Field(default_factory=list)
70
+
71
+
72
+ class SignSweepResult(BaseModel):
73
+ """Output of the sign direction sweep."""
74
+ pos_sharpe: float
75
+ neg_sharpe: float
76
+ verdict: str = Field(description="'pos' or 'neg' — which direction works")
77
+ info_value: float = Field(description="abs(pos - neg), higher = more signal")
78
+
79
+
80
+ class BrainMetrics(BaseModel):
81
+ """Metrics harvested from BRAIN simulation."""
82
+ alpha_id: str
83
+ sharpe_full: float
84
+ sharpe_is: float
85
+ sharpe_os: float
86
+ fitness: float
87
+ turnover: float
88
+ returns: float
89
+ max_drawdown: float
90
+ yearly_sharpe: list[float]
91
+ yearly_returns: list[float]
92
+ margin_pct: Optional[float] = None
93
+ long_count: Optional[int] = None
94
+ short_count: Optional[int] = None
95
+
96
+
97
+ class Verdict(str, Enum):
98
+ PROMOTE = "promote"
99
+ ITERATE = "iterate"
100
+ KILL = "kill"
101
+
102
+
103
+ class CrowdScoutResult(BaseModel):
104
+ """Output of the Crowd Scout agent."""
105
+ max_corr_to_library: float
106
+ is_thematic_duplicate: bool
107
+ anomaly_already_saturated: bool
108
+ verdict: Verdict
109
+ reason: str
110
+
111
+
112
+ class SurgeonResult(BaseModel):
113
+ """Output of the Performance Surgeon agent."""
114
+ regime_dependent: bool
115
+ decay_detected: bool
116
+ sign_error_likely: bool
117
+ dominant_regime: Optional[str] = None
118
+ iteration_suggestion: str
119
+ verdict: Verdict
120
+ reason: str
121
+
122
+
123
+ class GatekeeperMemo(BaseModel):
124
+ """Output of the Production Gatekeeper (Bigfish)."""
125
+ go_no_go: bool
126
+ confidence: float = Field(ge=0.0, le=1.0)
127
+ strengths: list[str]
128
+ weaknesses: list[str]
129
+ risks: list[str]
130
+ recommendation: str
131
+ full_memo: str