Skip to content

finos-labs/dtcc-i-h-2025-morgan-stanley-technology

Portfolio Analyzer Agent System

Description

The Portfolio Analyzer is an AI-powered agent system designed to provide comprehensive investment portfolio analysis. It automates the process of gathering financial data, calculating risk metrics, assessing market sentiment, visualizing performance, and compiling these insights into a consolidated report. This tool aims to empower investors with actionable intelligence to make more informed decisions.

Key Features

  • Comprehensive Portfolio Metrics: Calculates overall portfolio Greeks and Stats (E.g.: Alpha, Beta, Omega) to assess portfolio composition and risks.

    • Annual return: The geometric average amount of money earned by an investment each year over a given time period.
    • Cumulative returns: The total return of the strategy over the entire period.
    • Annual volatility: A measure of the dispersion of returns (standard deviation) on an annualized basis, indicating risk.
    • Sharpe ratio: Measures risk-adjusted return, calculated as the (average return minus the risk-free rate) divided by the standard deviation of return. A higher Sharpe ratio is generally better.
    • Calmar ratio: Measures risk-adjusted return relative to the maximum drawdown. Calculated as the annualized return divided by the absolute value of the maximum drawdown.
    • Stability: The R-squared of a linear fit to the cumulative log returns. Indicates how steady the growth of the investment has been.
    • Max drawdown: The largest peak-to-trough decline during a specific period, indicating the worst possible loss from a previous high.
    • Omega ratio: A risk-return performance measure. It's calculated by dividing the sum of positive returns above a certain threshold by the sum of negative returns below that threshold.
    • Sortino ratio: Measures risk-adjusted return, similar to Sharpe ratio, but it only penalizes downside volatility (returns falling below a user-specified target or required rate of return).
    • Skew: Measures the asymmetry of the return distribution. Negative skew indicates a longer left tail (more large negative returns), positive skew indicates a longer right tail (more large positive returns).
    • Kurtosis: Measures the 'tailedness' of the return distribution, indicating the frequency of extreme outliers (fat tails). Higher kurtosis means more of the variance is due to infrequent extreme deviations.
    • Tail ratio: Ratio of the 95th percentile of returns to the absolute value of the 5th percentile of returns. A value greater than 1 suggests that large positive returns are larger than large negative returns.
    • Daily value at risk: Estimates the potential loss on a given day at a certain confidence level (e.g., 95% or 99%). It represents the worst expected loss under normal market conditions over a specific time horizon.
    • Alpha: The excess return of the strategy relative to a benchmark, after adjusting for the strategy's beta (market risk). A positive alpha suggests the strategy outperformed the benchmark on a risk-adjusted basis.
    • Beta: Measures the volatility (systematic risk) of the strategy in relation to a benchmark (e.g., the S&P 500). A beta of 1 indicates the strategy moves in line with the benchmark; >1 is more volatile, <1 is less volatile.
    • Information ratio: Measures the portfolio returns above the returns of a benchmark (usually an index) to the volatility of those returns. It's a measure of a portfolio manager's skill at generating returns in excess of a given benchmark.
    • Profit factor: The ratio of gross profits to gross losses. A value greater than 1 indicates profitability.
    • Common sense ratio: The profit factor multiplied by the tail ratio. It attempts to combine profitability with the risk of extreme losses.
    • Recovery factor: The absolute value of the net profit divided by the maximum drawdown. It measures how quickly the strategy recovers from drawdowns.
    • Ulcer index: A measure of downside risk that considers the depth and duration of drawdowns. Higher values indicate more significant and prolonged drawdowns.
    • Serenity index: A measure that combines the Calmar ratio with a factor related to the average drawdown, aiming to capture both risk-adjusted return and the 'peacefulness' of the equity curve.
  • Security Analysis:

    • Fetches up-to-date information and news for securities in the portfolio.
    • Performs sentiment analysis on recent news and web content related to each security.
  • Performance Visualization:

    • Generates charts and tables for key performance indicators, such as historical returns and drawdown charts.
    • Compares portfolio performance against specified benchmarks.
  • Automated Reporting: Consolidates all analyses, metrics, and visualizations into a structured, human-readable report (potentially HTML/PDF) with placeholders for generated images.

  • Agent-Based Architecture: Utilizes a planner agent to orchestrate tasks among various specialized tools and sub-agents for modularity and efficiency.

Architecture Overview

The Portfolio Analyzer operates using a sophisticated agent-based architecture orchestrated by a central Planner Agent. This Planner coordinates a suite of specialized components:

  1. Input Processor: Handles user-provided portfolio data (e.g., tickers, quantities).
  2. Data Collection Agents/Tools:
    • Security Search Tool: Gathers news and fundamental data for each security.
    • Sentiment Analysis Agent: Retrieves and analyzes market sentiment for securities using NLP.
    • Benchmark Data Tool: Fetches historical data for chosen financial benchmarks.
  3. Analytical Tools:
    • Greeks Calculation Tool: Computes individual and portfolio-level option Greeks.
    • Greeks Analysis Agent: Interprets the calculated Greeks to provide risk insights.
  4. Visualization Tools:
    • Chart/Table Image Tool: Generates visual representations of data (e.g., drawdown charts, performance vs. benchmark).
  5. Reporting:
    • Report Writer Agent: Compiles all gathered information, analyses, and visual placeholders into a final comprehensive report.

