A quant trading system platform based on FinGPT, demonstrating new applications of large pre-trained Language Models in quantitative finance.
FinGPT Trader
A quantitative trading system that combines Falcon-7B language model-driven sentiment analysis with technical market analysis to identify cryptocurrency trading opportunities. The system's core innovation is its confidence-weighted sentiment scoring mechanism, which integrates both the sentiment value and the model's confidence level to generate more reliable trading signals.
System Overview
FinGPT Trader processes financial news and market data in parallel, combining both sources to identify potential trading opportunities. The system uses:
- Falcon-7B Model: Fine-tuned for financial sentiment analysis
- Confidence-Weighted Scoring: 60% confidence weight, 40% sentiment strength weight
- Technical Analysis: Standard technical indicators for market inefficiency detection
- RSS-first News Ingestion: Crypto-native publisher RSS feeds, with NewsAPI fallback
- Event-Driven Architecture: Asynchronous processing of market events
- Risk Management: Basic position tracking and exposure monitoring
Current Implementation Status
โ = Implemented | ๐ง = Partially Implemented | ๐ = Planned | โ ๏ธ = Implementation Issues
Core Components
- Sentiment Analysis
- Market Data Processing
- Trading Execution
- Risk Management
Technical Implementation
Confidence-Weighted Sentiment Analysis
The system's key innovation is its confidence-weighted sentiment scoring mechanism. Rather than using raw sentiment scores, FinGPT Trader weighs the model's confidence (60%) against sentiment strength (40%) to generate more reliable signals:
# Calculate confidence-weighted sentiment score
weightedscore = (confidence 0.6) (abs(sentimentscore) * 0.4)
Generate signal if weighted score exceeds detection threshold
if weightedscore > detectionthreshold:
signals.append({
'symbol': pair,
'type': 'SENTIMENT',
'direction': 1 if sentiment_score > 0 else -1,
'strength': abs(sentiment_score),
'confidence': confidence,
'price': current_price,
'timestamp': datetime.now()
})
This approach helps filter out low-confidence predictions, reducing false signals.
Market-Sentiment Correlation Tracking
The system maintains a history of sentiment and price movements to calculate correlation coefficients:
# Calculate correlation between sentiment changes and price changes
correlation = np.corrcoef(
sentimentchanges[:minlength],
pricechanges[:minlength]
)[0, 1]
Update correlation record for position sizing
self.market_correlation[symbol] = {
'value': correlation,
'updated_at': datetime.now(),
'samples': min_length
}
This correlation data helps adjust signal strength based on historical sentiment-price relationships.
System Architecture
graph TD
A[Falcon-7B Model] -->|Sentiment Analysis| B[Market Analysis Engine]
B -->|Signal Generation| C[Trading Core]
D[Binance API] -->|Market Data| B
C -->|Orders| D
E[Risk Monitor] -->|Position Limits| C
F[Portfolio Tracker] -->|Positions| C
G[Market Inefficiency Detector] -->|Trading Signals| B
H[News Data Feed] -->|Real-time News| A
style A fill:#d0f0c0
style B fill:#d0f0c0
style C fill:#f0e0a0
style D fill:#d0f0c0
style E fill:#f0e0a0
style F fill:#d0f0c0
style G fill:#d0f0c0
style H fill:#d0f0c0
classDef implemented fill:#d0f0c0;
classDef partial fill:#f0e0a0;
classDef planned fill:#f0d0d0;
Configuration
The system uses a hierarchical YAML-based configuration system:
trading.yaml: Core trading parameters, thresholds, and position sizingstrategies.yaml: Strategy-specific parameters and detection thresholdsmodel.yaml: ML model configurationsservices.yaml: External service connectivity parameters
News Sources
News ingestion is RSS-first. Default feeds are configured in config/services.yaml:
- CoinDesk:
https://www.coindesk.com/arc/outboundfeeds/rss/ - Cointelegraph:
https://cointelegraph.com/rss - Cointelegraph Bitcoin:
https://cointelegraph.com/rss/tag/bitcoin - Cointelegraph Ethereum:
https://cointelegraph.com/rss/tag/ethereum
Setup Requirements
Prerequisites
- Python 3.8+ with asyncio support
- Windows, macOS, or Linux
- 8GB+ RAM recommended (for model loading)
- CUDA-compatible GPU recommended but not required
Environment Setup
# Create virtual environment
python -m venv venv
source venv/bin/activate # or activate on Windows
Install dependencies
pip install -r requirements.txt
Windows-specific: Set console to UTF-8 mode
chcp 65001 # If running in cmd.exe
Configuration
# Set up your .env file with required API keys:
BINANCEAPIKEY=yourkeyhere # Obtain from Binance Testnet
BINANCEAPISECRET=yoursecrethere # Obtain from Binance Testnet
NEWSAPIKEY=yourkeyhere # Optional fallback for news feeds
HUGGINGFACETOKEN=yourtoken_here # Optional for model access
Optional paid/provider-specific fallback:
CRYPTOPANICAPIKEY=
CRYPTOPANICAPIPLAN=developer
Running the System
# Basic run
python main.py
Run with minimal console output
python main.py -q
Run with verbose debugging output
python main.py -v
Current Challenges
Known Issues
- API Connectivity
- Sentiment Analysis
analyze() and analyze_text()
- Unicode encoding errors in Windows environments
- Inconsistent LLM response formats causing parsing errors
- Trading Execution
execute_trade() method
- Inconsistent signal formats between processing methods
Immediate Improvements Needed
- API Connectivity
- Method Compatibility
- Position Sizing
- Error Handling
Known Issues
- API Connectivity
- Sentiment Analysis
analyze() and analyze_text()
- Unicode encoding errors in Windows environments
- Inconsistent response formats from the LLM causing "Unknown format code 'f'" errors
- Type conversion issues when formatting sentiment scores
- Trading Execution
- System Stability
Immediate Fixes Needed
- Binance Client Initialization
base_url parameter in AsyncClient.create()
- Use only supported parameters: apikey, apisecret, and testnet
- Trading Execution
- Position Sizing
- Sentiment Analysis
Development Roadmap
Current development priorities:
- [x] Fix AsyncIO event loop issues
- [x] Improve error handling in API calls
- [ ] Enhance sentiment analysis prompt engineering
- [ ] Fix minimum order size calculation
- [ ] Fix Binance API client initialization parameters
- [ ] Resolve execute_trade() parameter mismatch
- [ ] Implement basic backtesting framework
- Advanced position sizing with Kelly Criterion
- Multi-asset portfolio optimization
- Value-at-Risk (VaR) calculations
- Sentiment-adjusted position sizing
- Correlation-aware risk metrics
Warning
โ ๏ธ IMPORTANT: This system is in early development stage and not production-ready:
- Use testnet only - not suitable for real trading
- Expect instability and potential errors
- Many features described are planned but not yet implemented
- System requires significant technical knowledge to run properly
License
MIT License - See LICENSE for details.
Acknowledgements
This project builds on the foundation of several important open-source projects and research:
- FinGPT Research: Core ideas on financial sentiment analysis and market prediction using large language models were inspired by research from the FinGPT paper.
- llama.cpp: Our inferencing pipeline leverages the llama.cpp framework for running language models with minimal computational resources.
- Binance API: Trading functionality is built on the Binance exchange API and Python client libraries.
- Python AsyncIO: The asynchronous architecture is powered by Python's AsyncIO framework.
Contributing
Contributions are welcome! Please fork the repository and submit a pull request with your changes. Ensure to follow the code style and include tests for new features. See CONTRIBUTING.md for more details.