GitHunt
SA

SayamAlt/Investment-Portfolio-Optimization-Workflow-using-LangGraph

Successfully developed an AI-powered Investment Portfolio Optimization Workflow using LangGraph that infers user risk profiles, selects tickers, fetches market data, and simulates & optimizes portfolios with actionable recommendations. It integrates advanced financial metrics, risk assessment, and dynamic portfolio management for decision-making.

πŸ“ˆ AI-Powered Investment Portfolio Optimization Agent

An advanced financial agent built using LangGraph, LangChain, and Streamlit that automates the entire portfolio management lifecycleβ€”from user profiling and ticker selection to risk-adjusted optimization and real-time market sentiment analysis.

πŸš€ Key Features

1. πŸ€– AI-Driven User Profiling

  • Infers your investment profile (risk appetite and horizon) from natural language descriptions.
  • Preserves explicit user constraints while adding AI-powered insights.

2. πŸ” Dynamic Ticker Selection

  • Recommends relevant stocks, ETFs, and sectors based on your preferences.
  • Uses LLM reasoning to filter tickers that align with current market trends and your risk profile.

3. πŸ“Š Advanced Portfolio Optimization

  • Max Sharpe Ratio (Tangency Portfolio): Automatically identifies the optimal risk-return trade-off.
  • Stable Dynamic Leverage: Implements a prudent Equity Multiplier (up to 2.5x) to enhance returns without degrading portfolio efficiency.
  • Monte Carlo Simulations: Runs thousands of simulations to calculate 95% Value-at-Risk (VaR) and Expected Shortfall.

4. πŸ“° Real-Time Market Intelligence

  • Sentiment Analysis: Fetches and analyzes news headlines from Finnhub & Yahoo Finance.
  • Fundamental Analysis: Pulls P/E ratios, Dividend Yields, Beta, and other key financial ratios.
  • Technical Indicators: Generates SMA, RSI, and momentum charts.

5. πŸ—οΈ Agentic Workflow (LangGraph)

  • A multi-node state machine orchestrates the process:
    • fetch_market_data ➑️ infer_user_profile ➑️ select_tickers ➑️ analyze_market ➑️ optimize_portfolio ➑️ assess_portfolio.

πŸ› οΈ Tech Stack

  • Framework: LangGraph, LangChain
  • LLM: OpenAI (GPT-4o)
  • UI: Streamlit
  • Financial APIs: Finnhub, yfinance
  • Optimization: CVXPY, NumPy, Pandas
  • Visualization: Plotly, Altair

βš™οΈ Setup & Installation

  1. Clone the repository:

    git clone <repository-url>
    cd "Investment Portfolio Optimization Agent using LangGraph"
  2. Install dependencies:

    pip install -r requirements.txt
  3. Configure Environment Variables:
    Create a .env file or set up Streamlit secrets:

    OPENAI_API_KEY=your_openai_key
    FINNHUB_API_KEY=your_finnhub_key
  4. Run the Application:

    streamlit run app.py

πŸ“ˆ Architecture

The system uses a State Graph approach where each node modifies a shared AgentState object. This ensures traceability and allows for complex conditional logic (e.g., rebalancing versus hedging based on market sentiment).

Investment Portfolio Optimization Workflow

πŸ›‘οΈ Risk Management

  • Leverage Caps: Strictly enforced limits to prevent over-exposure (Aggressive: 2.5x max).
  • Metric Sanitization: Proper handling of percentage-based metrics (Dividend Yield, Beta) to ensure realistic projections.
  • Action Recommendations: Context-aware suggestions (Hold, Rebalance, Hedge) based on portfolio-wide risk scoring.
SayamAlt/Investment-Portfolio-Optimization-Workflow-using-LangGraph | GitHunt