Pedot commited on
Commit
075cd2c
Β·
1 Parent(s): 91cf3a5

FCPO: remove DXY/Fed keywords, add MYR analysis, replace DXY card with MYR on dashboard+bots

Browse files
Files changed (4) hide show
  1. analyzer.py +103 -45
  2. bot.py +16 -11
  3. config.py +4 -4
  4. dashboard.py +13 -4
analyzer.py CHANGED
@@ -192,16 +192,24 @@ class SentimentAnalyzer:
192
  risk_off_signals = 0
193
  risk_on_signals = 0
194
 
195
- if geo_intensity in ["High", "Moderate"]:
196
- risk_off_signals += 2
197
- if macro_bias == "Dovish":
198
- risk_off_signals += 2
199
- if macro_bias == "Hawkish":
200
- risk_on_signals += 2
201
- if sentiment_score > 30:
202
- risk_off_signals += 1
203
- elif sentiment_score < -30:
204
- risk_on_signals += 1
 
 
 
 
 
 
 
 
205
 
206
  if risk_off_signals > risk_on_signals:
207
  return "Risk-Off"
@@ -251,7 +259,26 @@ class SentimentAnalyzer:
251
  supply_score -= 1
252
  return supply_score
253
 
254
- def generate_final_bias(self, sentiment_score, dxy_bias, geo_intensity, macro_bias, contrarian_signal, supply_score=0, articles=None):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  score = 0
256
 
257
  if sentiment_score > 50:
@@ -263,29 +290,48 @@ class SentimentAnalyzer:
263
  elif sentiment_score < -20:
264
  score -= 1
265
 
266
- if dxy_bias == "Bearish":
267
- score += 2
268
- elif dxy_bias == "Bullish":
269
- score -= 2
 
 
 
 
 
 
270
 
271
- if geo_intensity == "High":
272
- score += 2
273
- elif geo_intensity == "Moderate":
274
- score += 1
 
 
 
 
 
 
275
 
276
- if macro_bias == "Dovish":
277
- score += 2
278
- elif macro_bias == "Hawkish":
279
- score -= 2
 
 
 
280
 
281
  if self.commodity in ("wti", "fcpo"):
282
- score += supply_score
 
 
 
283
 
284
- if contrarian_signal == "YES":
285
- if sentiment_score > 75:
286
- score -= 3
287
- elif sentiment_score < -75:
288
- score += 3
 
289
 
290
  if score >= 4:
291
  bias = "Strong Buy"
@@ -303,22 +349,32 @@ class SentimentAnalyzer:
303
  if self.commodity == "wti":
304
  drivers.append("geopolitical supply risk")
305
  elif self.commodity == "fcpo":
306
- drivers.append("supply chain disruption")
307
  else:
308
  drivers.append("geopolitical fear premium")
309
- if macro_bias == "Dovish":
310
- drivers.append("dovish Fed expectations")
311
- elif macro_bias == "Hawkish":
312
- if self.commodity == "wti":
313
- drivers.append("hawkish Fed demand pressure")
314
- elif self.commodity == "fcpo":
315
- drivers.append("hawkish Fed pressure on EM demand")
316
- else:
317
- drivers.append("hawkish Fed pressure")
318
- if dxy_bias == "Bearish":
319
- drivers.append("weak dollar support")
320
- elif dxy_bias == "Bullish":
321
- drivers.append("strong dollar headwind")
 
 
 
 
 
 
 
 
 
 
322
  if self.commodity == "wti" and supply_score > 0:
323
  drivers.append("supply tightness")
324
  elif self.commodity == "wti" and supply_score < 0:
@@ -327,7 +383,7 @@ class SentimentAnalyzer:
327
  drivers.append("palm oil supply tightness")
328
  elif self.commodity == "fcpo" and supply_score < 0:
329
  drivers.append("palm oil oversupply")
330
- if contrarian_signal == "YES":
331
  drivers.append("contrarian reversal risk")
332
 
333
  if self.groq and self.groq.available:
