File size: 11,903 Bytes
c01e005
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: cc-by-nc-4.0
library_name: xgboost
tags:
- finance
- stock-market
- indian-stock-market
- nse
- bse
- tabular
- time-series
- xgboost
- classification
- indian-market
---

# XGBoost β€” Indian Stock Market Prediction

XGBoost binary classification model trained on historical Indian equity-market data to predict whether a stock reaches a specified positive-return threshold within a **5-trading-day horizon**.

The current model targets a **+3.0% return threshold** and was trained across thousands of Indian equities using technical, market, cross-sectional, and macroeconomic features.

> **Research status:** This repository contains a research model and its out-of-sample evaluation artifacts. The reported results should not be interpreted as a guarantee of future market performance or profitability.

---

## Model Overview

| Property                | Value                                |
| ----------------------- | ------------------------------------ |
| Model                   | XGBoost                              |
| Task                    | Binary classification                |
| Prediction target       | β‰₯ +3.0% return within 5 trading days |
| Dataset size            | ~6.92 million rows                   |
| Symbols                 | 2,656                                |
| Historical period       | 2008-09-02 β†’ 2026-06-30              |
| Features                | 221                                  |
| Positive class          | 36.8%                                |
| Negative class          | 63.2%                                |
| `scale_pos_weight`      | 1.49                                 |
| Training method         | Histogram-based XGBoost              |
| Hardware                | CUDA GPU                             |
| Maximum boosting rounds | 2,000                                |
| Learning rate           | 0.02                                 |
| Maximum tree depth      | 6                                    |
| Early stopping          | 75 rounds                            |

---

# Dataset

The training dataset contains approximately **6.92 million observations** covering **2,656 Indian stock symbols** from September 2008 through June 2026.

The model uses 221 input features derived from historical market data and broader market conditions.

The feature groups include:

* Price returns
* Momentum
* Trend indicators
* Volatility
* Technical indicators
* Relative strength
* Market breadth
* Cross-sectional statistics
* Nifty relationships
* Gold relationships
* Brent crude relationships
* USD/INR relationships
* US-market indicators

The target is a binary label representing whether the specified positive-return threshold is reached within the prediction horizon.

---

# Temporal Dataset Split

The dataset was divided chronologically rather than randomly.

| Split             | Period                  | Approx. Share |
| ----------------- | ----------------------- | ------------: |
| Training          | 2008-09-02 β†’ 2021-02-15 |           70% |
| Validation        | 2021-02-16 β†’ 2024-08-30 |           20% |
| Walk-forward test | 2024-09-01 β†’ 2026-06-30 |           10% |

This temporal separation is intended to reduce leakage from randomly mixing observations from different points in time.

The final test period was not used for model fitting.

---

# Validation Performance

The model achieved the following results on the held-out validation period:

**2021-02-16 β†’ 2024-08-30**

| Metric                             |      Score |
| ---------------------------------- | ---------: |
| ROC-AUC                            | **0.9472** |
| PR-AUC                             | **0.9042** |
| Precision                          | **0.7981** |
| Recall                             | **0.8364** |
| Information Coefficient (Spearman) | **0.7140** |
| Brier Score                        | **0.0835** |
| Brier Skill Score                  | **0.6068** |
| Mean Calibration Error             | **0.0749** |

Validation observations:

**1,698,058 rows**

The validation results indicate strong separation between the positive and negative classes on this historical period.

However, validation performance alone should not be treated as evidence of future profitability.

---

# Validation Decile Analysis

Predictions were divided into ten probability-ranked groups.

| Decile | Hit Rate | Samples |
| -----: | -------: | ------: |
|    D10 |    98.4% | 169,806 |
|     D9 |    88.8% | 169,806 |
|     D8 |    60.5% | 169,806 |
|     D7 |    31.1% | 169,805 |
|     D6 |    14.6% | 169,806 |
|     D5 |     6.6% | 169,806 |
|     D4 |     3.1% | 169,805 |
|     D3 |     1.7% | 169,806 |
|     D2 |     0.9% | 169,806 |
|     D1 |     0.4% | 169,806 |

The probability ranking shows strong separation across the validation sample, with substantially different observed positive rates between the lowest- and highest-ranked groups.

These figures describe historical classification performance and do not account for transaction costs, slippage, liquidity constraints, portfolio construction, or market impact.

---

# Out-of-Sample Walk-Forward Evaluation

The model was subsequently evaluated chronologically over the final portion of the dataset.

The test period was divided into four chronological folds of approximately six months each.

| Fold | Period                  |     PR-AUC |         IC |  Brier | Samples |
| ---- | ----------------------- | ---------: | ---------: | -----: | ------: |
| 1    | 2024-09-01 β†’ 2025-02-28 | **0.9336** | **0.7619** | 0.0850 | 262,062 |
| 2    | 2025-03-01 β†’ 2025-08-31 | **0.8987** | **0.7044** | 0.0829 | 266,786 |
| 3    | 2025-09-01 β†’ 2026-02-28 | **0.8921** | **0.7011** | 0.0845 | 282,585 |
| 4    | 2026-03-01 β†’ 2026-06-30 | **0.8962** | **0.7157** | 0.0925 | 180,837 |

