FinTrack is a full-stack stock trading and portfolio management dashboard built with the MERN stack. It allows users to sign up, log in, view real-time stock prices, place buy/sell trades, manage watchlists, track portfolio holdings, analyze returns, use an AI-powered finance chatbot, run stock price prediction, and perform quantitative portfolio optimization.
The platform has been extended with a Python-based Quant Portfolio Optimizer Microservice that applies financial engineering concepts such as Markowitz mean-variance optimization, Sharpe ratio maximization, current-vs-optimal portfolio comparison, rebalancing suggestions, and Monte Carlo simulations.
- User registration and login
- JWT-based authentication
- Secure password hashing using bcrypt
- HTTP-only cookie/session support
- Protected dashboard routes
- User-specific portfolio and trading data
- Real-time market overview
- Stock price display using AlphaVantage API
- Watchlist support
- Buy/Sell trading engine
- Transaction history
- Current holdings tracking
- Portfolio value calculation
- Profit and loss tracking
- Returns analytics
- Market analytics dashboard
FinTrack tracks the user's active stock holdings and portfolio state.
The portfolio system supports:
- User-specific holdings
- Quantity-based stock positions
- Current price tracking
- Portfolio value calculation
- Investment tracking
- Returns calculation
- Profit/loss analysis
- Transaction history
The Quant Optimizer is the final financial engineering layer added to FinTrack.
It compares the user's current portfolio with a mathematically optimized portfolio using Markowitz portfolio theory.
The optimizer provides:
- Current portfolio weight calculation
- Markowitz mean-variance optimization
- Maximum Sharpe ratio portfolio
- Current vs optimal allocation comparison
- Portfolio expected return
- Portfolio volatility
- Sharpe ratio
- Rebalancing suggestions
- Monte Carlo simulation for current portfolio
- Monte Carlo simulation for optimized portfolio
- Graph-based risk visualization
FinTrack runs Monte Carlo simulations on both:
- The user's current portfolio
- The optimized portfolio
The simulation estimates future portfolio value paths and displays:
- Median portfolio path
- 5th percentile downside scenario
- 95th percentile upside scenario
- Expected final portfolio value
- Probability of loss
- Downside risk estimate
This helps users compare the risk-return behavior of their current allocation against the optimized allocation.
FinTrack integrates a self-built ML stock prediction model.
Deployed model test endpoint:
https://stock-analyser-ggjy.onrender.com/predict/MSFTReplace MSFT with any stock ticker.
Example:
https://stock-analyser-ggjy.onrender.com/predict/AAPL
https://stock-analyser-ggjy.onrender.com/predict/NVDAThe prediction module allows users to estimate the future movement or expected value of a listed stock using the deployed model API.
FinTrack includes an AI-powered finance assistant using OpenAI's API.
The chatbot can help users with:
- Financial concepts
- Stock market questions
- Portfolio-related queries
- Trading explanations
- Investment terminology
- General finance guidance
The dashboard includes watchlist and notification support.
Current notification endpoint:
GET /api/notifications/unread-countAt the current stage, the unread notification route returns:
{
"count": 0
}This prevents dashboard fetch errors and keeps the UI ready for a future notification system.
| Layer | Technology |
|---|---|
| Frontend | React, Vite, Tailwind CSS, Bootstrap |
| Backend | Node.js, Express.js |
| Database | MongoDB, Mongoose |
| Authentication | JWT, bcrypt, cookies |
| Market Data API | AlphaVantage API |
| AI Assistant | OpenAI API |
| ML Prediction | Deployed FastAPI model on Render |
| Quant Service | Python, FastAPI, NumPy, Pandas, SciPy |
| Charts | Recharts |
| Icons | Lucide React |
Fin-track/
├── client/
│ ├── src/
│ │ ├── components/
│ │ ├── layouts/
│ │ ├── pages/
│ │ │ ├── Dashboard.jsx
│ │ │ ├── QuantOptimizer.jsx
│ │ │ ├── BuySell.jsx
│ │ │ ├── Invested.jsx
│ │ │ ├── Returns.jsx
│ │ │ ├── ProfitLoss.jsx
│ │ │ ├── MarketAnalytics.jsx
│ │ │ ├── TransactionHistory.jsx
│ │ │ ├── Watchlist.jsx
│ │ │ ├── MailNotifications.jsx
│ │ │ ├── Signin.jsx
│ │ │ └── Signup.jsx
│ │ └── App.jsx
│ ├── package.json
│ └── vite.config.js
│
├── server/
│ ├── routes/
│ │ ├── authRoutes.js
│ │ ├── portfolio.js
│ │ ├── market.js
│ │ ├── trades.js
│ │ ├── userRoutes.js
│ │ ├── watchlist.js
│ │ ├── notificationRoutes.js
│ │ └── quantRoutes.js
│ ├── utils/
│ │ ├── calculateCurrentWeights.js
│ │ └── fetchHistoricalPrices.js
│ ├── index.js
│ └── package.json
│
├── quant_service/
│ ├── main.py
│ ├── optimizer.py
│ ├── run.py
│ └── requirements.txt
│
├── .gitignore
└── README.mdCreate a .env file inside the server/ folder.
PORT=3002
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
QUANT_SERVICE_URL=http://localhost:8000
ALPHA_VANTAGE_API_KEY=your_alphavantage_api_keyImportant: never commit .env files to GitHub.
Create a .env file inside the client/ folder.
VITE_BACKEND_URL=http://localhost:3002
VITE_ALPHA_VANTAGE_KEY=your_alphavantage_api_key
VITE_PREDICTION_API_URL=https://stock-analyser-ggjy.onrender.comgit clone https://github.com/vtyagi26/FinTrack.git
cd FinTrack/Fin-trackcd server
npm install
npm run devThe backend runs on:
http://localhost:3002Health check:
http://localhost:3002/Expected response:
API running...cd client
npm install
npm run devThe frontend runs on:
http://localhost:5173The quant optimizer runs as a separate Python FastAPI microservice.
cd quant_service
python -m venv venvActivate virtual environment.
On Windows:
venv\Scripts\activateOn Mac/Linux:
source venv/bin/activateInstall dependencies:
pip install -r requirements.txtRun the service:
uvicorn main:app --reload --host 127.0.0.1 --port 8000The quant service runs on:
http://localhost:8000Swagger docs:
http://localhost:8000/docsYou need to run three servers in separate terminals.
cd quant_service
venv\Scripts\activate
uvicorn main:app --reload --host 127.0.0.1 --port 8000cd server
npm run devcd client
npm run devThen open:
http://localhost:5173| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/signup |
Register new user |
| POST | /api/auth/login |
Login user |
| POST | /api/auth/logout |
Logout user |
| GET | /api/auth/verify |
Verify logged-in user |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/portfolio |
Get portfolio data |
| GET | /api/portfolio/holdings |
Get user holdings |
| GET | /api/portfolio/positions |
Get user positions |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/trades |
Place buy/sell trade |
| GET | /api/trades |
Fetch trade history |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/market |
Fetch market data |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/watchlist |
Get watchlist |
| POST | /api/watchlist |
Add stock to watchlist |
| DELETE | /api/watchlist/:id |
Remove stock from watchlist |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/notifications/unread-count |
Get unread notification count |
| Method | Endpoint | Description |
|---|---|---|
| POST | /quant/optimize |
Run portfolio optimization and Monte Carlo simulation |
Example request:
{
"holdings": [
{
"ticker": "AAPL",
"quantity": 10,
"currentPrice": 180
},
{
"ticker": "MSFT",
"quantity": 5,
"currentPrice": 420
},
{
"ticker": "NVDA",
"quantity": 2,
"currentPrice": 900
}
],
"riskFreeRate": 0.06,
"horizonDays": 252,
"simulations": 1000
}Example response:
{
"currentPortfolio": {
"weights": {
"AAPL": 0.3158,
"MSFT": 0.3684,
"NVDA": 0.3158
},
"expectedReturn": 0.12,
"volatility": 0.2,
"sharpeRatio": 0.3,
"finalExpectedValue": 112000
},
"optimalPortfolio": {
"weights": {
"AAPL": 0.25,
"MSFT": 0.35,
"NVDA": 0.4
},
"expectedReturn": 0.16,
"volatility": 0.18,
"sharpeRatio": 0.55,
"finalExpectedValue": 116000
},
"rebalance": [
{
"ticker": "AAPL",
"currentWeight": 0.3158,
"optimalWeight": 0.25,
"difference": -0.0658,
"action": "SELL"
}
],
"monteCarlo": {
"current": {
"graph": [],
"summary": {}
},
"optimal": {
"graph": [],
"summary": {}
}
}
}React Dashboard
↓
Express Backend
↓
Convert holdings into current weights
↓
Fetch historical prices using AlphaVantage
↓
FastAPI Quant Microservice
↓
Markowitz optimization + Monte Carlo simulation
↓
Return optimal allocation, risk metrics, graphs
↓
Render results in React dashboardThe optimizer calculates:
- Daily returns from historical closing prices
- Annualized expected returns
- Annualized covariance matrix
- Portfolio expected return
- Portfolio volatility
- Sharpe ratio
- Maximum Sharpe ratio allocation
- Current portfolio performance
- Optimized portfolio performance
- Rebalancing difference
The optimization objective is to maximize the Sharpe ratio:
Sharpe Ratio = (Portfolio Return - Risk Free Rate) / Portfolio VolatilityMonte Carlo simulation is used to estimate possible future portfolio value paths.
The simulation uses:
- Initial portfolio value
- Expected annual return
- Annual volatility
- Trading-day time step
- Random normal shocks
- Multiple simulation paths
The simulator outputs percentile paths such as:
- 5th percentile
- Median
- 95th percentile
These are visualized in the dashboard using Recharts.
FinTrack includes the following pages:
- Landing page
- Sign in
- Sign up
- Dashboard home
- Watchlist
- Invested holdings
- Returns
- Buy/Sell
- Transaction history
- AI Assistant
- Prediction Agent
- Quant Optimizer
- Mail Notifications
The prediction model is deployed on Render.
Example endpoint:
https://stock-analyser-ggjy.onrender.com/predict/MSFTThe quant service can also be deployed as a FastAPI service.
Recommended Render start command:
uvicorn main:app --host 0.0.0.0 --port $PORTIf the service is structured as app/main.py, use:
uvicorn app.main:app --host 0.0.0.0 --port $PORTDo not commit:
.env
venv/
node_modules/
dist/
build/
__pycache__/Only commit:
requirements.txt
package.json
package-lock.json
source code files
README.md- Connect notification system with MongoDB
- Add email alerts for price limits
- Add efficient frontier visualization
- Add portfolio beta calculation
- Add maximum drawdown calculation
- Add Value at Risk and Conditional Value at Risk
- Add sector diversification analysis
- Add Indian market support
- Add options pricing using Black-Scholes and CRR model
- Add live broker integration
- Deploy quant optimizer microservice separately
- Store optimization results in user history
- Market data powered by AlphaVantage
- UI built with React, Tailwind CSS, Bootstrap, and Recharts
- Backend powered by Node.js, Express, and MongoDB
- Quant analytics powered by Python, FastAPI, NumPy, Pandas, and SciPy
- AI assistant powered by OpenAI API
- ML prediction service deployed on Render
Vaibhav Tyagi
GitHub: vtyagi26