How I built a local-first portfolio analysis tool using Python, interactive charts and optional AI
Managing investments is not just about knowing how much money you have invested in the stock market. It is also important to understand where your money is invested, which sectors have more exposure, how your holdings are performing and how your portfolio is changing over time.
Many investors use broker applications to check their holdings. These applications provide useful information, but sometimes you need a separate view of your investments to understand the bigger picture.
I wanted to build something that could help with this.
That is how I started working on AI Portfolio Intelligence, an open-source Python project that helps investors analyse their stock market holdings through interactive reports and charts.
GitHub project: https://github.com/malkarisreenivasulu/ai-portfolio-intelligence
Why I built this project
I have spent several years working in the stock market and fintech industry. During this time, I have worked with trading platforms, APIs, market data and investment-related technology.
One thing I have always found interesting is how we can make financial information easier to understand.
When you have multiple stocks in your portfolio, simply looking at a list of holdings does not give you the complete picture.
For example:
- How much money is invested in each stock?
- Which sector has the highest allocation?
- What is the current market value of the portfolio?
- Which stocks are contributing to unrealised profit or loss?
- How has the portfolio changed compared to the previous month?
- Are there any holdings for which cost or market price information is missing?
I wanted to bring these details into one simple report.
Instead of building another trading application, I decided to focus on portfolio analysis.
What is AI Portfolio Intelligence?
AI Portfolio Intelligence is a local-first portfolio analysis tool developed using Python.
It takes stock holdings as input and generates an interactive HTML report.
The report includes different charts and information that help users understand their investments.
Some of the main features are:
1. Stock-wise portfolio allocation
You can see how much of your portfolio is allocated to each stock through an interactive chart.
This makes it easier to identify which stocks have a higher weight in your portfolio.
2. Investment cost analysis
The application shows the investment cost distribution across different holdings.
This helps investors understand where their invested capital is distributed.
3. Sector-wise allocation
Sector allocation is another important part of portfolio analysis.
For example, an investor may have holdings in banking, IT, automobile, pharma and other sectors.
The application can display sector-wise allocation using a donut chart.
It also keeps unmapped holdings under an Unclassified category instead of guessing their sectors.
4. Unrealised profit and loss
The application calculates unrealised profit or loss for holdings where both acquisition cost and market price are available.
It also displays positive and negative values using charts.
This is useful for getting a quick view of the portfolio.
5. Portfolio snapshots
One feature I particularly wanted to include was portfolio snapshots.
Investors can save portfolio data at different points in time and compare the snapshots.
For example, you can compare your holdings from the beginning of the month with your current holdings.
This helps you understand changes in quantities and market values.
However, a change in portfolio value should not automatically be treated as investment profit. Deposits, withdrawals and price changes can all affect the value.
Why I chose a local-first approach
One of my main design decisions was to keep the application local-first.
Financial information is personal. Not everyone is comfortable uploading their holdings and investment details to an external platform.
I wanted users to have control over their own data.
Here is how it works:
- Portfolio data can be imported using a CSV file.
- Calculations happen locally using Python.
- Reports are generated as HTML files.
- Charts work without depending on external CDNs.
- There is no requirement for a hosted account or database.
- The application does not automatically upload portfolio information anywhere.
You can run the application on your own computer and open the generated report in your browser.
For me, keeping financial information under the user’s control is an important part of building financial software.
Where does AI come into the picture?
The name includes AI, but I did not want AI to control the actual portfolio calculations.
There is a good reason for this.
When dealing with financial information, calculations should be consistent and verifiable.
For example, market value, investment cost and unrealised profit or loss should come from defined mathematical calculations. They should not depend on what an AI model generates.
So I separated the two responsibilities.
Python handles the calculations. AI helps explain the results.
The application calculates portfolio information using Python Decimal arithmetic.
It can also generate an aggregate-only AI brief.
For users who want additional explanations, there is an optional integration with Ollama, which allows commentary using a locally installed AI model.
The AI commentary is kept separate from the calculated results.
This means the application can work perfectly well without installing an AI model.
I think this separation is important when building applications for financial use cases.
Jainam ProTrade integration
Another interesting part of this project is the optional Jainam ProTrade integration.
The idea is to allow users with the required broker API access to fetch their holdings and use them for portfolio analysis.
There is also an option to import an existing broker JSON export with an explicit field mapping.
The integration is designed as read-only.
It is meant for fetching CNC cash-equity holdings, not placing or modifying orders.
The project also has a CSV-first approach, so users do not need broker API access to use the main features.
The broker integration is optional and has validation limitations. Users should verify their API access and compare imported holdings with their broker account before relying on the results.
This is an independent open-source project. It is not an official Jainam product and is not affiliated with or endorsed by Jainam.
Technology used
I wanted to keep the technology stack simple and avoid unnecessary dependencies.
The main technologies used are:
- Python: Core application and portfolio calculations.
- Pydantic: Data validation and structured portfolio information.
- Plotly: Interactive portfolio charts.
- JSON: Portfolio snapshots and comparisons.
- HTML: Self-contained reports.
- Ollama: Optional local AI explanations.
One thing worth mentioning is that the project does not require Pandas or NumPy for its core calculations.
I used Python’s Decimal arithmetic for financial calculations to maintain decimal precision.
The charts use floating-point values only for visual display.
How to try the project
The project is open source and available on GitHub.
You can download it and run a fictional demonstration without providing any broker credentials or installing an AI model.
You need Python 3.11 to 3.14.
Clone the repository:
git clone --branch v0.1.0 https://github.com/malkarisreenivasulu/ai-portfolio-intelligence.git
cd ai-portfolio-intelligence
Create a virtual environment:
python3 -m venv .venv
source .venv/bin/activate
Install the package:
python -m pip install .
Run the demo:
python -m portfolio_intelligence demo
Once the command finishes, open:
demo-output/report.html
You can explore the interactive charts directly in your browser.
The demonstration uses fictional portfolio information.
For using your own holdings, you can import a CSV file and generate your own report. The GitHub repository includes examples and detailed documentation.
What is not included yet?
I also want to be clear about the current scope.
This is an initial release, and there are several areas that can be improved in future versions.
The current release focuses on INR-denominated, long-only cash equities and ETFs.
It does not currently calculate:
- Tax and capital gains.
- Realised trading profit and loss.
- Dividends and transaction charges.
- Time-weighted portfolio returns.
- Derivative contract exposure.
- Live market prices.
I would like to explore more features as the project develops, particularly around portfolio tracking, better financial reporting and additional integrations.
Open source and contributions
I have made this project available under the MIT licence.
Developers, traders and fintech enthusiasts are welcome to explore the code, report issues and suggest improvements.
I would particularly like to hear from people working on:
- Stock market data and portfolio analytics.
- Financial technology applications.
- Python-based financial tools.
- Local AI applications.
- Broker API integrations.
You can find the source code, examples, setup instructions and documentation here:
GitHub Repository:
https://github.com/malkarisreenivasulu/ai-portfolio-intelligence
Final thoughts
I built this project because I wanted a simple way to understand stock market holdings without depending on a large platform or sending financial information to external services.
I also wanted to experiment with a practical use of AI in financial applications.
My view is that AI should help people understand information better, but important financial calculations should remain transparent and verifiable.
This project is a small step in that direction.
I would be happy if developers, investors and people from the fintech community explored it and shared their feedback.
If you find it useful, please consider giving the GitHub repository a star or contributing to the project.
Developed by Sreenivasulu Malkari
Product Management | Fintech | Trading Platforms | APIs | AI Applications
GitHub: https://github.com/malkarisreenivasulu
LinkedIn: https://www.linkedin.com/in/sreenivasulu-malkari/
Website: https://malkari.in
Disclaimer: This is an independent software project for portfolio analysis and educational purposes. It is not investment advice, a trading recommendation or a guarantee of live market information.