Agents agents_arch.png

Technology Stack (Potential)

  • Primary Language: Python
  • Agent Framework: [e.g., AutoGen]
  • NLP/Sentiment Analysis: OpenAI and Prompts)
  • Financial Data: Financial modeling APIs (e.g., pyfolio)
  • Greeks Calculation: Libraries like py_vollib or custom financial mathematics modules.
  • Charting: Matplotlib, Seaborn, Plotly
  • Report Generation: FPDF, ReportLab, WeasyPrint (for PDF from HTML)
  • Search: Google Search API or similar web scraping tools.

Team : Morgan Stanley Technology

Members

  • shamitv
  • jkarethiya
  • sankalpsuryawanshi
  • susmithakunisetty
  • shreya-v7
  • Neha-0407
  • naveen-agarwal-git
  • virajbedekar

Setup & Installation

# Clone the repository
git clone [https://github.com/](https://github.com/)[your-username]/portfolio-analyzer.git
cd portfolio-analyzer

# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`

# Install dependencies
pip install -r requirements.txt

# API Key Configuration
# Create a .env file or configure environment variables for necessary API keys
# (e.g., for financial data APIs, search APIs)
# Example .env file:
# FINANCIAL_API_KEY="YOUR_API_KEY"
# SEARCH_API_KEY="YOUR_SEARCH_API_KEY"

The following environment variables should be present in your `.env` file:

*   `AWS_ACCESS_KEY_ID`: Your AWS Access Key ID for accessing AWS services.
*   `AWS_SECRET_ACCESS_KEY`: Your AWS Secret Access Key for accessing AWS services.
*   `AWS_SESSION_TOKEN`: Your AWS Session Token (if using temporary credentials).
*   `AWS_DEFAULT_REGION`: The default AWS region to be used.
*   `AWS_REGION`: The AWS region to be used.
*   `MOCK_DATA_DIR`: The directory path for mock data used by the application.
*   `FINANCIAL_API_KEY`: Your API key for the financial data provider.
*   `SEARCH_API_KEY`: Your API key for the search provider.


# Run the below Docker Compose Commands : To Be Updated post final implementation
docker-compose build
docker-compose up

# Check the Application Status : To Be Updated post final implementation
# 1. Health Check : http://localhost:8000/ should retun "Hello from Planner Agent!" 
# 2. POST Call : curl -X POST http://localhost:8000/run -H "Content-Type: application/json" -d '{"portfolio": [{"symbol": "GOOGL", "quantity": 5}]}'

Agents :

+---------------------+     +---------------------+     +-----------------------+
|     User Input      | --> |    Planner Agent    | ==> | Security Search Tool  |
| (Portfolio details, |     |   (Orchestrator)    |     +-----------------------+
|  optional benchmark)|     +---------^-----------+                |
+---------------------+               |                            | (Security Info)
                                      |                            V
                                      |        +--------------------------------+
                                      |        |   Sentiment Analysis Agent     |
                                      |        | (Web Search + NLP for Sentiment)|
                                      |        +--------------------------------+
                                      |                            |
                                      |                            | (Sentiment Scores)
                                      |                            V
                                      |        +--------------------------------+
                                      |        |    Benchmark Data Tool         |
                                      |        +--------------------------------+
                                      |                            |
                                      |                            | (Benchmark Data)
                                      |                            V
                                      |        +--------------------------------+
                                      |        |   Greeks Calculation Tool      |
                                      |        | (Calculates Portfolio Greeks)  |
                                      |        +--------------------------------+
                                      |                            |
                                      |                            | (Calculated Greeks)
                                      |                            V
                                      |        +--------------------------------+
                                      |        |     Greeks Analysis Agent      |
                                      |        |   (Interprets Greeks)          |
                                      |        +--------------------------------+
                                      |                            |
                                      |                            | (Greeks Insights)
                                      |                            V
                                      |        +--------------------------------+
                                      |        | Chart / Table Image Tool       |
                                      |        | (Generates Visuals, e.g., PNG) |
                                      |        +--------------------------------+
                                      |                            |
                                      |                            | (Image Placeholders/Paths)
                                      +----------------------------+
                                      |
                                      V
+---------------------------------------------------------------------------------+
|                               Report Writer Agent                               |
| (Compiles all data, analyses, and image placeholders into a structured report)  |
+---------------------------------------------------------------------------------+
                                      |
                                      V
+---------------------------------------------------------------------------------+
|                                Final Report                                     |
|               (e.g., HTML/PDF with text, tables, and embedded images)           |
+---------------------------------------------------------------------------------+

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •