An intelligent investment advisory platform for the Nairobi Securities Exchange (NSE) that leverages machine learning to provide personalized stock recommendations based on user risk profiles.
- AI-Powered Recommendations: Machine learning model trained on NSE historical data provides personalized stock recommendations
- Risk Profile Analysis: KYC-based risk assessment (Conservative, Moderate, Aggressive)
- Real-Time Market Data: Live NSE market data including NASI index, top gainers/losers, and stock prices
- Dynamic Confidence Scores: ML-generated confidence levels with detailed breakdowns
- User Authentication: Secure JWT-based authentication with session management
- Portfolio Dashboard: Comprehensive view of investments, performance, and risk metrics
- Market Insights: Historical performance data and market trends
- React 19 with TypeScript
- React Router for navigation
- Context API for state management
- Custom CSS for styling
- Node.js with Express.js
- PostgreSQL for user data and authentication
- MongoDB for market data and stock information
- JWT for secure authentication
- Real-time NSE data scraping
- Python 3 with scikit-learn
- RandomForest Regressor for stock predictions
- Joblib for model serialization
- Custom recommendation engine with risk-adjusted scoring
- Node.js (v16+)
- PostgreSQL (v12+)
- MongoDB (v4.4+)
- Python 3.8+ with pip
- NSE historical data CSV files (2023, 2024)
git clone https://github.com/e-mutai/aiser.git
cd aiser# Install Node.js dependencies
npm install
# Setup Python virtual environment
cd ml
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
cd ..PostgreSQL:
# Create database
createdb -U postgres aiser
# Database will auto-initialize on first run
# Default table: users (id, email, password, first_name, last_name, phone_number, risk_score, kyc_verified, kyc_status, last_token)MongoDB:
# Start MongoDB service
sudo systemctl start mongod
# Database and collections are auto-created on first runcd ml/recommender
python train_model.py
# This generates ml/ml_model.joblib (~352MB, not tracked in git)Create a .env file in the root directory:
PORT=5000
JWT_SECRET=your-secret-key
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your-password
POSTGRES_DB=aiser
MONGODB_URI=mongodb://localhost:27017/aisernode server.js
# Backend runs on http://localhost:5000npm start
# Frontend runs on http://localhost:3000- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- Health Check: http://localhost:5000/api/health
POST /api/auth/register- Register new userPOST /api/auth/login- User loginGET /api/user/profile- Get user profile (requires auth)
POST /api/kyc/submit- Submit KYC informationGET /api/kyc/status- Check KYC verification status
GET /api/market/nse- Get NSE market overviewGET /api/market/stock/:ticker- Get specific stock data
GET /api/recommendations?count=5- Get AI recommendations- Query params:
count(number of recommendations)
- NSE historical stock data (2023-2024)
- Features: Price, Volume, Moving Averages, Volatility, RSI, MACD
- Target: 30-day predicted returns
- Algorithm: RandomForest Regressor
- Features: 20+ technical indicators
- Risk Adjustment: Conservative (-50%/-25%), Aggressive (+15%)
- Confidence Calculation: Based on predicted return and volatility
confidence = (predicted_return Γ 500) - (volatility Γ 1000)
# Adjusted by user risk profile
# Returns: BUY, HOLD, or SELL with confidence percentageaiser/
βββ src/ # React frontend
β βββ components/ # React components
β βββ contexts/ # Context providers
β βββ styles.css # Global styles
βββ ml/ # Machine learning
β βββ recommender/ # ML model code
β β βββ model.py # Model logic
β β βββ predict.py # Prediction script
β β βββ train_model.py # Training script
β βββ requirements.txt # Python dependencies
β βββ README.md # ML setup guide
βββ public/ # Static assets
βββ server.js # Express server
βββ routes.js # API routes
βββ mongodb.js # MongoDB connection
βββ scraper.js # NSE data scraper
βββ recommendation-engine.js # ML integration
βββ package.json # Node dependencies
- Bcrypt password hashing
- JWT token-based authentication
- Session management with token refresh
- Protected API routes
- KYC verification system
| Profile | Risk Score | Investment Strategy |
|---|---|---|
| Conservative | 0-40 | Low-risk stocks, bonds, stable returns |
| Moderate | 41-70 | Balanced portfolio, moderate growth |
| Aggressive | 71-100 | High-growth stocks, higher volatility |
# Frontend tests
npm test
# Backend API test
curl http://localhost:5000/api/health- The ML model file (
ml/ml_model.joblib) is not tracked in git due to size (352MB) - Each developer must train the model locally after cloning
- NSE data CSV files are required for model training
- Market data refreshes every 5 minutes
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit changes:
git commit -m 'Add feature' - Push to branch:
git push origin feature-name - Submit a pull request
This project is licensed under the MIT License.
- Enock Mutai (@e-mutai)
- NSE for market data
- scikit-learn for ML framework
- MeπΏ for the amazing frontend library