A full-stack AI-powered algorithmic trading simulator combining supervised ML, reinforcement learning, portfolio optimisation, and advanced risk modelling β with live daily trading signals and explainable AI.
π Live App Β· π Features Β· π οΈ Tech Stack Β· β‘ Quick Start
AlgoTrade AI is a quantitative finance research platform built end-to-end in Python. It fetches live market data from Yahoo Finance, runs trained ML and RL models to generate trading signals, and presents everything through an interactive Streamlit dashboard with eight analytical pages.
The platform is designed to demonstrate skills relevant to quant research, algorithmic trading, and ML engineering roles β covering the full pipeline from raw data ingestion to deployed web application.
- Fetches live OHLCV data from Yahoo Finance up to yesterday's close β automatically every day
- Runs all three trained models (XGBoost, Random Forest, Logistic Regression) and displays BUY / HOLD / SELL
- SHAP explainability β bar chart showing exactly which feature influenced the prediction and by how much
- AI reasoning cards β plain English explanation of RSI, MACD, Bollinger Bands, MA crossovers, and model confidence
- 90-day candlestick chart with signal marked, MACD subplot, RSI subplot
- Three trained classifiers: XGBoost, Random Forest, Logistic Regression
- Price chart with BUY/SELL signal markers and probability band
- Real model evaluation metrics: Accuracy, Precision, Recall, ROC-AUC, F1
- Feature importance bar chart from trained model
- Confusion matrix
- Equity curve vs Buy & Hold
- Reinforcement learning trading agent (PPO-based momentum strategy)
- Portfolio vs Buy & Hold chart with trade markers
- Training reward curve
- Rolling 20-day portfolio returns
- Trade distribution and recent trades table
- Unified equity curve comparison: ML vs RL vs Buy & Hold
- Drawdown chart for both strategies
- Live quote panel (price, open, high, low, volume)
- Strategy metrics comparison table
- Signal indicators (RSI, MACD, BB Width, MA Cross)
- Modern Portfolio Theory with 1,000 random portfolio simulations
- Efficient frontier scatter plot coloured by Sharpe ratio
- Max Sharpe and Min Volatility portfolios highlighted
- Optimal weight allocation donut chart
- Correlation matrix heatmap
- Individual stock return and volatility cards
- Historical VaR, Parametric VaR, Monte Carlo VaR β all three methods
- Confidence level slider updates all three simultaneously
- Rolling 60-day VaR chart
- Daily return distribution histogram
- Realised vs EWMA predicted volatility
- Up to 5,000 Geometric Brownian Motion price paths
- Fan chart with 5th / 25th / 50th / 75th / 95th percentile bands
- Final value distribution histogram
- Scenario summary (Bear / Low / Base / High / Bull)
- Distribution stats: mean, std dev, skewness, kurtosis, tail probabilities
- Full execution history for ML and RL strategies
- Real P&L calculated from actual BUY β SELL round trips (not simulated)
- Cumulative P&L chart with individual trade bars
- P&L distribution histogram
- Monthly breakdown bar chart
- Trade stats: win rate, avg win/loss, profit factor, best/worst trade
| Layer | Technology |
|---|---|
| Language | Python 3.10+ |
| Dashboard | Streamlit |
| ML Models | scikit-learn, XGBoost |
| RL Agent | Momentum-based strategy (PPO architecture) |
| Data | Yahoo Finance via yfinance |
| Visualisation | Plotly |
| Explainability | SHAP |
| Numerical | NumPy, pandas |
| Deployment | Streamlit Community Cloud |
StockProject/
β
βββ data/
β βββ raw/ # OHLCV CSVs downloaded from Yahoo Finance
β β βββ AAPL.csv
β β βββ TSLA.csv
β β βββ ...
β βββ processed/ # Feature-engineered CSVs for model training
β β βββ AAPL_features.csv
β β βββ ...
β βββ data_loader.py # Downloads raw data from Yahoo Finance
β βββ live_feed.py # Fetches live data + computes features daily
β
βββ ml_price_prediction/
β βββ train_model.py # Trains XGBoost, RF, Logistic Regression
β βββ predict.py # Generates signals from trained models
β βββ evaluation.py # Model evaluation metrics
β
βββ ml_strategy_rl/
β βββ rl_agent.py # DQN-based RL agent
β βββ trading_environment.py # Custom Gym-style trading environment
β βββ q_learning_agent.py # Q-learning baseline
β βββ reward_functions.py # Reward shaping
β βββ train_rl_agent.py # RL training loop
β
βββ backtesting/
β βββ backtester.py # Core backtesting engine
β βββ performance_metrics.py # Sharpe, VaR, drawdown, win rate etc.
β
βββ risk_management/
β βββ var_model.py # VaR calculations
β βββ monte_carlo.py # Monte Carlo simulation
β βββ volatility_prediction.py
β βββ risk_controls.py
β
βββ portfolio/
β βββ allocation.py
β βββ portfolio_manager.py
β
βββ models/ # Trained .pkl model files
β βββ xgb_model.pkl
β βββ random_forest_model.pkl
β βββ logistic_model.pkl
β
βββ signals/
β βββ trading_signals.csv
β
βββ dashboard/
β βββ AlgoTradeAI/
β βββ trading_app/
β βββ app.py # Home page
β βββ utils.py # Shared theme, data loaders, sidebar
β βββ pages/
β βββ Daily_Signal.py # π‘ Live daily prediction
β βββ ML_Prediction.py # π€ ML model signals
β βββ RL_Agent.py # π§ RL trading agent
β βββ Overview.py # π Portfolio overview
β βββ Portfolio_Optimizer.py # πΌ Efficient frontier
β βββ Price_Indicators.py # π Technical analysis
β βββ Risk_VaR.py # β οΈ Value at Risk
β βββ Monte_Carlo.py # π² Price path simulation
β βββ Trade_Log.py # π Execution history
β
βββ requirements.txt
βββ README.md
git clone https://github.com/Varsh24-hash/AI-trading.git
cd StockProjectpip install -r requirements.txtpython data/data_loader.pypython ml_price_prediction/train_model.pystreamlit run dashboard/AlgoTradeAI/trading_app/app.pySix features are computed from raw OHLCV data β these match exactly between training and live inference:
| Feature | Description |
|---|---|
return_1d |
Previous day's percentage return |
MA_10 |
10-day simple moving average |
MA_50 |
50-day simple moving average |
volatility |
10-day rolling annualised volatility |
volume_change |
Day-over-day volume percentage change |
RSI |
14-period Relative Strength Index |
| Model | Use case |
|---|---|
| XGBoost | Primary signal β gradient boosted trees, handles non-linearity |
| Random Forest | Ensemble baseline β robust to overfitting |
| Logistic Regression | Linear baseline β interpretable coefficients |
All models are trained on an 80/20 time-series split (no data leakage).
Probability > 0.60 β BUY
Probability < 0.40 β SELL
Otherwise β HOLD
The daily signal feature is the key differentiator of this project. Unlike models trained on a fixed historical window, it:
- Fetches 2 years of data from Yahoo Finance up to yesterday's close
- Computes all 6 features on the fresh data
- Runs the saved
.pklmodel β no retraining required - Generates a BUY / HOLD / SELL signal for tomorrow
- Explains the decision using SHAP values and indicator analysis
This means the signal is always based on the most recent market data available, without any manual intervention.
| Ticker | Company |
|---|---|
| AAPL | Apple Inc. |
| TSLA | Tesla Inc. |
| MSFT | Microsoft Corp. |
| GOOGL | Alphabet Inc. |
| AMZN | Amazon.com |
| NVDA | NVIDIA Corp. |
| META | Meta Platforms |
| JPM | JPMorgan Chase |
| V | Visa Inc. |
| WMT | Walmart Inc. |
All strategy backtests report the following metrics:
- Total Return β cumulative portfolio growth
- Annualised Return β CAGR assuming 252 trading days
- Volatility β annualised standard deviation of daily returns
- Sharpe Ratio β excess return per unit of risk
- Max Drawdown β largest peak-to-trough decline
- Win Rate β percentage of profitable trading days
- Calmar Ratio β annualised return / max drawdown
- Sortino Ratio β downside-only risk-adjusted return
- VaR (Historical / Parametric / Monte Carlo) β daily loss limit at confidence level
- CVaR / Expected Shortfall β average loss beyond VaR threshold
The app is deployed on Streamlit Community Cloud and rebuilds automatically on every push to main.
Live URL: https://ai-trading-8yddslultqfz2hfv9yt32z.streamlit.app
Built by Varshini and Chandrakala as a quantitative finance and ML engineering portfolio project.