@@ -351,9 +407,10 @@ class SentimentAnalyzer:
351
  contrarian = self.compute_contrarian_signal(sentiment_score)
352
  market_mood = self.determine_market_mood(geo_intensity, macro_bias, sentiment_score)
353
  dxy_bias = self.analyze_dxy(articles)
 
354
  supply_score = self._analyze_supply(articles)
355
  final_bias, justification = self.generate_final_bias(
356
- sentiment_score, dxy_bias, geo_intensity, macro_bias, contrarian, supply_score, articles
357
  )
358
 
359
  for a in articles:
@@ -384,6 +441,7 @@ class SentimentAnalyzer:
384
  "macro_bias": macro_bias,
385
  "market_mood": market_mood,
386
  "supply_score": supply_score,
 
387
  "commodity": self.commodity,
388
  }
389
  }
 
192
  risk_off_signals = 0
193
  risk_on_signals = 0
194
 
195
+ if self.commodity == "fcpo":
196
+ if sentiment_score > 30:
197
+ risk_on_signals += 2
198
+ elif sentiment_score < -30:
199
+ risk_off_signals += 2
200
+ if geo_intensity in ["High", "Moderate"]:
201
+ risk_off_signals += 1
202
+ else:
203
+ if geo_intensity in ["High", "Moderate"]:
204
+ risk_off_signals += 2
205
+ if macro_bias == "Dovish":
206
+ risk_off_signals += 2
207
+ if macro_bias == "Hawkish":
208
+ risk_on_signals += 2
209
+ if sentiment_score > 30:
210
+ risk_off_signals += 1
211
+ elif sentiment_score < -30:
212
+ risk_on_signals += 1
213
 
214
  if risk_off_signals > risk_on_signals:
215
  return "Risk-Off"
 
259
  supply_score -= 1
260
  return supply_score
261
 
262
+ def _analyze_myr(self, articles):
263
+ if self.commodity != "fcpo":
264
+ return "Neutral"
265
+ myr_score = 0
266
+ for a in articles:
267
+ text_lower = a["text"].lower()
268
+ has_myr = "myr" in text_lower or "ringgit" in text_lower or "malaysian" in text_lower
269
+ if not has_myr:
270
+ continue
271
+ if any(p in text_lower for p in ["weak", "falls", "drops", "slides", "declines", "depreciates"]):
272
+ myr_score -= 1
273
+ if any(p in text_lower for p in ["strong", "rallies", "rises", "firms", "gains", "appreciates"]):
274
+ myr_score += 1
275
+ if myr_score < -1:
276
+ return "Bearish"
277
+ if myr_score > 1:
278
+ return "Bullish"
279
+ return "Neutral"
280
+
281
+ def generate_final_bias(self, sentiment_score, dxy_bias, geo_intensity, macro_bias, contrarian_signal, supply_score=0, myr_bias="Neutral", articles=None):
282
  score = 0
283
 
284
  if sentiment_score > 50:
 
290
  elif sentiment_score < -20:
291
  score -= 1
292
 
293
+ if self.commodity == "fcpo":
294
+ if myr_bias == "Bearish":
295
+ score += 2
296
+ elif myr_bias == "Bullish":
297
+ score -= 2
298
+ else:
299
+ if dxy_bias == "Bearish":
300
+ score += 2
301
+ elif dxy_bias == "Bullish":
302
+ score -= 2
303
 
304
+ if self.commodity == "fcpo":
305
+ if geo_intensity == "High":
306
+ score += 1
307
+ elif geo_intensity == "Moderate":
308
+ score += 1
309
+ else:
310
+ if geo_intensity == "High":
311
+ score += 2
312
+ elif geo_intensity == "Moderate":
313
+ score += 1
314
 
315
+ if self.commodity == "fcpo":
316
+ pass
317
+ else:
318
+ if macro_bias == "Dovish":
319
+ score += 2
320
+ elif macro_bias == "Hawkish":
321
+ score -= 2
322
 
323
  if self.commodity in ("wti", "fcpo"):
