Skip to content

e-mutai/aiser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AISER - AI-Powered Investment Advisory Platform

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.

πŸš€ Features

  • 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

πŸ› οΈ Tech Stack

Frontend

  • React 19 with TypeScript
  • React Router for navigation
  • Context API for state management
  • Custom CSS for styling

Backend

  • 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

Machine Learning

  • Python 3 with scikit-learn
  • RandomForest Regressor for stock predictions
  • Joblib for model serialization
  • Custom recommendation engine with risk-adjusted scoring

πŸ“‹ Prerequisites

  • Node.js (v16+)
  • PostgreSQL (v12+)
  • MongoDB (v4.4+)
  • Python 3.8+ with pip
  • NSE historical data CSV files (2023, 2024)

βš™οΈ Installation

1. Clone the Repository

git clone https://github.com/e-mutai/aiser.git
cd aiser

2. Install Dependencies

# 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 ..

3. Database Setup

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 run

4. Train ML Model

cd ml/recommender
python train_model.py
# This generates ml/ml_model.joblib (~352MB, not tracked in git)

5. Environment Variables (Optional)

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/aiser

πŸš€ Running the Application

Start Backend Server

node server.js
# Backend runs on http://localhost:5000

Start Frontend (New Terminal)

npm start
# Frontend runs on http://localhost:3000

Access the Application

πŸ“‘ API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - User login
  • GET /api/user/profile - Get user profile (requires auth)

KYC & Risk Assessment

  • POST /api/kyc/submit - Submit KYC information
  • GET /api/kyc/status - Check KYC verification status

Market Data

  • GET /api/market/nse - Get NSE market overview
  • GET /api/market/stock/:ticker - Get specific stock data

Recommendations

  • GET /api/recommendations?count=5 - Get AI recommendations
  • Query params: count (number of recommendations)

πŸ€– ML Model Details

Training Data

  • NSE historical stock data (2023-2024)
  • Features: Price, Volume, Moving Averages, Volatility, RSI, MACD
  • Target: 30-day predicted returns

Model Architecture

  • Algorithm: RandomForest Regressor
  • Features: 20+ technical indicators
  • Risk Adjustment: Conservative (-50%/-25%), Aggressive (+15%)
  • Confidence Calculation: Based on predicted return and volatility

Recommendation Engine

confidence = (predicted_return Γ— 500) - (volatility Γ— 1000)
# Adjusted by user risk profile
# Returns: BUY, HOLD, or SELL with confidence percentage

πŸ“ Project Structure

aiser/
β”œβ”€β”€ 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

πŸ” Security Features

  • Bcrypt password hashing
  • JWT token-based authentication
  • Session management with token refresh
  • Protected API routes
  • KYC verification system

πŸ“Š User Risk Profiles

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

πŸ§ͺ Testing

# Frontend tests
npm test

# Backend API test
curl http://localhost:5000/api/health

πŸ“ Notes

  • 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

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Commit changes: git commit -m 'Add feature'
  4. Push to branch: git push origin feature-name
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.

πŸ‘₯ Authors

  • Enock Mutai (@e-mutai)

πŸ™ Acknowledgments

  • NSE for market data
  • scikit-learn for ML framework
  • MeπŸ—Ώ for the amazing frontend library

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors