Quick Start - risik01/stock-ai GitHub Wiki
โก Quick Start Guide - Stock AI Trading System
Inizia subito con il Stock AI Trading System! Questa guida ti porterร dall'installazione alla prima sessione di trading in meno di 15 minuti.
๐ฏ Obiettivo Quick Start
Al termine di questa guida avrai:
- โ Sistema completamente funzionante
- โ Portfolio virtuale attivo con $10K
- โ News Trading AI operativo
- โ Dashboard web accessibili
- โ Prima sessione di trading simulato
โฑ๏ธ 15-Minute Setup
โก Step 1: Clone & Setup (3 min)
# Clone repository
git clone https://github.com/risik01/stock-ai.git
cd stock-ai
# Crea virtual environment
python3 -m venv venv
source venv/bin/activate # Linux/macOS
# venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
โก Step 2: News Dependencies (2 min)
# Install News Trading dependencies
pip install feedparser textblob vaderSentiment nltk beautifulsoup4 lxml
# Download NLTK data
python -c "import nltk; nltk.download('vader_lexicon'); nltk.download('punkt')"
โก Step 3: Quick Test (5 min)
# Test 1: Data collection
python src/data_collector.py --symbols AAPL --period 1mo
# Test 2: News system
python trading-new/news_trading_cli.py cycle
# Test 3: RL Agent
python src/test_rl.py --quick
# Test 4: Web dashboard
python src/web_dashboard.py &
python trading-new/news_web_dashboard.py &
โก Step 4: First Trading Session (5 min)
# Avvia trading automatico simulato
python src/main.py --mode simulation --duration 300 # 5 minuti
# Monitora in tempo reale
python src/cli_monitor.py
๐ฎ Demo Mode - Prova Immediata
๐ Modalitร Demo Completa
# Avvia tutto in demo mode
./scripts/demo_start.sh
# O manualmente:
python src/main.py --demo --symbols AAPL,GOOGL,TSLA --duration 600
Cosa include Demo Mode:
- ๐ Dati Live: Prezzi reali da Yahoo Finance
- ๐ค RL Agent: Pre-trained model per decisioni immediate
- ๐ฐ News Analysis: Sentiment analysis in tempo reale
- ๐ฐ Virtual Portfolio: $10,000 iniziali
- ๐ Live Dashboard: Grafici e metriche real-time
๐ Cosa Vedere Durante Demo
Terminal Output:
๐ค RL Agent initialized - Model loaded
๐ฐ News collector started - 6/10 sources active
๐ฐ Portfolio: $10,000 (100% cash)
๐ Monitoring: AAPL, GOOGL, TSLA
[12:34:56] ๐ AAPL: $175.30 (+0.5%) | Sentiment: +0.2 | Signal: BUY
[12:35:12] ๐ฅ Breaking: Apple earnings beat expectations (Sentiment: +0.7)
[12:35:15] ๐ฐ TRADE: BUY AAPL 28 shares @ $175.30 ($4,908.40)
[12:35:16] ๐ Portfolio: $5,091.60 cash + $4,908.40 stocks = $10,000.00
Web Dashboard:
- http://localhost:5000 - Main dashboard
- http://localhost:5001 - News dashboard
๐ฏ Primi Comandi Essenziali
๐ Monitoraggio Portfolio
# Status portfolio corrente
python src/portfolio.py --status
# Performance history
python src/portfolio.py --history
# Risk analysis
python src/portfolio.py --risk
Output Example:
๐ฐ PORTFOLIO STATUS
โโโ Total Value: $10,247.50 (+2.48%)
โโโ Cash: $2,150.30 (21.0%)
โโโ Positions: 3 active
โ โโโ AAPL: 28 shares ($4,908.40, +1.2%)
โ โโโ GOOGL: 15 shares ($2,189.85, +3.1%)
โ โโโ TSLA: 8 shares ($998.95, -0.8%)
โโโ P&L Today: +$97.35 (+0.98%)
๐ฐ News Analysis
# Latest news analysis
python trading-new/news_trading_cli.py news
# Current signals
python trading-new/news_trading_cli.py signals
# Breaking news alerts
python trading-new/news_trading_cli.py alerts
Output Example:
๐ฐ NEWS ANALYSIS (Last Hour)
โโโ Articles: 47 collected from 6 sources
โโโ Breaking News: 3 items
โโโ Sentiment Score: +0.15 (Slightly Positive)
โโโ Trading Signals: 2 BUY, 1 SELL
๐ฏ ACTIVE SIGNALS
โโโ AAPL: BUY (Sentiment: +0.3, Confidence: 0.8)
โโโ TSLA: SELL (Sentiment: -0.2, Confidence: 0.7)
โโโ GOOGL: HOLD (Sentiment: +0.1, Confidence: 0.5)
๐ค RL Agent Control
# Agent status
python src/rl_agent.py --status
# Force retrain (if needed)
python src/train_rl.py --episodes 100
# Model performance
python src/rl_agent.py --performance
๐ Dashboard Walkthrough
http://localhost:5000)
๐ Main Dashboard (Sezioni Principali:
- ๐ Overview: Portfolio value, daily P&L, win rate
- ๐ Charts: Price charts con segnali RL
- ๐ฐ Portfolio: Posizioni correnti e allocation
- ๐ Performance: Metriche storiche e benchmark
- โ๏ธ Settings: Configurazione live
Key Metrics da Monitorare:
- Total Portfolio Value: Valore totale investimenti
- Daily Return: Performance giornaliera
- Sharpe Ratio: Rendimento aggiustato per rischio
- Max Drawdown: Massima perdita dal picco
- Win Rate: Percentuale trades profittevoli
http://localhost:5001)
๐ฐ News Dashboard (Sezioni:
- ๐ฐ Live Feed: Stream notizie in tempo reale
- ๐ฏ Signals: Segnali trading basati su news
- ๐ Sentiment: Grafici sentiment per simbolo
- ๐จ Alerts: Breaking news e eventi critici
- ๐ Impact: Correlazione news-prezzi
Funzionalitร Interattive:
- Real-time Updates: Aggiornamento automatico ogni 30s
- Symbol Filtering: Filtra per simboli specifici
- Sentiment Timeline: Storia sentiment per simbolo
- News Source Toggle: Abilita/disabilita fonti specifiche
๐ฎ Modalitร Operative
๐ Simulation Mode (Default)
# Trading simulato - zero rischi
python src/main.py --mode simulation
# Caratteristiche:
# โ
Portfolio virtuale ($10K)
# โ
Prezzi reali di mercato
# โ
Trades registrati ma non eseguiti
# โ
Performance tracking completo
๐ Backtest Mode
# Test su dati storici
python src/main.py --mode backtest --start 2023-01-01 --end 2023-12-31
# Risultati:
# โ
Performance vs Buy & Hold
# โ
Maximum Drawdown analysis
# โ
Sharpe Ratio calculation
# โ
Trade statistics
๐๏ธ Watch Mode
# Solo monitoraggio, no trading
python src/main.py --mode watch --symbols AAPL,GOOGL,MSFT
# Output:
# โ
Prezzi live
# โ
Segnali generati
# โ
News sentiment
# โ
Nessun trade eseguito
๐ฏ Paper Trading Mode
# Trading realistico con denaro virtuale
python src/main.py --mode paper --cash 50000
# Simula:
# โ
Latency di mercato
# โ
Slippage dei prezzi
# โ
Transaction costs
# โ
Market hours restrictions
๐ ๏ธ Personalizzazione Rapida
๐ฏ Scegli i Tuoi Simboli
# Edita config/settings.json
nano config/settings.json
{
"data_collector": {
"symbols": ["AAPL", "GOOGL", "MSFT", "TSLA", "AMZN", "NVDA"],
"period": "2y",
"interval": "1d"
}
}
๐ฐ Personalizza Portfolio
{
"portfolio": {
"initial_cash": 50000, // $50K invece di $10K
"max_position_size": 0.15, // Max 15% per posizione
"transaction_cost": 0.0005, // 0.05% transaction cost
"stop_loss": 0.05 // Stop-loss a 5%
}
}
๐ฐ Configura News Sources
{
"news": {
"sources": {
"yahoo_finance": true,
"cnbc": true,
"reuters": true,
"bloomberg": false, // Disabilita se non necessario
"marketwatch": true
},
"update_interval": 300, // Ogni 5 minuti
"sentiment_threshold": 0.1 // Soglia per segnali
}
}
๐ Primi Risultati - Cosa Aspettarsi
โ Successo Indicators
Dopo 1 ora di trading:
- ๐ Portfolio Value: Oscillazioni tra -2% e +3%
- ๐ค RL Decisions: 5-15 segnali generati
- ๐ฐ News Analysis: 20-50 articoli processati
- ๐ฐ Trades: 1-3 trades eseguiti
- ๐ Performance: Tracking accurato
Log Output Tipico:
[14:30:15] ๐ Market Open - Starting analysis
[14:30:45] ๐ฐ Collected 23 news articles
[14:31:02] ๐ค RL Signal: AAPL BUY (confidence: 0.72)
[14:31:05] ๐ News Sentiment: AAPL +0.3 (positive)
[14:31:08] ๐ฐ TRADE: BUY AAPL 15 shares @ $175.42
[14:31:10] ๐ฏ Portfolio: +0.15% today
โ ๏ธ Warning Signs da Controllare
- RSS Errors: >50% fonti fallite
- Model Errors: RL agent non risponde
- Data Gaps: Prezzi non aggiornati
- Memory Issues: Usage >80%
- Performance: Cycle time >30s
๐ฏ Configurazioni Raccomandate
๐ฐ Principiante
{
"symbols": ["AAPL", "GOOGL", "MSFT"],
"initial_cash": 10000,
"max_position_size": 0.2,
"mode": "simulation",
"risk_tolerance": "low"
}
๐ Intermediate
{
"symbols": ["AAPL", "GOOGL", "MSFT", "TSLA", "AMZN", "NVDA"],
"initial_cash": 25000,
"max_position_size": 0.15,
"mode": "paper",
"risk_tolerance": "medium"
}
๐ Advanced
{
"symbols": ["AAPL", "GOOGL", "MSFT", "TSLA", "AMZN", "NVDA", "META", "NFLX"],
"initial_cash": 100000,
"max_position_size": 0.1,
"mode": "paper",
"risk_tolerance": "high",
"enable_shorting": true
}
๐ Prossimi Passi
Dopo il Quick Start, esplora:
๐ Approfondimenti
- RL Agent Overview - Capire l'AI trading
- News Trading Overview - Sentiment analysis
- Configuration Files - Setup avanzato
- Performance Analysis - Ottimizzare risultati
๐ ๏ธ Customizzazione
- Nuove Strategie: Sviluppa algoritmi custom
- Additional Data: Integra piรน fonti dati
- Risk Management: Implementa stop-loss avanzati
- Alert System: Setup notifiche Discord/Slack
๐ Produzione
- Live Trading: Migrazione a broker reale
- Cloud Deployment: Deploy su AWS/GCP
- Monitoring: Setup alerting professionale
- Scaling: Multiple accounts/strategies
๐ Quick Troubleshooting
โ Errori Comuni
# Problema: ModuleNotFoundError
pip install -r requirements.txt
# Problema: Portfolio non si carica
rm data/current_portfolio.pkl
python src/portfolio.py --reset
# Problema: News feeds non funzionano
python trading-new/news_rss_collector.py --debug
# Problema: RL Agent errori
python src/train_rl.py --episodes 50 --force
๐ง Reset Completo
# Reset tutto ai defaults
rm -rf data/cache/*
rm data/current_portfolio.pkl data/rl_model.pkl
cp config/settings.json.example config/settings.json
python src/main.py --init
๐ Congratulazioni!
๐ Il tuo Stock AI Trading System รจ ora operativo!
- โ Sistema funzionante in meno di 15 minuti
- โ Portfolio virtuale attivo
- โ News trading automatico
- โ Dashboard live accessibili
- โ Pronto per trading simulato
Next: Esplora le funzionalitร avanzate e personalizza il sistema secondo le tue esigenze!
Happy Trading! ๐๐ฐ