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.
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
- Event-Driven Architecture: Asynchronous processing of market events
- Risk Management: Basic position tracking and exposure monitoring
β
= Implemented | π§ = Partially Implemented | π
= Planned |
-
Sentiment Analysis
- β Falcon-7B financial sentiment model implementation
- β Confidence-weighted sentiment scoring
- β Adaptive correlation tracking between sentiment and price
-
Market Data Processing
- π§ Price data collection from Binance (
β οΈ API parameter issues) - β Technical indicator calculation (RSI, MAs, volume analysis)
- β Market inefficiency detection
- π§ Minimum order size handling (
β οΈ Size calculations incorrect)
- π§ Price data collection from Binance (
-
Trading Execution
- β Binance testnet integration
- π§ Order execution (
β οΈ Method parameter mismatches) - β Position tracking
- π Tax-loss harvesting
-
Risk Management
- π§ Basic position tracking
- β Simple exposure metrics
- π Value-at-Risk (VaR) calculations
- π Correlation-aware risk metrics
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
weighted_score = (confidence * 0.6) * (abs(sentiment_score) * 0.4)
# Generate signal if weighted score exceeds detection threshold
if weighted_score > detection_threshold:
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.
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(
sentiment_changes[:min_length],
price_changes[:min_length]
)[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.
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;
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
- Python 3.8+ with asyncio support
- Windows, macOS, or Linux
- 8GB+ RAM recommended (for model loading)
- CUDA-compatible GPU recommended but not required
# 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
# Set up your .env file with required API keys:
BINANCE_API_KEY=your_key_here # Obtain from Binance Testnet
BINANCE_API_SECRET=your_secret_here # Obtain from Binance Testnet
CRYPTOPANIC_API_KEY=your_key_here # Required for news feeds
HUGGINGFACE_TOKEN=your_token_here # Optional for model access
# Basic run
python main.py
# Run with minimal console output
python main.py -q
# Run with verbose debugging output
python main.py -v
-
API Connectivity
- Binance client fails with invalid
base_url
parameter - CryptoPanic API returns null values for some endpoints
- Error handling needs improvement for API failures
- Binance client fails with invalid
-
Sentiment Analysis
- Method discrepancies between
analyze()
andanalyze_text()
- Unicode encoding errors in Windows environments
- Inconsistent LLM response formats causing parsing errors
- Method discrepancies between
-
Trading Execution
- Position sizing calculations produce orders below minimum requirements
- Parameter mismatch in
execute_trade()
method - Inconsistent signal formats between processing methods
-
API Connectivity
- Remove unsupported parameters in AsyncClient.create()
- Add error handling for API timeouts and failures
-
Method Compatibility
- Fix signature mismatch in trading execution methods
- Standardize signal format between components
-
Position Sizing
- Add validation for exchange minimum order sizes
- Implement dynamic lookup of exchange requirements
-
Error Handling
- Add more robust exception handling for LLM responses
- Improve logging for system monitoring
-
API Connectivity
- Binance client initialization fails with invalid parameters (base_url not supported)
- CryptoPanic API endpoints return null values
- Error handling for API failures needs improvement
-
Sentiment Analysis
- Method implementation discrepancies between
analyze()
andanalyze_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
- Method implementation discrepancies between
-
Trading Execution
- Position sizing too small for minimum order requirements
- Parameter mismatch in RoboService.execute_trade() method
- Inconsistent signal format between different processing methods
-
System Stability
- NoneType errors when awaiting non-coroutines
- Uncaught exceptions in service initialization
- UI vs. logging conflicts
-
Binance Client Initialization
- Remove unsupported
base_url
parameter in AsyncClient.create() - Use only supported parameters: api_key, api_secret, and testnet
- Remove unsupported
-
Trading Execution
- Fix signature mismatch in RoboService.execute_trade() method
- Standardize signal format between different processing stages
-
Position Sizing
- Add validation for minimum order sizes before execution attempts
- Implement dynamic lookup of exchange minimum requirements
-
Sentiment Analysis
- Add type conversion for sentiment scores before formatting
- Add exception handling for inconsistent LLM responses
Current development priorities:
- Fix AsyncIO event loop issues
- 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
Future enhancements:
- Advanced position sizing with Kelly Criterion
- Multi-asset portfolio optimization
- Value-at-Risk (VaR) calculations
- Sentiment-adjusted position sizing
- Correlation-aware risk metrics
- 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
MIT License - See LICENSE for details.
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.
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.