A comprehensive algorithmic trading platform that combines advanced Natural Language Processing (FinGPT) with quantitative trading strategies to exploit market inefficiencies in cryptocurrency markets. The system implements a multi-layered architecture:
-
Market Inefficiency Detection Layer
- Sentiment-price divergence analysis
- Order flow imbalance detection
- Microstructure pattern recognition
- Cross-exchange arbitrage identification
-
Smart Order Routing Engine
- Multi-exchange order execution
- Liquidity aggregation
- Transaction cost optimization
- Dynamic order splitting
-
Robo Advisory Module
- Portfolio optimization with ESG constraints
- Tax-loss harvesting automation
- Dynamic rebalancing
- Risk-adjusted position sizing
-
Risk Management System
- Real-time risk monitoring
- Portfolio-level risk controls
- Dynamic stop-loss management
- Exposure limits enforcement
The platform leverages Large Language Models for real-time market sentiment analysis while employing statistical arbitrage and market microstructure strategies for alpha generation. A sophisticated robo-advisory layer provides automated portfolio management with ESG considerations and tax optimization.
Market inefficiencies represent deviations from the Efficient Market Hypothesis (EMH) where prices don't fully reflect all available information. In crypto markets, these inefficiencies are particularly pronounced due to:
Crypto markets often exhibit significant information gaps due to:
- Fragmented exchange landscapes
- Varying regulatory environments
- Complex technical foundations
- Rapid technological evolution
Common in crypto due to:
-
Order Book Fragmentation
- Multiple exchanges
- Varying liquidity pools
- Cross-chain complexities
-
Price Formation Dynamics
$$P(t) = P(t-1) + λ(D(t) + η(t)) where: - λ: Market impact parameter - D(t): Order flow imbalance - η(t): Noise trader impact$$ -
Arbitrage Opportunities
- Cross-exchange pricing discrepancies
- Cross-chain value transfers
- Market maker inventory imbalances
-
Alpha Generation
- Short-term price prediction
- Statistical arbitrage opportunities
- Mean reversion strategies
-
Risk Management
- Liquidity risk assessment
- Market impact estimation
- Portfolio rebalancing costs
-
Market Making
- Optimal spread determination
- Inventory management
- Cross-exchange arbitrage
Exploits sentiment-price divergences in crypto markets:
Implementation Details:
- Uses FinGPT for real-time sentiment analysis
- Monitors news, social media, and on-chain metrics
- Adapts β based on market volatility regime
- Dynamic θ threshold using market microstructure
Captures order flow imbalances and liquidity provision opportunities:
Key Features:
- Multi-level order book analysis
- Volume-weighted price impact estimation
- Adaptive order placement
- Cross-exchange liquidity aggregation
Exploits temporary price dislocations:
Implementation:
- Pairs trading across exchanges
- Cointegration-based pair selection
- Dynamic spread modeling
- Transaction cost optimization
- Signal Generation
combined_signal = w_1 * sentiment_signal + w_2 * micro_signal + w_3 * stat_arb_signal
where w_1 + w_2 + w_3 = 1
- Position Sizing
- Risk Management
- Per-trade stop loss
- Portfolio-level VaR limits
- Drawdown controls
- Exposure limits per strategy
- Execution Optimization
- Smart order routing
- Transaction cost analysis
- Liquidity-aware execution
- Cross-exchange netting
We focus on four key types of market inefficiencies:
When market sentiment and price movements show significant disparity:
Detects unusual buying/selling pressure:
Based on mean-reverting behavior in market microstructure:
Identifies price discrepancies across exchanges:
Our robo advisor implements modern portfolio theory with ESG and tax considerations:
graph TB
subgraph Data Layer
MD[Market Data Stream] --> PP[Price Processor]
NF[News Feed] --> NP[News Processor]
OB[Order Book] --> OP[Order Flow Processor]
XE[Cross-Exchange Data] --> XA[Arbitrage Detector]
end
subgraph Analysis Layer
PP --> TA[Technical Analysis]
NP --> SA[Sentiment Analysis]
OP --> MA[Microstructure Analysis]
XA --> CA[Cross-Exchange Analysis]
subgraph LLM Module
SA --> FG[FinGPT]
FG --> SS[Sentiment Signals]
end
subgraph Inefficiency Detection
TA --> ID[Inefficiency Detector]
MA --> ID
SS --> ID
CA --> ID
end
subgraph Robo Advisory
CP[Client Profiles] --> RA[Risk Assessment]
RA --> PA[Portfolio Analysis]
PA --> PO[Portfolio Optimization]
PA --> TH[Tax Harvesting]
PA --> ESG[ESG Optimization]
PO --> RB[Rebalancing]
TH --> RB
ESG --> RB
end
end
subgraph Execution Layer
ID --> SG[Signal Generator]
RB --> SG
SG --> PS[Position Sizing]
PS --> RM[Risk Management]
RM --> OE[Order Execution]
end
subgraph Monitoring
OE --> PT[Performance Tracker]
PT --> RA[Risk Analyzer]
RA --> AA[Alpha Attribution]
PT --> TC[Tax Calculator]
PT --> EC[ESG Compliance]
end
The foundation of our system, responsible for gathering and preprocessing all necessary data:
-
Market Data Stream [MD]
- Real-time cryptocurrency price feeds
- Order book depth data
- Trade execution data
- Volume profiles
-
News Feed [NF]
- Cryptocurrency news articles
- Social media sentiment
- On-chain metrics
- Market announcements
-
Order Book [OB]
- Level 2 market data
- Bid-ask spreads
- Liquidity depth analysis
- Order flow imbalance
-
Cross-Exchange Data [XE]
- Price disparities
- Liquidity differences
- Arbitrage opportunities
- Exchange-specific features
Processes raw data into actionable insights:
-
Technical Analysis [TA]
- Price pattern recognition
- Trend analysis
- Volume profiling
- Momentum indicators
-
Sentiment Analysis [SA]
- News sentiment scoring
- Social media sentiment
- Market sentiment indicators
- Trend sentiment correlation
-
Microstructure Analysis [MA]
- Order flow analysis
- Market impact estimation
- Liquidity analysis
- Tick data analysis
-
LLM Module
- Natural language processing
- Context-aware analysis
- Multi-source integration
- Adaptive learning
Identifies trading opportunities through:
-
Signal Generation
- Sentiment-price divergence
- Order flow imbalance
- Microstructure patterns
- Cross-exchange arbitrage
-
Opportunity Scoring
- Confidence metrics
- Execution probability
- Risk-adjusted returns
- Transaction costs
Manages portfolio optimization and client requirements:
-
Risk Assessment [RA]
- Client risk profiling
- Market risk analysis
- Portfolio risk metrics
- Drawdown management
-
Portfolio Analysis [PA]
- Asset allocation
- Portfolio optimization
- Performance attribution
- Rebalancing needs
-
Tax & ESG
- Tax-loss harvesting
- ESG scoring
- Impact investing
- Compliance monitoring
Handles trade execution and position management:
-
Position Sizing [PS]
- Kelly criterion optimization
- Risk-based sizing
- Portfolio constraints
- Liquidity considerations
-
Risk Management [RM]
- Position limits
- Stop-loss management
- Exposure monitoring
- VaR calculations
-
Order Execution [OE]
- Smart order routing
- Transaction cost analysis
- Execution algorithms
- Post-trade analysis
Tracks system performance and risk:
-
Performance Tracking [PT]
- Return metrics
- Risk metrics
- Attribution analysis
- Benchmark comparison
-
Risk Analysis [RA]
- Real-time risk monitoring
- Stress testing
- Scenario analysis
- Limit monitoring
-
Compliance [TC/EC]
- Tax efficiency monitoring
- ESG compliance
- Regulatory requirements
- Trading restrictions
- Raw data enters through the Data Layer
- Analysis Layer processes and enriches data
- Inefficiency Detection identifies opportunities
- Robo Advisory manages portfolio requirements
- Execution Layer implements trading decisions
- Monitoring Layer tracks performance and risk
fingpt_trader/
├── main.py # Main trading system
├── models/
│ ├── llm/ # LLM-related models
│ │ ├── base.py # Base LLM interface
│ │ ├── fingpt.py # FinGPT implementation
│ │ └── utils/
│ │ ├── tokenizer.py
│ │ └── inference.py
│ ├── market/ # Market analysis
│ │ ├── inefficiency.py
│ │ └── patterns.py
│ ├── portfolio/ # Portfolio management
│ │ ├── optimization.py
│ │ ├── risk.py
│ │ └── rebalancing.py
│ └── sentiment/
│ ├── analyzer.py # Sentiment analysis
│ └── preprocessor.py
├── services/
│ ├── base_service.py # Base service interface
│ ├── data_feeds/ # Market data services
│ │ ├── market_data_service.py
│ │ └── news_service.py
│ ├── monitoring/ # System monitoring
│ │ ├── system_monitor.py
│ │ └── performance_tracker.py
│ └── trading/ # Trading services
│ ├── robo_service.py
│ └── order_manager.py
├── data/ # Data storage
│ ├── raw/ # Raw market data
│ ├── processed/ # Processed features
│ └── logs/ # System logs
├── config/ # Configuration files
│ ├── trading.yaml # Main trading config
│ ├── test_trading.yaml # Test config
│ └── logging.yaml # Logging config
├── scripts/ # Utility scripts
│ ├── backtest.py
│ ├── analyze.py
│ ├── live_trade.py
│ └── run_trader.py
├── examples/ # Example implementations
│ ├── market_data.py
│ ├── sentiment_analysis.py
│ ├── pair_trading.py
│ └── robo_advisor_demo.py
├── utils/ # Utility functions
│ ├── config.py # Configuration management
│ ├── logging.py # Logging utilities
│ └── validation.py # Data validation
└── tests/ # Test suite
├── test_system_integration.py
├── test_portfolio_optimization.py
├── test_signal_generation.py
└── test_robo_advisor.py
system = TradingSystem(config_path="config/trading.yaml")
await system.initialize()
# Register client
await system.register_client("client1", {
"risk_score": 7.0,
"investment_horizon": 10,
"constraints": {"max_stock": 0.8},
"tax_rate": 0.25,
"esg_preferences": {"min_score": 0.7}
})
# Get recommendation
portfolio = await system.get_portfolio_recommendation("client1")
# Market data analysis
market_data = await system.get_market_data()
signals = await system.detect_inefficiencies(market_data)
# Generate and execute trades
trades = system.generate_trades(signals)
await system.execute_trades(trades)
trading:
max_position_size: 0.2
risk_limit: 0.05
confidence_threshold: 0.65
robo:
rebalance_threshold: 0.05
tax_impact_factor: 0.3
base_threshold: 0.02
# Clone repository
git clone https://github.com/ashioyajotham/fingpt_trader.git
cd fingpt_trader
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
.\venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Run tests
pytest tests/
# Start trading
python scripts/run_trader.py --config config/trading.yaml
See CONTRIBUTING.md for contribution guidelines.
This project is licensed under the MIT License - see LICENSE file for details.