324
+ if self.commodity == "fcpo":
325
+ score += supply_score * 2
326
+ else:
327
+ score += supply_score
328
 
329
+ if self.commodity != "fcpo":
330
+ if contrarian_signal == "YES":
331
+ if sentiment_score > 75:
332
+ score -= 3
333
+ elif sentiment_score < -75:
334
+ score += 3
335
 
336
  if score >= 4:
337
  bias = "Strong Buy"
 
349
  if self.commodity == "wti":
350
  drivers.append("geopolitical supply risk")
351
  elif self.commodity == "fcpo":
352
+ drivers.append("trade disruption risk")
353
  else:
354
  drivers.append("geopolitical fear premium")
355
+ if self.commodity != "fcpo":
356
+ if macro_bias == "Dovish":
357
+ drivers.append("dovish Fed expectations")
358
+ elif macro_bias == "Hawkish":
359
+ if self.commodity == "wti":
360
+ drivers.append("hawkish Fed demand pressure")
361
+ else:
362
+ drivers.append("hawkish Fed pressure")
363
+ else:
364
+ if macro_bias == "Dovish":
365
+ drivers.append("easier global financial conditions")
366
+ elif macro_bias == "Hawkish":
367
+ drivers.append("tighter global financial conditions")
368
+ if self.commodity == "fcpo":
369
+ if myr_bias == "Bearish":
370
+ drivers.append("weak Ringgit support")
371
+ elif myr_bias == "Bullish":
372
+ drivers.append("strong Ringgit headwind")
373
+ else:
374
+ if dxy_bias == "Bearish":
375
+ drivers.append("weak dollar support")
376
+ elif dxy_bias == "Bullish":
377
+ drivers.append("strong dollar headwind")
378
  if self.commodity == "wti" and supply_score > 0:
379
  drivers.append("supply tightness")
380
  elif self.commodity == "wti" and supply_score < 0:
 
383
  drivers.append("palm oil supply tightness")
384
  elif self.commodity == "fcpo" and supply_score < 0:
385
  drivers.append("palm oil oversupply")
386
+ if self.commodity != "fcpo" and contrarian_signal == "YES":
387
  drivers.append("contrarian reversal risk")
388
 
389
  if self.groq and self.groq.available:
 
407
  contrarian = self.compute_contrarian_signal(sentiment_score)
408
  market_mood = self.determine_market_mood(geo_intensity, macro_bias, sentiment_score)
409
  dxy_bias = self.analyze_dxy(articles)
410
+ myr_bias = self._analyze_myr(articles)
411
  supply_score = self._analyze_supply(articles)
412
  final_bias, justification = self.generate_final_bias(
413
+ sentiment_score, dxy_bias, geo_intensity, macro_bias, contrarian, supply_score, myr_bias, articles
414
  )
415
 
416
  for a in articles:
 
441
  "macro_bias": macro_bias,
442
  "market_mood": market_mood,
443
  "supply_score": supply_score,
444
+ "myr_bias": myr_bias,
445
  "commodity": self.commodity,
446
  }
447
  }
bot.py CHANGED
@@ -158,12 +158,20 @@ def generate_report(commodity="gold", groq_client=None):
158
  title = escape_md2(a["title"][:60])
159
  articles_text += f"\n{i}\\. {indicator} _{title}_"
160
 
161
- supply_line = ""
162
- if commodity in ("wti", "fcpo"):
163
  supply_score = meta.get("supply_score", 0)
164
  supply_label = "Tight" if supply_score > 0 else "Oversupply" if supply_score < 0 else "Balanced"
165
- icon = "πŸ›’οΈ" if commodity == "wti" else "🌴"
166
- supply_line = f"\n{icon} *Supply\\:* {escape_md2(supply_label)} \\({supply_score}\\)"
 
 
 
 
 
 
 
 
167
 
