News Trading Overview - risik01/stock-ai GitHub Wiki
Il News Trading AI è un modulo avanzato che aggiunge capacità di trading basate sull'analisi del sentiment delle notizie finanziarie in tempo reale.
- Monitora 10+ fonti RSS finanziarie autorevoli
- Raccolta parallela e ottimizzata per performance
- Breaking news detection per eventi critici
- Filtro intelligente per simboli azionari rilevanti
- Triple method approach: TextBlob + VADER + Financial Dictionary
- Confidence scoring per affidabilità analisi
- Context-aware analysis specifico per testo finanziario
- Real-time processing di centinaia di articoli
- Segnali BUY/SELL basati su sentiment aggregato
- Portfolio virtuale per simulazione sicura
- Risk management integrato
- Alert system per eventi critici
graph TD
A[RSS Feeds] --> B[News Collector]
B --> C[Sentiment Analyzer]
C --> D[Trading AI Engine]
D --> E[Virtual Portfolio]
D --> F[Alert System]
D --> G[Web Dashboard]
D --> H[CLI Interface]
Componente | File | Righe | Funzione |
---|---|---|---|
RSS Collector | news_rss_collector.py |
450+ | Raccolta notizie da fonti multiple |
Sentiment Analyzer | news_sentiment_analyzer.py |
500+ | Analisi sentiment ibrida |
Trading AI | news_based_trading_ai.py |
600+ | Engine di trading principale |
CLI Interface | news_trading_cli.py |
400+ | Interfaccia riga di comando |
Web Dashboard | news_web_dashboard.py |
350+ | Server web + API REST |
Dashboard HTML | news_dashboard.html |
800+ | Frontend responsive |
Fonte | URL | Articoli/Ora | Affidabilità |
---|---|---|---|
Yahoo Finance | feeds.finance.yahoo.com |
15-25 | ⭐⭐⭐⭐⭐ |
CNBC | cnbc.com/rss |
20-30 | ⭐⭐⭐⭐⭐ |
Reuters Business | reuters.com/rss |
10-20 | ⭐⭐⭐⭐⭐ |
Bloomberg | bloomberg.com/rss |
10-15 | ⭐⭐⭐⭐⭐ |
Fonte | Focus | Aggiornamenti |
---|---|---|
MarketWatch | Market analysis | Ogni 15 min |
Seeking Alpha | Investment research | Ogni 30 min |
Benzinga | Trading news | Real-time |
The Motley Fool | Long-term investing | Daily |
Finviz | Market screening | Hourly |
Zacks | Earnings & ratings | Daily |
# Analisi sentiment generale
polarity = TextBlob(text).sentiment.polarity # -1 a +1
subjectivity = TextBlob(text).sentiment.subjectivity # 0 a 1
- Peso: 30% del sentiment totale
- Strengths: Veloce, generale purpose
- Weaknesses: Non specifico per finanza
# Ottimizzato per social media e testi informali
analyzer = SentimentIntensityAnalyzer()
scores = analyzer.polarity_scores(text)
compound_score = scores['compound'] # -1 a +1
- Peso: 40% del sentiment totale
- Strengths: Context-aware, gestisce emoji/slang
- Use case: News con tone colloquiale
# Dizionario specializzato con 500+ termini finanziari
financial_terms = {
'bullish': 0.8, 'bearish': -0.8,
'earnings beat': 0.6, 'revenue miss': -0.5,
'upgrade': 0.7, 'downgrade': -0.7
# ... 500+ termini
}
- Peso: 30% del sentiment totale
- Strengths: Specifico per finanza
- Coverage: Earnings, rating, market conditions
final_sentiment = (
textblob_score * 0.3 +
vader_score * 0.4 +
financial_score * 0.3
)
confidence = calculate_agreement_confidence(scores)
Confidence Calculation:
- Alta (>0.8): Tutti e 3 i metodi concordi
- Media (0.5-0.8): 2 metodi su 3 concordi
- Bassa (<0.5): Disaccordo tra metodi
def generate_signal(sentiment_score, confidence, news_count):
if confidence < 0.6:
return 'HOLD' # Sentiment incerto
if sentiment_score > 0.3 and confidence > 0.8:
return 'STRONG_BUY'
elif sentiment_score > 0.1 and confidence > 0.7:
return 'BUY'
elif sentiment_score < -0.1 and confidence > 0.7:
return 'SELL'
elif sentiment_score < -0.3 and confidence > 0.8:
return 'STRONG_SELL'
else:
return 'HOLD'
Sentiment Score | Confidence | Action | Description |
---|---|---|---|
> +0.3 |
> 0.8 |
STRONG_BUY | Sentiment molto positivo, alta fiducia |
+0.1 to +0.3 |
> 0.7 |
BUY | Sentiment positivo |
-0.1 to +0.1 |
any |
HOLD | Sentiment neutrale |
-0.3 to -0.1 |
> 0.7 |
SELL | Sentiment negativo |
< -0.3 |
> 0.8 |
STRONG_SELL | Sentiment molto negativo, alta fiducia |
Il peso delle notizie diminuisce nel tempo:
def apply_time_decay(sentiment, age_hours):
decay_factor = math.exp(-age_hours * 0.1) # 10% decay per ora
return sentiment * decay_factor
VIRTUAL_PORTFOLIO = {
'initial_cash': 10000, # $10K iniziali
'max_position_size': 0.2, # 20% max per simbolo
'transaction_cost': 0.001, # 0.1% costo per trade
'minimum_trade': 100 # $100 trade minimo
}
- Total Portfolio Value: Valore totale (cash + posizioni)
- Realized P&L: Profitti/perdite realizzate
- Unrealized P&L: P&L posizioni aperte
- Trade Count: Numero totale trades
- Win Rate: Percentuale trades profittevoli
- Average Hold Time: Tempo medio mantenimento posizioni
Tipo | Trigger | Esempio |
---|---|---|
CRITICAL | Sentiment estremo | "AAPL: Sentiment -0.85 (SELL signal)" |
WARNING | Volatilità alta | "TSLA: Volume spike +250%" |
INFO | Nuovi segnali | "GOOGL: BUY signal generato" |
- Console: Output immediato
- Log File: Registrazione persistente
- Web Dashboard: Alert in tempo reale
- API Endpoint: Per integrazioni esterne
# Comandi principali
python news_trading_cli.py news # Analisi notizie
python news_trading_cli.py signals # Segnali trading
python news_trading_cli.py cycle # Ciclo singolo
python news_trading_cli.py auto # Trading automatico
python news_trading_cli.py portfolio # Status portfolio
URL: http://localhost:5001
Sezioni:
- 📊 Overview: Stats in tempo reale
- 📰 News Feed: Notizie live + breaking news
- 🎯 Trading Signals: Segnali attivi
- 💰 Portfolio: Gestione posizioni virtuali
- 📈 Charts: Grafici sentiment + performance
- 🚨 Alerts: Notifiche eventi critici
- Raccolta News: <0.5s per 60+ articoli
- Sentiment Analysis: <0.1s per articolo
- Signal Generation: <0.2s per simbolo
- Ciclo Completo: <10s per analisi full-market
- Threading Parallelo: Raccolta RSS concorrente
- Caching Intelligente: Evita re-analisi articoli
- Batch Processing: Elaborazione groupped
- Connection Pooling: Riuso connessioni HTTP
- Unit Tests: Ogni componente singolarmente
- Integration Tests: Flusso end-to-end
- Performance Tests: Benchmark speed/memory
- Reliability Tests: Gestione errori network
- ✅ 60+ articoli raccolti da fonti multiple
- ✅ 22 breaking news rilevate nell'ultima ora
- ✅ 95% uptime raccolta RSS
- ✅ <10s per ciclo completo
- ✅ 2-5 segnali generati per sessione
Il News Trading AI può essere integrato con il sistema principale per creare strategie ibride:
# Esempio integrazione
final_signal = (
rl_signal * 0.7 + # 70% RL/Technical
news_signal * 0.3 # 30% News Sentiment
)
Possibilità di dashboard unificata che mostra:
- Performance sistema principale
- Sentiment overview news
- Segnali combinati
- Risk metrics consolidati
- Portfolio Virtuale: Nessun denaro reale a rischio
- Prezzi Simulati: Basati su Yahoo Finance
- Trade Simulation: Registrati ma non eseguiti
- Safe Testing: Ambiente completamente sicuro
- RSS Feeds: Max 1 richiesta/30s per fonte
- Yahoo Finance: Max 1 richiesta/10s per simbolo
- Sentiment Analysis: Ottimizzata per velocità
- Error Handling: Retry automatico + fallback
- RSS Configuration - Configurare fonti news
- Sentiment Analysis - Approfondire analisi
- News Strategies - Sviluppare strategie custom
- Hybrid Integration - Integrare con sistema principale
Per documentazione tecnica dettagliata, vedere i file nella directory trading-new/