SmartPortfolio AI is a modular, intelligent AI agent system designed to manage and optimize investment portfolios using Model Context Protocol (MCP).
This project showcases how an AI agent can evaluate, evolve, and recommend investment strategies dynamically, based on performance and policy constraints β while separating the decision logic (MCP) from execution workflows.
To demonstrate Model Context Protocol (MCP) in action β where the AI system evolves internal capabilities (e.g., portfolio strategies) and adapts its behavior to changing conditions, user feedback, and performance results.
- Model Context Protocol (MCP): Tracks and manages evolving capabilities (investment strategies), scoring them based on past outcomes and adapting over time.
- Modular AI Agent Design: Each agent performs a dedicated role in the portfolio rebalancing process.
- Separation of Concerns: MCP recommends the best strategy, but a lightweight controller orchestrates the execution.
User (Telegram)
β
Conversational Agent
β
ββββββββββββββββββ
β β
Calls Execution Controller βββββββββββββββ
(a lightweight orchestrator) |
β |
MCP Engine β Capability Manager Layer |
β |
Sends recommendation: |
- Use "Risk Parity" |
- Deactivate "Equal Weight" β
β β
Execution Controller calls agents as needed: β
- Portfolio Analysis β
- Bank Policy β
- Rebalance Strategy β
- Trade Execution β
βββββββββββββββββββββββββββββββββββββββββββββ
Agent | Role |
---|---|
Conversational Interface Agent | Handles Telegram input/output and user interactions |
MCP Engine | Recommends strategies based on historical performance & context |
Portfolio Analysis Agent | Assesses portfolio structure and current asset distribution |
Bank Policy Agent | Applies internal or regulatory constraints on strategies |
Rebalance Strategy Agent | Executes chosen portfolio rebalancing logic |
Trade Execution Agent | Simulates or dispatches trade instructions |
SmartPortfolioMCP/
βββ agents/
β βββ analysis_agent.py
β βββ rebalance_agent.py
β βββ bank_policy_agent.py
β βββ trade_execution_agent.py
β βββ MCP_engine.py # The brain β recommends & evolves strategy capabilities
β
βββ MCP/
β βββ capabilities.json # Tracks all strategies, scores, and metadata
β βββ performance_log.json # Logs real-world or simulated performance results
β
βββ interface/
β βββ telegram_bot.py # Telegram Conversational Agent
β
βββ controller/
β βββ execution_controller.py # Orchestrates agents based on MCP output
β
βββ data/
β βββ sample_portfolio.json
β
βββ run.py # Main entry point
βββ requirements.txt
βββ README.md
- User interacts via Telegram.
- Conversational Agent parses the query and forwards to the Execution Controller.
- The Controller calls the MCP Engine to get a recommended strategy.
- The MCP Engine evaluates current capability states (via
capabilities.json
). - Based on recommendation, the Controller:
- Calls Portfolio Analysis
- Applies Bank Policies
- Executes Strategy
- Triggers Trade Execution
- Results are fed back to the MCP Engine for scoring and capability adjustment.
equal_weight
risk_parity
volatility_weighted
dividend_focus
Each strategy has:
{
"confidence_score": 0.74,
"times_used": 3,
"last_performance": 0.021,
"active": true
}
git clone https://github.com/yourusername/SmartPortfolioMCP.git
cd SmartPortfolioMCP
pip install -r requirements.txt
python run.py
To start the Telegram bot, configure your bot token in interface/telegram_bot.py
and run it.
- Real-time price feed via Alpha Vantage or Yahoo Finance
- Backtesting engine
- Real trade execution via Alpaca API
- Visual dashboard (Streamlit/Gradio)
- Capability graph visualization
This project keeps the MCP Engine pure β responsible only for capability evaluation, evolution, and strategy recommendation, not system control.
The execution controller handles orchestration, maintaining modularity and showcasing how agent-based AI systems can be both adaptive and interpretable.
A sophisticated portfolio management system with AI-powered analysis and Telegram bot interface.
-
Portfolio Management
- Track holdings and positions
- Calculate portfolio metrics
- Monitor performance and risk metrics
- Rebalancing suggestions
-
Market Analysis
- Real-time market data integration
- Sentiment analysis
- Technical indicators
- News integration
-
Telegram Bot Interface
- View portfolio status
- Get real-time alerts
- Execute trades
- Receive recommendations
MCP-project/
βββ agents/ # AI agents for different analysis tasks
βββ MCP/ # Core MCP functionality
β βββ alerts.py # Portfolio alerts system
β βββ conditions.py # Alert conditions
β βββ MCP_engine.py # Main engine
β βββ holdings.py # Portfolio holdings
β βββ market_data.py # Market data integration
β βββ portfolio.py # Portfolio management
βββ interface/ # User interfaces
β βββ telegram_bot.py # Telegram bot implementation
βββ tests/ # Test suite
β βββ agents/ # Agent tests
β βββ MCP/ # Core functionality tests
β βββ interface/ # Interface tests
βββ .env.example # Example environment variables
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
- Clone the repository:
git clone <repository-url>
cd MCP-project
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Copy
.env.example
to.env
and configure your environment variables:
cp .env.example .env
- Configure your environment variables in
.env
:
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
ALPHA_VANTAGE_API_KEY=your_alpha_vantage_key
Run all tests:
python -m pytest
Run specific test files:
python -m pytest tests/interface/test_telegram_bot.py
- Start the Telegram bot:
python -m interface.telegram_bot
- Available commands in Telegram:
/start
- Start the bot/help
- Show help message/portfolio
- View current portfolio/risk
- View risk metrics/performance
- View performance metrics/recommendations
- Get recommendations/rebalance
- Rebalance portfolio/alerts
- Manage alerts/strategies
- View available strategies
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Financial data providers
- Open-source libraries
- Contributors and maintainers