168
  report = f"""*{escape_md2(cfg['display_name'])} Sentiment Report*
169
  πŸ“… {escape_md2(datetime.now(MYT).strftime('%d %b %Y, %H:%M'))} MYT
@@ -174,10 +182,9 @@ def generate_report(commodity="gold", groq_client=None):
174
  {be} *{escape_md2(fs[bias_key])}*
175
 
176
  *━━━ METRICS ━━━*
177
- πŸ“Š *Sentiment\\:* {a2[score_key]} \\({escape_md2(a2['sentiment_label'])}\\)
178
- {mood_emoji} *Mood\\:* {escape_md2(a1['overall_market_mood'])}
179
- πŸ’΅ *DXY\\:* {escape_md2(a3['dxy_directional_bias'])}
180
- {contrarian_emoji} *Contrarian\\:* {escape_md2(a2['contrarian_signal'])}{supply_line}
181
 
182
  *━━━ MACRO ━━━*
183
  {escape_md2(a1['macro_event_impact'])}
@@ -193,9 +200,7 @@ def generate_report(commodity="gold", groq_client=None):
193
  *━━━ JUSTIFICATION ━━━*
194
  {escape_md2(fs['justification'])}
195
 
196
- _Data\\: VADER \\+ Rule\\-Based \\| {meta['articles_analyzed']} articles_"""
197
-
198
- return report
199
 
200
 
201
  async def start_cmd(update: Update, context: ContextTypes.DEFAULT_TYPE):
 
158
  title = escape_md2(a["title"][:60])
159
  articles_text += f"\n{i}\\. {indicator} _{title}_"
160
 
161
+ if commodity == "fcpo":
162
+ dxy_line = f"πŸ’± *MYR:* {escape_md2(meta.get('myr_bias', 'Neutral'))}"
163
  supply_score = meta.get("supply_score", 0)
164
  supply_label = "Tight" if supply_score > 0 else "Oversupply" if supply_score < 0 else "Balanced"
165
+ supply_line = f"🌴 *Supply:* {escape_md2(supply_label)} \\({supply_score}\\)"
166
+ contrarian_line = ""
167
+ else:
168
+ dxy_line = f"πŸ’΅ *DXY:* {escape_md2(a3['dxy_directional_bias'])}"
169
+ supply_line = ""
170
+ if commodity == "wti":
171
+ supply_score = meta.get("supply_score", 0)
172
+ supply_label = "Tight" if supply_score > 0 else "Oversupply" if supply_score < 0 else "Balanced"
173
+ supply_line = f"\nπŸ›’οΈ *Supply:* {escape_md2(supply_label)} \\({supply_score}\\)"
174
+ contrarian_line = f"\n{contrarian_emoji} *Contrarian:* {escape_md2(a2['contrarian_signal'])}"
175
 
176
  report = f"""*{escape_md2(cfg['display_name'])} Sentiment Report*
177
  πŸ“… {escape_md2(datetime.now(MYT).strftime('%d %b %Y, %H:%M'))} MYT
 
182
  {be} *{escape_md2(fs[bias_key])}*
183
 
184
  *━━━ METRICS ━━━*
185
+ πŸ“Š *Sentiment:* {a2[score_key]} \\({escape_md2(a2['sentiment_label'])}\\)
186
+ {mood_emoji} *Mood:* {escape_md2(a1['overall_market_mood'])}
187
+ {dxy_line}{contrarian_line}{supply_line}
 
188
 
189
  *━━━ MACRO ━━━*
190
  {escape_md2(a1['macro_event_impact'])}
 
200
  *━━━ JUSTIFICATION ━━━*
201
  {escape_md2(fs['justification'])}
202
 
203
+ _Data: Groq AI \\+ VADER \\| {meta['articles_analyzed']} articles_"""
 
 
204
 
205
 
206
  async def start_cmd(update: Update, context: ContextTypes.DEFAULT_TYPE):
