A portfolio optimization copilot for OpenBB that uses PyPortfolioOpt to generate efficient frontier allocations.
- OpenBB Integration:
- Plugs into OpenBB Workspace's copilot and widget interfaces
- Fetches price data from FMP via OpenBB Platform's python library
- Real-time feedback through server-sent events
- Interactive portfolio visualization widgets
- Portfolio Optimization Models:
- Maximum Sharpe Ratio optimization
- Minimum Volatility optimization
- Efficient Risk (target volatility)
- Efficient Return (target return)
-
Python 3.10 to 3.12
-
FMP API access (via OpenBB Platform)
-
OpenAI API access
-
Dependencies listed in
pyproject.toml
-
Tech Stack:
- FastAPI with Starlette SSE for real-time updates
- OpenBB Platform Python library for data access
- PyPortfolioOpt for optimization algorithms
- Pydantic for data validation
- Magentic for LLM interactions
-
Clone the repository:
git clone https://github.com/yourusername/allocator-bot.git cd allocator-bot
-
Install dependencies using Poetry:
poetry install
- Copy
.env.example
to.env
and fill in the values.
Start the server on localhost:
python main.py
-
Add as a Copilot:
- Click on the OpenBB Copilot dropdown
- Click "Add Copilot"
- Enter the server URL (e.g.,
http://localhost:4322
for local deployment) - Add authorization header with the API key from
API_KEYS_FILE_PATH
- Header name:
Authorization
- Header value:
Bearer <API_KEY>
- Header name:
- Click "Create"
-
Add as a Widget Source:
- Click "Add Data" on your dashboard
- Go to "Custom Backends"
- Select "Allocator Bot Backend"
- Enter the same URL and API key used for the copilot
- Click "Add"
- The copilot accepts natural language requests for portfolio optimization
- You can specify:
- List of tickers
- Total investment amount
- Risk-free rate
- Target volatility
- Holding period
- The copilot will provide:
- Optimized allocations with different risk models
- Interactive tables and visualizations
- Real-time feedback and error handling
- Allocation IDs for widget integration
- Load allocations using their IDs
- Filter by specific risk models
- Visualize allocations using various chart types (e.g., donut charts)
- Compare different optimization strategies
- Fork the repository
- Create a new branch for your feature or bugfix
- Submit a pull request with a description of your changes
This project is licensed under MIT. PyPortfolioOpt is licensed under MIT. OpenBB is licensed under AGPL.