File size: 11,091 Bytes
8f71473 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | ---
dataset_info:
features:
- name: Date
dtype: string
- name: Open
dtype: float64
- name: High
dtype: float64
- name: Low
dtype: float64
- name: Close
dtype: float64
- name: Volume
dtype: int64
- name: Dividends
dtype: float64
- name: Stock Splits
dtype: float64
- name: Ticker
dtype: string
- name: SMA_5
dtype: float64
- name: SMA_10
dtype: float64
- name: SMA_20
dtype: float64
- name: SMA_50
dtype: float64
- name: EMA_12
dtype: float64
- name: EMA_26
dtype: float64
- name: MACD
dtype: float64
- name: MACD_Signal
dtype: float64
- name: MACD_Histogram
dtype: float64
- name: RSI
dtype: float64
- name: BB_Middle
dtype: float64
- name: BB_Upper
dtype: float64
- name: BB_Lower
dtype: float64
- name: BB_Width
dtype: float64
- name: BB_Position
dtype: float64
- name: Volatility
dtype: float64
- name: Price_Change
dtype: float64
- name: Price_Change_5d
dtype: float64
- name: High_Low_Ratio
dtype: float64
- name: Open_Close_Ratio
dtype: float64
- name: Volume_SMA
dtype: float64
- name: Volume_Ratio
dtype: float64
- name: Close_lag_1
dtype: float64
- name: Close_lag_2
dtype: float64
- name: Close_lag_3
dtype: float64
- name: Close_lag_5
dtype: float64
- name: Close_lag_10
dtype: float64
- name: Volume_lag_1
dtype: float64
- name: Volume_lag_2
dtype: float64
- name: Volume_lag_3
dtype: float64
- name: Volume_lag_5
dtype: float64
- name: Volume_lag_10
dtype: float64
- name: Price_Change_lag_1
dtype: float64
- name: Price_Change_lag_2
dtype: float64
- name: Price_Change_lag_3
dtype: float64
- name: Price_Change_lag_5
dtype: float64
- name: Price_Change_lag_10
dtype: float64
- name: RSI_lag_1
dtype: float64
- name: RSI_lag_2
dtype: float64
- name: RSI_lag_3
dtype: float64
- name: RSI_lag_5
dtype: float64
- name: RSI_lag_10
dtype: float64
- name: MACD_lag_1
dtype: float64
- name: MACD_lag_2
dtype: float64
- name: MACD_lag_3
dtype: float64
- name: MACD_lag_5
dtype: float64
- name: MACD_lag_10
dtype: float64
- name: Volatility_lag_1
dtype: float64
- name: Volatility_lag_2
dtype: float64
- name: Volatility_lag_3
dtype: float64
- name: Volatility_lag_5
dtype: float64
- name: Volatility_lag_10
dtype: float64
- name: Future_Return_1d
dtype: float64
- name: Future_Up_1d
dtype: int64
- name: Future_Category_1d
dtype: float64
- name: Future_Return_5d
dtype: float64
- name: Future_Up_5d
dtype: int64
- name: Future_Category_5d
dtype: float64
- name: Future_Return_10d
dtype: float64
- name: Future_Up_10d
dtype: int64
- name: Future_Category_10d
dtype: float64
- name: Future_Return_20d
dtype: float64
- name: Future_Up_20d
dtype: int64
- name: Future_Category_20d
dtype: float64
splits:
- name: train
num_bytes: 374644429
num_examples: 620095
download_size: 335534650
dataset_size: 374644429
configs:
- config_name: default
data_files:
- split: train
path: data/train-*
license: mit
task_categories:
- time-series-forecasting
- reinforcement-learning
- tabular-regression
language:
- en
tags:
- finance
- time-series
- stocks
- technical-analysis
- yahoo-finance
- reinforcement-learning
pretty_name: S&P 500 Comprehensive Stock Market Dataset
size_categories:
- 100K<n<1M
---
# ๐ S&P 500 Comprehensive Stock Market Dataset
<div align="center">