config.py CHANGED
@@ -163,12 +163,12 @@ COMMODITY_CONFIGS = {
163
  "currency": "RM",
164
  "keywords": {
165
  "fcpo": ["FCPO", "CPO", "crude palm oil", "palm oil futures", "bursa derivatives", "palm oil price"],
166
- "supply": ["MPOB", "stock", "inventory", "production", "FFB", "OER", "output", "yield", "crop"],
167
- "demand": ["export", "India import", "China import", "biodiesel", "B20", "B40", "POGO", "blending"],
168
- "weather": ["El NiΓ±o", "La NiΓ±a", "drought", "monsoon", "rainfall", "flood", "dry spell"],
169
  "policy": ["DMO", "export levy", "export ban", "EUDR", "RSPO", "MSPO", "tariff", "quota"],
170
  "competing": ["soybean oil", "CBOT", "rapeseed", "sunflower oil", "differential", "spread"],
171
- "myr": ["MYR", "Ringgit", "Malaysian ringgit", "forex"],
172
  "geopolitical": ["Geopolitical", "War", "Conflict", "Tension", "Sanctions", "Russia", "Ukraine", "tariff", "trade war"],
173
  },
174
  "rss_feeds": [
 
163
  "currency": "RM",
164
  "keywords": {
165
  "fcpo": ["FCPO", "CPO", "crude palm oil", "palm oil futures", "bursa derivatives", "palm oil price"],
166
+ "supply": ["MPOB", "stock", "inventory", "production", "FFB", "OER", "output", "yield", "crop", "supply"],
167
+ "demand": ["export", "India import", "China import", "biodiesel", "B20", "B40", "POGO", "blending", "import demand"],
168
+ "weather": ["El NiΓ±o", "La NiΓ±a", "drought", "monsoon", "rainfall", "flood", "dry spell", "weather"],
169
  "policy": ["DMO", "export levy", "export ban", "EUDR", "RSPO", "MSPO", "tariff", "quota"],
170
  "competing": ["soybean oil", "CBOT", "rapeseed", "sunflower oil", "differential", "spread"],
171
+ "myr": ["MYR", "Ringgit", "Malaysian ringgit", "forex", "currency"],
172
  "geopolitical": ["Geopolitical", "War", "Conflict", "Tension", "Sanctions", "Russia", "Ukraine", "tariff", "trade war"],
173
  },
174
  "rss_feeds": [
dashboard.py CHANGED
@@ -416,9 +416,15 @@ def main():
416
  with col2:
417
  st.markdown(metric_card("Market Mood", a1["overall_market_mood"]), unsafe_allow_html=True)
418
  with col3:
419
- dxy_delta = "↑ Dollar" if a3["dxy_directional_bias"] == "Bullish" else "↓ Dollar" if a3["dxy_directional_bias"] == "Bearish" else "β€”"
420
- dxy_dc = "#FF453A" if a3["dxy_directional_bias"] == "Bullish" else "#30D158" if a3["dxy_directional_bias"] == "Bearish" else "#86868B"
421
- st.markdown(metric_card("DXY Bias", a3["dxy_directional_bias"], dxy_delta, dxy_dc), unsafe_allow_html=True)
 
 
 
 
 
 
422
  with col4:
423
  if commodity in ("wti", "fcpo"):
424
  supply_score = meta.get("supply_score", 0)
@@ -451,7 +457,10 @@ def main():
451
 
452
  col_macro, col_geo = st.columns(2)
453
  with col_macro:
454
- st.markdown(f'<div><div style="color:#86868B;font-size:11px;font-weight:600;letter-spacing:0.1em;text-transform:uppercase;font-family:{APPLE_FONT};margin-bottom:16px;">Macro & Fed</div><div style="color:#F5F5F7;font-size:14px;line-height:1.6;font-family:{APPLE_FONT};">{a1["macro_event_impact"]}</div><div style="margin-top:12px;color:#86868B;font-size:12px;font-family:{APPLE_FONT};">Bias: <span style="color:#0A84FF;font-weight:600;">{meta["macro_bias"]}</span></div></div>', unsafe_allow_html=True)
 
 
 
455
  with col_geo:
456
  st.markdown(f'<div><div style="color:#86868B;font-size:11px;font-weight:600;letter-spacing:0.1em;text-transform:uppercase;font-family:{APPLE_FONT};margin-bottom:16px;">Geopolitical</div><div style="color:#F5F5F7;font-size:14px;line-height:1.6;font-family:{APPLE_FONT};">{a1["geopolitical_summary"]}</div><div style="margin-top:12px;color:#86868B;font-size:12px;font-family:{APPLE_FONT};">Intensity: <span style="color:#FF9F0A;font-weight:600;">{meta["geo_intensity"]}</span></div></div>', unsafe_allow_html=True)
457
 
 
416
  with col2:
417
  st.markdown(metric_card("Market Mood", a1["overall_market_mood"]), unsafe_allow_html=True)
418
  with col3:
419
+ if commodity == "fcpo":
420
+ myr_bias = meta.get("myr_bias", "Neutral")
421
+ myr_delta = "↓ Ringgit" if myr_bias == "Bearish" else "↑ Ringgit" if myr_bias == "Bullish" else "β€”"
422
+ myr_dc = "#30D158" if myr_bias == "Bearish" else "#FF453A" if myr_bias == "Bullish" else "#8E8E93"
423
+ st.markdown(metric_card("MYR (Ringgit)", myr_bias, myr_delta, myr_dc), unsafe_allow_html=True)
424
+ else:
425
+ dxy_delta = "↑ Dollar" if a3["dxy_directional_bias"] == "Bullish" else "↓ Dollar" if a3["dxy_directional_bias"] == "Bearish" else "β€”"
426
+ dxy_dc = "#FF453A" if a3["dxy_directional_bias"] == "Bullish" else "#30D158" if a3["dxy_directional_bias"] == "Bearish" else "#86868B"
427
+ st.markdown(metric_card("DXY Bias", a3["dxy_directional_bias"], dxy_delta, dxy_dc), unsafe_allow_html=True)
428
  with col4:
429
  if commodity in ("wti", "fcpo"):
430
  supply_score = meta.get("supply_score", 0)
 
457
 
458
  col_macro, col_geo = st.columns(2)
459
  with col_macro:
460
+ if commodity == "fcpo":
461
+ st.markdown(f'<div><div style="color:#86868B;font-size:11px;font-weight:600;letter-spacing:0.1em;text-transform:uppercase;font-family:{APPLE_FONT};margin-bottom:16px;">Supply & Policy</div><div style="color:#F5F5F7;font-size:14px;line-height:1.6;font-family:{APPLE_FONT};">{a1["macro_event_impact"]}</div><div style="margin-top:12px;color:#86868B;font-size:12px;font-family:{APPLE_FONT};">Supply: <span style="color:#30D158;font-weight:600;">{meta.get("supply_score",0):+d}</span></div></div>', unsafe_allow_html=True)
462
+ else:
463
+ st.markdown(f'<div><div style="color:#86868B;font-size:11px;font-weight:600;letter-spacing:0.1em;text-transform:uppercase;font-family:{APPLE_FONT};margin-bottom:16px;">Macro & Fed</div><div style="color:#F5F5F7;font-size:14px;line-height:1.6;font-family:{APPLE_FONT};">{a1["macro_event_impact"]}</div><div style="margin-top:12px;color:#86868B;font-size:12px;font-family:{APPLE_FONT};">Bias: <span style="color:#0A84FF;font-weight:600;">{meta["macro_bias"]}</span></div></div>', unsafe_allow_html=True)
464
  with col_geo:
465
  st.markdown(f'<div><div style="color:#86868B;font-size:11px;font-weight:600;letter-spacing:0.1em;text-transform:uppercase;font-family:{APPLE_FONT};margin-bottom:16px;">Geopolitical</div><div style="color:#F5F5F7;font-size:14px;line-height:1.6;font-family:{APPLE_FONT};">{a1["geopolitical_summary"]}</div><div style="margin-top:12px;color:#86868B;font-size:12px;font-family:{APPLE_FONT};">Intensity: <span style="color:#FF9F0A;font-weight:600;">{meta["geo_intensity"]}</span></div></div>', unsafe_allow_html=True)
466