Building an AI Portfolio Analyzer with Python, FastAPI, React & Machine Learning
Over the last few months, I wanted to build a project that combined everything I enjoy working onβdata engineering, machine learning, backend APIs, and modern frontend development.
The result is AI Portfolio Analyzer, a web application that helps investors analyze portfolios, forecast prices using machine learning, understand portfolio risk, and estimate capital gains taxes.
π Live Demo: https://portfolio-analyzer-sigma-amber.vercel.app/
π» GitHub: https://github.com/abhinavsharma11pix/portfolio-analyzer
Why I Built It
Most portfolio tracking applications focus on showing holdings and returns. I wanted to build something that could answer questions like:
- How risky is my portfolio?
- What does the historical performance tell me?
- What could prices look like over the next month?
- How much tax would I owe if I sold today?
- Can AI help summarize portfolio performance?
This project became an opportunity to combine quantitative finance, machine learning, and full-stack engineering into a single application.
Features
Live Market Data
The application supports both NSE and NYSE stocks with real-time market updates through WebSockets.
This enables live portfolio valuation without constantly refreshing the page.
Machine Learning Forecasting
One of the most interesting parts of the project was building the forecasting pipeline.
Instead of relying on a single model, I combined multiple approaches:
- Exponential Smoothing (ETS)
- Random Forest Regressor
- LightGBM
Each model captures different characteristics of market behavior.
The application generates a 30-day forecast and presents it alongside historical prices for comparison.
AI Portfolio Advisor
The application uses Llama 3 to generate portfolio insights.
Rather than simply explaining metrics, it analyzes portfolio composition and produces natural language summaries that are easier for investors to understand.
Examples include:
- concentration risk
- diversification opportunities
- sector exposure
- portfolio observations
Portfolio Risk Analytics
The platform calculates several commonly used portfolio metrics including:
- Sharpe Ratio
- Value at Risk (VaR)
- Sortino Ratio
- Beta
- Maximum Drawdown
These metrics provide additional context beyond simple profit and loss.
Capital Gains Tax Engine
Another feature I wanted to include was tax estimation.
The application supports:
- FIFO lot matching
- Short-term and long-term capital gains
- Tax estimation
- Harvesting insights
This allows investors to understand the tax implications of selling holdings.
Tech Stack
Backend
- Python
- FastAPI
- SQLite
- WebSockets
Machine Learning
- Scikit-Learn
- LightGBM
- Pandas
- NumPy
Frontend
- React
- TypeScript
- Vite
Deployment
- Vercel
- Render
Challenges
Every project comes with tradeoffs.
Some of the interesting challenges included:
- Designing APIs that could efficiently serve portfolio data.
- Keeping market data responsive.
- Combining statistical and machine learning models into a single forecasting workflow.
- Balancing prediction quality with inference time.
- Building an intuitive dashboard that exposes complex financial metrics without overwhelming users.
Each iteration improved both the user experience and the architecture.
Lessons Learned
Building this project strengthened my understanding of:
- designing production-ready APIs
- machine learning workflows
- frontend and backend integration
- financial analytics
- performance optimization
- deploying full-stack applications
More importantly, it reminded me how much you learn by building end-to-end products rather than isolated models.
What's Next?
Some ideas I'm currently exploring include:
- Portfolio optimization algorithms
- Additional forecasting models
- User authentication and cloud database support
- Backtesting strategies
- More interactive visualizations
If you have suggestions or feedback, I'd love to hear them.
β GitHub:
https://github.com/abhinavsharma11pix/portfolio-analyzer
π Live Demo:
https://portfolio-analyzer-sigma-amber.vercel.app/
Top comments (0)