This document outlines how Allora's sentiment analysis and predictions have been integrated into the Rebalancr system, based on extensive research in algorithmic trading and market analysis.
The integration follows a multi-layered approach:
┌───────────────┐ ┌────────────────┐ ┌──────────────────┐
│ External APIs │───▶│ Allora Client │───▶│ │
└───────────────┘ └────────────────┘ │ │
│ │
┌───────────────┐ ┌────────────────┐ │ IntelligenceEngine │
│ Market Data │───▶│ Risk Monitor │───▶│ │
└───────────────┘ └────────────────┘ └──────────────────┘
│
┌───────────────┐ ┌────────────────┐ │
│ Yield Sources │───▶│ Yield Optimizer│─────────────┘
└───────────────┘ └────────────────┘ │
▼
┌──────────────┐ ┌──────────────────┐
│TradeReviewer │◀─┤ RebalancerAction │
└──────────────┘ │ Provider │
└──────────────────┘
- Provides sentiment analysis through Allora's topic-specific predictions
- Implements fear/greed classification
- Detects market manipulation patterns
- Includes caching to minimize API calls
- Combines sentiment signals with statistical analysis
- Uses dynamic weight adjustment for signal processing
- Performs cost-benefit analysis for rebalancing decisions
- Manages performance tracking
- Validates rebalancing decisions
- Acts as a "second opinion" similar to other successful trading systems
- Supports both AI and rule-based validation
- Implements the AgentKit pattern for agent actions
- Provides portfolio analysis, execution, simulation, and reporting
- Serves as the execution layer for the system
- Tracks strategy effectiveness
- Analyzes signals from both sentiment and statistical components
- Provides recommendations for strategy improvements
Research in market analysis suggests separating responsibilities:
-
AI/Sentiment Analysis (Allora)
- Focused on market sentiment analysis
- Provides fear/greed classification
- Detects potential market manipulation
-
Statistical Analysis
- Handles all numerical calculations
- Manages volatility, trend, and price metrics
- Calculates cost-benefit ratios
-
Validation Layer
- Provides third-party validation of decisions
- Can reject trades based on risk metrics
- Adds extra protection against poor decisions
Each asset has its own profile with:
- Customized sentiment/statistical weights
- Relevant Allora topic IDs
- Manipulation detection thresholds
Based on empirical research and backtesting:
- Minimum 7-day rebalancing interval to optimize fees
- Cost-benefit analysis for rebalancing decisions
- 2x minimum benefit threshold for execution
Configuration parameters are stored in config.py and include:
- Allora API settings
- Strategy parameters
- Network configurations
- Trade reviewer settings
The RebalancerActionProvider implements these actions:
analyze-portfolio: Get rebalance recommendationsexecute-rebalance: Execute a rebalancesimulate-rebalance: Simulate a rebalance with custom allocationsget-performance: Get performance metrics and recommendations
To set up the system:
- Install dependencies using Poetry
# Install dependencies
poetry install
# Activate virtual environment
poetry shell- Set environment variables
export ALLORA_API_KEY="your_api_key"- Initialize the components
from rebalancr.intelligence.allora.client import AlloraClient
from rebalancr.intelligence.intelligence_engine import IntelligenceEngine
from rebalancr.strategy.engine import StrategyEngine
from rebalancr.intelligence.reviewer import TradeReviewer
from rebalancr.performance.analyzer import PerformanceAnalyzer
from rebalancr.execution.providers.rebalancer import rebalancer_action_provider
from rebalancr.config import get_config
# Initialize components with Poetry-managed dependencies
config = get_config()
allora_client = AlloraClient(api_key=config["ALLORA_API_KEY"])
intelligence_engine = IntelligenceEngine(allora_client=allora_client)
strategy_engine = StrategyEngine()
trade_reviewer = TradeReviewer(config=config["REVIEWER"])
performance_analyzer = PerformanceAnalyzer()
# Create action provider
rebalancer_provider = rebalancer_action_provider(
wallet_provider=wallet_provider,
intelligence_engine=intelligence_engine,
strategy_engine=strategy_engine,
trade_reviewer=trade_reviewer,
performance_analyzer=performance_analyzer,
config=config["STRATEGY"]
)Research shows that equal initial weights (25%) for different signals provide a balanced starting point. The system adapts these weights based on performance data.
The multi-layered approach provides additional safety, following established patterns in automated trading systems that use multiple validation layers.
Market research indicates that different assets exhibit unique characteristics requiring customized analysis parameters and risk thresholds.
-
Forward Testing Framework
- Implement simulated trading without execution
- Compare predictions to actual outcomes
- Refine weights based on performance
-
Enhanced Manipulation Detection
- Improve detection algorithms
- Implement cross-reference validation
-
Dynamic Weight Adjustment
- Automatically tune weights based on performance
- Implement seasonal adjustments