Investment Portfolio Tracker

Flagship Project

The Problem

An investor may use several Demat accounts with different brokers. Each account has its own BUY and SELL transactions, holdings, and profit-and-loss information. Looking at each account separately makes it difficult to understand the complete portfolio.

It is also not practical to read every transaction and calculate the important points manually. Financial documents create another difficulty: company statements and investment commentaries can be long, and they may contain financial terms that are difficult to understand quickly.

The Idea

I built this project to bring the investor's portfolio information and supporting documents into one place. The user can add any number of Demat accounts and record the BUY and SELL transactions made through those accounts.

The application then calculates the combined view of the portfolio, including holdings, account-wise summaries, and an overall portfolio summary. The user does not need to check every account separately to understand the current position.

Asking Questions about the Portfolio

The application includes an AI chat assistant that can use the portfolio data through backend tools. Instead of manually searching through transactions and summaries, the user can ask questions in normal language.

For example, the user can ask:

  • What is my current portfolio summary?
  • How many stocks am I holding now?
  • How has a particular stock performed?
  • What is the holding weight of a stock in my portfolio?
  • What are my holdings across all of my Demat accounts?

The assistant uses the portfolio tools and explains the results in simple words. The goal is to make the information easier to understand without requiring the user to inspect every transaction manually.

Understanding Uploaded Documents

The user can also upload documents such as company financial statements and investment commentaries. The application indexes the uploaded documents so the assistant can retrieve relevant information when answering questions.

This allows the user to ask for a high-level explanation instead of reading a long document from beginning to end. The assistant can answer questions about the uploaded material and provide source citations so the user can see where the answer came from.

The assistant can also help explain information that contains complex financial language or many numbers in a simpler way. It is designed to make the document easier to understand, not to replace the original document.

Comparing Information across Documents

Documents can be uploaded into a chat and considered together. For example, a user could upload documents about three companies they hold and ask what common risks are mentioned across them.

The assistant may identify repeated topics such as interest rates, inflation, or future RBI and Federal Reserve commentary when those topics are supported by the uploaded documents. The user can then follow those specific risks more closely because they may affect several holdings in the portfolio.

This connects two types of information: the user's portfolio data and the information in the user's own documents. The answers remain grounded in the selected chat and its uploaded documents.

How I Built the Backend

The application is built with FastAPI and uses SQLAlchemy with PostgreSQL for users, Demat accounts, transactions, chats, and documents. I separated the backend into Routes, Services, and Repository layers so that request handling, application rules, and database access remain separate.

The portfolio services calculate the portfolio results, while the AI tools call those services instead of directly accessing the database. This lets the normal application and the AI assistant use the same business rules.

AI and Document Search

LangGraph organizes the assistant's tool-calling workflow. Depending on the question, the assistant can use portfolio tools, uploaded document search, or application-help content.

The document pipeline supports PDF, DOCX, TXT, and Markdown files. It uses configurable ChromaDB or Pinecone vector stores, and the language model and embedding providers can be selected through configuration. Supported provider options include Gemini, OpenAI-compatible services, and local development providers.

Document retrieval is scoped to the authenticated user and active chat. This prevents documents from one user's account or one chat from being used as evidence for another user's question.

Keeping the Assistant Secure

Security was an important part of this project. The assistant does not receive internal user_id or chat_id values from the model. The server supplies trusted user and chat context when the tools run.

I also added MCP support through a local STDIO transport and an authenticated Streamable HTTP transport. Remote MCP clients use revocable personal access tokens, and the tokens are stored as Argon2 hashes.

MCP clients use public conversation references when selecting a chat. The backend resolves those references internally and checks ownership before accessing the conversation or its documents. The model never controls the internal database identifiers.

Testing

I added an automated Pytest suite covering authentication, portfolio workflows, repository contracts, document uploads, RAG, AI tools, LangGraph orchestration, and MCP security.

The tests cover both normal application behavior and the boundaries that protect user data, chat documents, and AI tool execution.

Important Limitation

The assistant is not a financial adviser and does not provide financial advice. It helps the user understand their own portfolio data and uploaded documents. Stock prices are entered manually by the user; the application does not connect to an external stock market API.

Technology Stack

Python, FastAPI, SQLAlchemy, PostgreSQL, LangChain, LangGraph, RAG, ChromaDB, Pinecone, Gemini, JWT, Argon2, Docker, MCP, and Pytest.

View GitHub Repository

View Quick Project Demonstration