Premchan369 commited on
Commit
dff4dc8
·
verified ·
1 Parent(s): b666cca

Upload goat_strategy.py

Browse files
Files changed (1) hide show
  1. goat_strategy.py +282 -0
goat_strategy.py ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """AlphaForge GOAT Strategy Guide - How to Be the Greatest of All Time
2
+
3
+ This is not just code. This is your quant trading BIBLE.
4
+ Follow these rules religiously and you will compound wealth.
5
+ Break them and you will blow up. Guaranteed.
6
+ """
7
+
8
+ from typing import Dict, List
9
+ import json
10
+
11
+ # THE GOAT MINDSET - Read This Every Morning
12
+
13
+ GOAT_MINDSET = """
14
+ THE GOAT MINDSET
15
+
16
+ 1. SURVIVAL FIRST, PROFIT SECOND
17
+ Your #1 job is NOT to make money. It's to NOT lose money.
18
+ If you survive, compounding does the rest.
19
+
20
+ 2. PROCESS OVER OUTCOME
21
+ A bad process with a good result is LUCK.
22
+ A good process with a bad result is VARIANCE.
23
+ Judge yourself by your PROCESS, not your PnL today.
24
+
25
+ 3. EDGE COMPOUNDS, LUCK DOESN'T
26
+ A 0.05 IC doesn't sound like much.
27
+ But over 252 trading days, it compounds into massive alpha.
28
+ This is why Two Sigma and Renaissance are worth $100B+.
29
+
30
+ 4. DIVERSIFICATION IS THE ONLY FREE LUNCH
31
+ Harry Markowitz won a Nobel Prize proving this.
32
+ Don't fight Nobel Prize winners.
33
+
34
+ 5. YOU ARE YOUR OWN WORST ENEMY
35
+ Fear makes you sell the bottom.
36
+ Greed makes you buy the top.
37
+ AlphaForge removes emotion. Trust the system.
38
+ """
39
+
40
+ # THE GOAT RULES - Violate at Your Own Peril
41
+
42
+ GOAT_RULES = {
43
+ "risk_management": {
44
+ "title": "RISK MANAGEMENT - THE ONLY THING THAT MATTERS",
45
+ "rules": [
46
+ {
47
+ "rule": "NEVER risk more than 2% of capital on a single position",
48
+ "why": "A 2% risk means you can be wrong 50 times in a row and still have 36% left.",
49
+ "action": "Set max_weight = 0.20 and stop-loss at 10%. 0.20 * 0.10 = 2% max loss."
50
+ },
51
+ {
52
+ "rule": "NEVER risk more than 6% of capital in a single month",
53
+ "why": "Three 2% losses in a month = 6%. That's your circuit breaker.",
54
+ "action": "Track monthly PnL. If down 6%, reduce all positions by 50%."
55
+ },
56
+ {
57
+ "rule": "ALWAYS know your maximum drawdown BEFORE you trade",
58
+ "why": "If you can't handle a 20% drawdown, don't use a strategy with 25% historical max DD.",
59
+ "action": "Set personal max DD threshold. AlphaForge default: 15%."
60
+ },
61
+ {
62
+ "rule": "NEVER add to a losing position",
63
+ "why": "Averaging down is how amateurs turn small losses into catastrophes.",
64
+ "action": "Use fixed position sizes. Never increase size because you're down."
65
+ },
66
+ {
67
+ "rule": "ALWAYS use the Kelly Criterion (fractionally)",
68
+ "why": "Kelly tells you optimal bet size given your edge. Use HALF Kelly or QUARTER Kelly.",
69
+ "action": "Kelly % = (Win Rate * Avg Win - Loss Rate * Avg Loss) / Avg Win. Use 25-50% of that."
70
+ }
71
+ ]
72
+ },
73
+
74
+ "position_sizing": {
75
+ "title": "POSITION SIZING - SIZE IS MORE IMPORTANT THAN TIMING",
76
+ "rules": [
77
+ {
78
+ "rule": "Size by VOLATILITY, not by conviction",
79
+ "why": "A 'sure thing' in a volatile stock can hurt you more than a 'maybe' in a calm stock.",
80
+ "action": "Position Size = (Target Risk %) / (Stock Volatility * Stop Loss %)."
81
+ },
82
+ {
83
+ "rule": "INCREASE size when Sharpe is high, DECREASE when Sharpe is low",
84
+ "why": "Your edge fluctuates. When metrics are hot, press the bet. When cold, shrink.",
85
+ "action": "Base position = Base * (Current Sharpe / Target Sharpe). Target Sharpe = 1.5."
86
+ },
87
+ {
88
+ "rule": "NEVER go all-in on a single signal",
89
+ "why": "Even the best signals have drawdowns. Combine multiple uncorrelated signals.",
90
+ "action": "Minimum 3 uncorrelated alpha sources: Price + Sentiment + Options Flow."
91
+ },
92
+ {
93
+ "rule": "USE volatility targeting for the TOTAL portfolio",
94
+ "why": "If target vol is 10% but current vol is 20%, you are 2x too risky. Scale down 50%.",
95
+ "action": "Portfolio Leverage = Target Vol / Current Portfolio Vol. Adjust daily."
96
+ }
97
+ ]
98
+ },
99
+
100
+ "execution": {
101
+ "title": "EXECUTION - THE DIFFERENCE BETWEEN THEORY AND REALITY",
102
+ "rules": [
103
+ {
104
+ "rule": "ALWAYS account for transaction costs",
105
+ "why": "At 150% annual turnover and 3bps cost, you lose 0.09% to friction. At 10bps, 0.30%.",
106
+ "action": "Use low-cost brokers. Avoid frequent rebalancing. Batch orders."
107
+ },
108
+ {
109
+ "rule": "NEVER trade during first/last 15 minutes unless you have to",
110
+ "why": "Open and close have highest volatility and widest spreads.",
111
+ "action": "Place orders between 10:30 AM - 3:30 PM EST. Use VWAP for large orders."
112
+ },
113
+ {
114
+ "rule": "ALWAYS use limit orders, NEVER market orders",
115
+ "why": "Market orders guarantee execution at unknown prices. Limit orders control price. Saves 5-10bps.",
116
+ "action": "Set limit at mid-price for liquid stocks. 5bps inside spread for illiquid."
117
+ },
118
+ {
119
+ "rule": "NEVER chase a move",
120
+ "why": "If a stock already moved 2% in 5 minutes, you missed it. Chasing = buying high.",
121
+ "action": "Set alerts at your entry price. If it never hits, move on. 10,000+ stocks exist."
122
+ }
123
+ ]
124
+ },
125
+
126
+ "psychology": {
127
+ "title": "PSYCHOLOGY - THE INVISIBLE KILLER",
128
+ "rules": [
129
+ {
130
+ "rule": "NEVER check PnL more than once per day",
131
+ "why": "Intraday volatility is noise. Checking every minute creates anxiety and impulsive decisions.",
132
+ "action": "Set a daily alarm for 4 PM. Check then. Close the app. Live your life."
133
+ },
134
+ {
135
+ "rule": "NEVER trade when emotional",
136
+ "why": "Fear, greed, anger, euphoria - all destroy edge. Your brain can't make rational decisions under strong emotion.",
137
+ "action": "After a big loss: mandatory 24-hour cooling period. No exceptions."
138
+ },
139
+ {
140
+ "rule": "ALWAYS keep a trading journal",
141
+ "why": "You think you know why you made each trade. You don't. Writing forces clarity.",
142
+ "action": "Log: Date, Signal, Size, Rationale, Outcome, Emotion Level (1-10). Review monthly."
143
+ },
144
+ {
145
+ "rule": "NEVER compare yourself to others",
146
+ "why": "Social media shows winners, not losers. Everyone has drawdowns.",
147
+ "action": "Your only benchmark is your own track record. Beat your previous self."
148
+ },
149
+ {
150
+ "rule": "ALWAYS sleep well at night",
151
+ "why": "If you can't sleep because of positions, your risk is too high. Your body is telling you.",
152
+ "action": "If you lose sleep, close 50% of the position tomorrow. Health > money."
153
+ }
154
+ ]
155
+ },
156
+
157
+ "strategy": {
158
+ "title": "STRATEGY - THE SCIENCE OF EDGE",
159
+ "rules": [
160
+ {
161
+ "rule": "ALWAYS have at least 3 uncorrelated alpha sources",
162
+ "why": "Price momentum and mean reversion can be negatively correlated. When one fails, the other works.",
163
+ "action": "AlphaForge uses: Price Technicals + Sentiment + Options Flow."
164
+ },
165
+ {
166
+ "rule": "NEVER overfit to historical data",
167
+ "why": "A strategy that perfectly fits the past will fail in the future. Markets change.",
168
+ "action": "Use walk-forward testing. Never optimize on the test set."
169
+ },
170
+ {
171
+ "rule": "ALWAYS monitor for regime changes",
172
+ "why": "Strategies that work in bull markets often fail in bear markets.",
173
+ "action": "Reduce beta in bear markets, increase in bull. AlphaForge detects regimes automatically."
174
+ },
175
+ {
176
+ "rule": "NEVER ignore the base rate",
177
+ "why": "If SPY goes up 55% of days, any 'long every day' strategy wins 55%. Report ALPHA, not return.",
178
+ "action": "If alpha < 2%, you are a closet indexer. Just buy SPY."
179
+ },
180
+ {
181
+ "rule": "ALWAYS diversify across time horizons",
182
+ "why": "Short-term (1-5 days) and long-term (1-3 months) signals have different drawdown periods.",
183
+ "action": "Run AlphaForge on 5-day, 21-day, and 63-day horizons. Blend 40/30/30."
184
+ }
185
+ ]
186
+ }
187
+ }
188
+
189
+ # GOAT TIER DEFINITIONS
190
+ GOAT_TIERS = {
191
+ "NEEDS_WORK": {
192
+ "range": (0, 40),
193
+ "emoji": "🔧",
194
+ "description": "You're learning. Don't trade real money yet.",
195
+ "advice": [
196
+ "Paper trade for 6 months minimum",
197
+ "Focus on risk management above all else",
198
+ "Read 'A Random Walk Down Wall Street' by Malkiel",
199
+ "Study the backtest metrics until you dream about Sharpe ratios"
200
+ ]
201
+ },
202
+ "DEVELOPING": {
203
+ "range": (40, 55),
204
+ "emoji": "📈",
205
+ "description": "You have potential. Keep grinding.",
206
+ "advice": [
207
+ "Trade with 10% of your intended capital",
208
+ "Focus on one alpha source until you master it",
209
+ "Journal every trade religiously",
210
+ "Review your metrics weekly, not daily"
211
+ ]
212
+ },
213
+ "SOLID_PRO": {
214
+ "range": (55, 70),
215
+ "emoji": "💪",
216
+ "description": "You're making real money. Stay disciplined.",
217
+ "advice": [
218
+ "Scale to 50% of intended capital",
219
+ "Add a second uncorrelated alpha source",
220
+ "Implement dynamic position sizing based on Sharpe",
221
+ "Start tracking tax efficiency"
222
+ ]
223
+ },
224
+ "ELITE_QUANT": {
225
+ "range": (70, 85),
226
+ "emoji": "⭐",
227
+ "description": "You're in the top 5% of active managers.",
228
+ "advice": [
229
+ "Scale to full capital allocation",
230
+ "Consider managing money for friends/family",
231
+ "Add options hedging for tail risk protection",
232
+ "Document your process for institutional capital"
233
+ ]
234
+ },
235
+ "LEGENDARY_GOAT": {
236
+ "range": (85, 100),
237
+ "emoji": "🐐",
238
+ "description": "You're competing with Renaissance and Two Sigma.",
239
+ "advice": [
240
+ "Consider launching a hedge fund",
241
+ "Hire a risk manager",
242
+ "Diversify into alternative data sources",
243
+ "Protect your IP aggressively - this edge won't last forever"
244
+ ]
245
+ }
246
+ }
247
+
248
+
249
+ def print_goat_mindset():
250
+ print(GOAT_MINDSET)
251
+
252
+
253
+ def print_goat_rules():
254
+ for section, content in GOAT_RULES.items():
255
+ print(f"\n{'='*80}")
256
+ print(f" {content['title']}")
257
+ print(f"{'='*80}\n")
258
+ for i, rule in enumerate(content['rules'], 1):
259
+ print(f" {i}. {rule['rule']}")
260
+ print(f" WHY: {rule['why']}")
261
+ print(f" ACTION: {rule['action']}")
262
+ print()
263
+
264
+
265
+ def get_tier_advice(score: float) -> dict:
266
+ for tier_name, tier_info in GOAT_TIERS.items():
267
+ low, high = tier_info['range']
268
+ if low <= score < high:
269
+ return {
270
+ 'tier': tier_name,
271
+ 'emoji': tier_info['emoji'],
272
+ 'description': tier_info['description'],
273
+ 'advice': tier_info['advice']
274
+ }
275
+ return GOAT_TIERS['LEGENDARY_GOAT']
276
+
277
+
278
+ if __name__ == '__main__':
279
+ print_goat_mindset()
280
+ print_goat_rules()
281
+ for tier_name, tier_info in GOAT_TIERS.items():
282
+ print(f"{tier_info['emoji']} {tier_name}: {tier_info['description']}")