### Walk-Forward Summary

| Statistic        |      Value |
| ---------------- | ---------: |
| Mean PR-AUC      | **0.9052** |
| Mean IC          | **0.7208** |
| Mean Brier Score | **0.0862** |
| Minimum IC       | **0.7011** |
| Maximum IC       | **0.7619** |

The model maintained relatively strong classification performance across all four chronological folds.

Performance did, however, vary between periods. The difference between the highest and lowest observed IC is approximately **0.061**.

This suggests that model performance is not completely invariant across market regimes and warrants additional robustness testing.

---

# Overfitting & Generalization

The model was evaluated using a chronological validation set followed by a later out-of-sample test period.

The results provide evidence that the model retains predictive separation outside its training period.

However, the current experiment does **not** establish that the model is free from overfitting.

In particular:

* Validation performance is very strong.
* Walk-forward test performance remains strong.
* Performance varies between chronological folds.
* The model reached the maximum configured **2,000 boosting rounds**, with the best iteration at **1,999**.
* Early stopping therefore did not activate before the configured maximum number of rounds.

The last point means that additional experiments with a larger maximum number of boosting rounds should be evaluated carefully rather than assuming that more trees will improve generalization.

Future experiments should compare performance across additional temporal folds and assess whether increasing model complexity improves out-of-sample performance or simply improves the validation period.

---

# Calibration

The validation set produced:

* Brier Score: **0.0835**
* Brier Skill Score: **0.6068**
* Mean Calibration Error: **0.0749**

The model therefore produces probability scores that contain useful information, but the raw probabilities should not automatically be interpreted as perfectly calibrated real-world probabilities.

Probability calibration should be evaluated separately if the model's output is to be interpreted probabilistically.

---

# Feature Set

The model uses 221 features.

Examples of macro and cross-market features include:

```text
usd_inr_sma20_ratio
usd_inr_sma200_ratio
usd_inr_momentum_10
usd_inr_momentum_20
usd_inr_volatility_20d
usd_inr_trend
usd_inr_zscore
usd_inr_vol_zscore
usd_inr_high_vol
usd_inr_appreciation

us_ret_1d
us_ret_5d
us_ret_20d
us_ret_60d

us_breadth_1d
us_breadth_5d
us_breadth_20d

us_dispersion_1d
us_dispersion_5d
us_avg_vol_ratio
us_pct_above_sma20
us_avg_rsi
us_avg_dist_52w_high

corr_nifty_20d
corr_nifty_60d
beta_nifty_60d
is_high_beta
is_low_beta
corr_breakdown

rel_strength_5d
rel_strength_20d

corr_gold_60d
corr_gold_rising

corr_brent_60d
corr_brent_rising

corr_usd_inr_60d
corr_usd_inr_rising

corr_us_60d
```

The complete feature schema is available in `model_metadata.json`.

---

# Model Artifacts

The repository contains the following artifacts:

| File                          | Description                                                                       |
| ----------------------------- | --------------------------------------------------------------------------------- |
| `xgb_model.json`              | Trained XGBoost model                                                             |
| `model_metadata.json`         | Training configuration, feature schema, split information and evaluation metadata |
| `feature_importance.csv`      | XGBoost feature-importance statistics                                             |
| `val_predictions.parquet`     | Validation predictions                                                            |
| `test_wf_predictions.parquet` | Chronological walk-forward test predictions                                       |

The prediction files are provided to make the reported evaluation results independently inspectable and reproducible.

---

# Reproducibility

The model metadata records:

* Feature names
* Feature count
* Dataset information
* Training period
* Validation period
* Model parameters
* Class weighting
* Best iteration
* Evaluation metrics
* Training timestamp

The model uses a fixed random seed of `42`.

---

# Important Limitations

This model should be considered a **research artifact**, not a guaranteed trading system.

The reported classification metrics do not directly measure:

* Portfolio returns
* Sharpe ratio
* Maximum drawdown
* Transaction costs
* Brokerage
* Taxes
* Slippage
* Bid/ask spread
* Market impact
* Position sizing
* Portfolio concentration
* Liquidity constraints
* Capacity
* Execution latency

A model can achieve strong classification metrics while producing poor investment returns after these factors are considered.

The target is also a classification threshold rather than a direct optimization of portfolio returns.

Additional research is therefore required before using the model for live decision-making.

---

# Current Research Status

The current experiment establishes a useful baseline for the **+3.0% / 5-trading-day** prediction task.

The next stages of research should include:

1. Additional temporal walk-forward experiments.
2. Comparison of model complexity and boosting-round counts.
3. Testing alternative return thresholds and horizons.
4. Feature ablation and importance stability analysis.
5. Leakage and feature-timing audits.
6. Performance analysis by market regime.
7. Calibration analysis on completely unseen periods.
8. Portfolio-level backtesting.
9. Transaction-cost and slippage modelling.
10. Paper-trading validation before considering live deployment.

---

# License

This model is published under the **Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)** license.

The license permits non-commercial use subject to the terms of the license.

Commercial use requires appropriate licensing.

---

# Author

[**Sayantan Basu**](https://sayantan-basu.vercel.app)