This project explores how unsupervised learning (market regimes) can be combined with reinforcement learning (RL) to model trading decisions on NVIDIA (NVDA) daily stock data.
The goal is not to beat buy-and-hold, but to:
- understand market structure,
- compare risk-aware vs profit-seeking policies,
- evaluate realistic trading performance.
src/
├── functions.py # Data processing, EDA, regimes, RL logic
├── notebook.ipynb # End-to-end analysis & experiments
├── nvda_market_data.csv # NVDA daily data (Yahoo Finance)
├── requirements.txt # Project dependencies
└── workspace.code-workspace
- Asset: NVIDIA (NVDA)
- Source: Yahoo Finance (
yfinance) - Frequency: Daily
- Period: 2010 – Present
- Features: OHLCV + engineered features
ret– daily return (%)volatility– rolling 20-day return standard deviation (%)volume_chg– daily volume change (%)
These describe price movement, risk, and market participation.
- Heavy-tailed returns and volume
- Volatility clustering
- Extreme return outliers (±20%)
- Weak linear correlations → motivates non-linear models
- Method: K-Means clustering
- Inputs: return & volatility
- Identified regimes:
- Bullish (positive returns)
- Bearish (negative returns)
- Sideways / low-volatility
Regimes provide market context, not direct predictions.
- Environment: NVDA daily returns with transaction costs
- Actions:
{-1 = short, 0 = hold, +1 = long} - Agent: Tabular Q-Learning
- Training: ε-greedy exploration (~20%, decayed)
- Evaluation: greedy policy (ε = 0)
Two agents are compared:
- Regime-blind RL
- Regime-aware RL (regime included in state)
- Cumulative PnL
- Average return
- Max drawdown (downside risk)
- Hit ratio (timing accuracy)
- Turnover (trading frequency)
- Buy-and-hold dominates in a strong bull market (NVDA).
- Regime-blind RL is more aggressive and trend-driven.
- Regime-aware RL trades less, with improved timing and risk control.
- Regimes add risk awareness, not guaranteed alpha.
- RL results vary due to stochastic exploration.
- Single-asset setting
- Simple regime definition
- Tabular RL
- In-sample evaluation only
- Multi-asset portfolios
- HMM or macro-based regimes
- Deep RL (DQN, Actor-Critic)
- Risk-adjusted rewards
- Walk-forward / out-of-sample testing
pip install -r requirements.txtThis project is for educational purposes only
and does not constitute financial advice.
Author: DS AI learner Karolis Vaivada