</div>
## ๐ฏ Dataset Overview
This comprehensive dataset contains **620,095 daily observations** of S&P 500 companies with **73 meticulously engineered features** spanning the last 5 years. Designed specifically for time series forecasting, stock price prediction, and advanced financial modeling tasks.
### ๐ Key Statistics
| Metric | Value |
|--------|-------|
| **Total Records** | 620,095 daily observations |
| **Features** | 73 comprehensive features |
| **Time Period** | Last 5 years |
| **Companies** | S&P 500 constituents |
| **Data Source** | Yahoo Finance API |
| **Update Frequency** | Daily market data |
## ๐ Quick Start
```python
from datasets import load_dataset
# Load the dataset
dataset = load_dataset("Adilbai/stock-dataset")
df = dataset["train"].to_pandas()
# Basic info
print(f"Dataset shape: {df.shape}")
print(f"Date range: {df['Date'].min()} to {df['Date'].max()}")
print(f"Unique tickers: {df['Ticker'].nunique()}")
```
## ๐ง Feature Categories
### ๐ Basic Market Data (9 features)
- **Date**: Trading date timestamp
- **OHLC Data**: Open, High, Low, Close prices
- **Volume**: Number of shares traded
- **Corporate Actions**: Dividends, Stock Splits
- **Ticker**: Stock symbol identifier
### ๐ Technical Analysis Indicators (16 features)
#### Moving Averages
- `SMA_5`, `SMA_10`, `SMA_20`, `SMA_50`: Simple Moving Averages
- `EMA_12`, `EMA_26`: Exponential Moving Averages
#### Momentum Indicators
- `MACD`, `MACD_Signal`, `MACD_Histogram`: MACD components
- `RSI`: Relative Strength Index (14-period)
#### Volatility Indicators
- `BB_Middle`, `BB_Upper`, `BB_Lower`: Bollinger Bands
- `BB_Width`, `BB_Position`: Bollinger Bands metrics
- `Volatility`: Historical volatility measure
### โ๏ธ Engineered Features (16 features)
- `Price_Change`: Daily price change
- `Price_Change_5d`: 5-day price change
- `High_Low_Ratio`: High to low price ratio
- `Open_Close_Ratio`: Open to close price ratio
- `Volume_SMA`: Volume moving average
- `Volume_Ratio`: Volume to average ratio
### โณ Lagged Features (32 features)
Historical context with 10-period lags for:
- **Price Lags**: `Close_lag_1` to `Close_lag_10`
- **Volume Lags**: `Volume_lag_1` to `Volume_lag_10`
- **Price Change Lags**: `Price_Change_lag_1` to `Price_Change_lag_10`
- **RSI Lags**: `RSI_lag_1` to `RSI_lag_10`
- **MACD Lags**: `MACD_lag_1` to `MACD_lag_10`
- **Volatility Lags**: `Volatility_lag_1` to `Volatility_lag_10`
### ๐ฏ Target Variables (12 features)
| Time Horizon | Return | Direction | Category |
|--------------|--------|-----------|----------|
| **1-Day** | `Future_Return_1d` | `Future_Up_1d` | `Future_Category_1d` |
| **5-Day** | `Future_Return_5d` | `Future_Up_5d` | `Future_Category_5d` |
| **10-Day** | `Future_Return_10d` | `Future_Up_10d` | `Future_Category_10d` |
| **20-Day** | `Future_Return_20d` | `Future_Up_20d` | `Future_Category_20d` |
## ๐ฏ Use Cases
### ๐ฎ Primary Applications
- **Stock Price Prediction**: Forecast future prices using technical indicators
- **Direction Classification**: Predict price movement direction
- **Risk Assessment**: Analyze volatility and market risk patterns
- **Trading Strategy Development**: Backtest algorithmic strategies
- **Financial Research**: Academic computational finance research
### ๐ค Machine Learning Tasks
- **Regression**: Predict continuous returns (`Future_Return_*`)
- **Binary Classification**: Predict direction (`Future_Up_*`)
- **Multi-class Classification**: Predict movements (`Future_Category_*`)
- **Time Series Forecasting**: Leverage lagged features
- **Anomaly Detection**: Identify unusual market patterns
## ๐ Example Usage
### Data Exploration
```python
# View dataset structure
print(f"Dataset shape: {df.shape}")
print(f"Features: {df.columns.tolist()}")
# Target distribution
print(df['Future_Up_1d'].value_counts())
print(df['Future_Category_1d'].value_counts())
```
### Feature Selection
```python
# Technical indicators
technical_features = [
'SMA_5', 'SMA_10', 'RSI', 'MACD',
'BB_Position', 'Volatility'
]
# Lagged features
lag_features = [col for col in df.columns if 'lag' in col]
# All targets
targets = [col for col in df.columns if 'Future_' in col]
```
### Model Training Example
```python
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import TimeSeriesSplit
# Prepare features and target
features = technical_features + lag_features
X = df[features].fillna(method='ffill')
y = df['Future_Return_1d']
# Time series split
tscv = TimeSeriesSplit(n_splits=5)
model = RandomForestRegressor(n_estimators=100)
# Train model
for train_idx, test_idx in tscv.split(X):
X_train, X_test = X.iloc[train_idx], X.iloc[test_idx]
y_train, y_test = y.iloc[train_idx], y.iloc[test_idx]
model.fit(X_train, y_train)
predictions = model.predict(X_test)
```
## โ ๏ธ Important Considerations
### ๐ด Data Limitations
- **Survivorship Bias**: Only current S&P 500 constituents included
- **Market Hours**: Regular trading session data only
- **Corporate Actions**: Historical adjustments may affect patterns
### โก Usage Guidelines
- **Temporal Order**: Maintain chronological order in train/test splits
- **Look-ahead Bias**: Avoid using future information in features
- **Market Regimes**: Performance may vary across market conditions
- **Feature Correlation**: Technical indicators share underlying price data
## ๐ Data Quality
### โ
Quality Assurance
- **Industry-standard** technical indicator calculations
- **Comprehensive** historical context with multiple time horizons
- **Robust** data validation pipelines
- **Proper handling** of corporate actions and market holidays
### ๐ง Data Processing
- **Forward-fill** methodology for missing data
- **Vectorized operations** for consistency
- **No look-ahead bias** in feature construction
- **Dividend and split** adjustments included
## ๐ Citation
If you use this dataset in your research, please cite:
```bibtex
@dataset{adilbai_sp500_dataset,
title={S&P 500 Comprehensive Stock Market Dataset},
author={Adilbai},
year={2024},
publisher={Hugging Face},
url={https://huggingface.co/datasets/Adilbai/stock-dataset}
}
```
## ๐ License
This dataset is released under the **MIT License**. While the dataset compilation and feature engineering are provided under MIT license, users should be aware of Yahoo Finance's terms of service for the underlying data.
## โ ๏ธ Disclaimer
> **Important**: This dataset is provided for educational and research purposes only. It should not be used as the sole basis for investment decisions. Past performance does not guarantee future results. Users should conduct their own research and consider consulting with financial advisors before making investment decisions.
---
<div align="center">
**Built with โค๏ธ for the financial ML community**
[๐ค Hugging Face](https://huggingface.co/datasets/Adilbai/stock-dataset) โข [๐ Dataset](https://huggingface.co/datasets/Adilbai/stock-dataset) โข [๐ Issues](https://huggingface.co/datasets/Adilbai/stock-dataset/discussions)
</div> |