thoutam commited on
Commit
20dcc05
·
verified ·
1 Parent(s): 2b7be18

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ nse_lstm_model.keras filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual environments
24
+ venv/
25
+ env/
26
+ ENV/
27
+
28
+ # IDE
29
+ .vscode/
30
+ .idea/
31
+ *.swp
32
+ *.swo
33
+
34
+ # OS
35
+ .DS_Store
36
+ Thumbs.db
37
+
38
+ # Jupyter
39
+ .ipynb_checkpoints/
40
+
41
+ # Model files (if you want to exclude them)
42
+ # *.keras
43
+ # *.pkl
README.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NSE LSTM Model - Indian Stock Market Prediction
2
+
3
+ ## Overview
4
+ This is a comprehensive LSTM (Long Short-Term Memory) neural network model trained on **6.8 million records** across **3,622 symbols** from the National Stock Exchange (NSE) of India. The model covers data from 2004-2025 and provides stock price predictions based on technical indicators and historical patterns.
5
+
6
+ ## Model Details
7
+ - **Architecture**: LSTM with Dropout layers
8
+ - **Input Shape**: (batch_size, 5, 25) - 5 days × 25 features
9
+ - **Output**: Single prediction value for next day's price
10
+ - **Training Data**: 6,795,445 records across 3,622 symbols
11
+ - **Features**: OHLCV data + 20 technical indicators
12
+ - **Model Size**: 0.23 MB
13
+ - **Parameters**: 16,289
14
+
15
+ ## Features
16
+ - **Price Data**: OPEN, HIGH, LOW, CLOSE, VOLUME
17
+ - **Technical Indicators**:
18
+ - Moving Averages (5, 10, 20, 50 day)
19
+ - Bollinger Bands (20 day)
20
+ - RSI (14 day)
21
+ - MACD
22
+ - Volume indicators (OBV, VPT)
23
+
24
+ ## Usage
25
+
26
+ ### Python
27
+ ```python
28
+ import tensorflow as tf
29
+ import pickle
30
+ import numpy as np
31
+
32
+ # Load model and scaler
33
+ model = tf.keras.models.load_model("nse_lstm_model.keras")
34
+ with open("nse_lstm_scaler.pkl", "rb") as f:
35
+ scaler = pickle.load(f)
36
+
37
+ # Prepare input data (5 days × 25 features)
38
+ input_data = np.random.randn(1, 5, 25) # Your normalized features here
39
+
40
+ # Make prediction
41
+ prediction = model.predict(input_data)
42
+ print(f"Predicted price change: {prediction[0][0]}")
43
+ ```
44
+
45
+ ### Input Data Format
46
+ Your input should be normalized data with shape (batch_size, 5, 25):
47
+ - **5**: Number of days (lookback period)
48
+ - **25**: Number of features (OHLCV + technical indicators)
49
+
50
+ ### Output
51
+ The model outputs a single value representing the predicted price change/movement for the next day.
52
+
53
+ ## Data Sources
54
+ - **NSE Bhavcopy**: Daily equity data from 2004-2025
55
+ - **Symbols**: 3,622 unique equity symbols
56
+ - **Frequency**: Daily data points
57
+ - **Coverage**: All major Indian stocks
58
+
59
+ ## Performance
60
+ - **Training MAE**: 0.0216
61
+ - **Validation MAE**: 0.0217
62
+ - **Memory Efficient**: Processes large datasets with minimal memory usage
63
+ - **Fast Inference**: Optimized for real-time predictions
64
+
65
+ ## License
66
+ MIT License - Free for commercial and research use.
67
+
68
+ ## Citation
69
+ If you use this model in your research, please cite:
70
+ ```
71
+ @software{nse_lstm_model,
72
+ title={NSE LSTM Model - Indian Stock Market Prediction},
73
+ author={Your Name},
74
+ year={2025},
75
+ url={https://huggingface.co/your-username/nse-lstm-model}
76
+ }
77
+ ```
78
+
79
+ ## Support
80
+ For questions or issues, please open an issue on the Hugging Face repository.
UPLOAD_INSTRUCTIONS.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hugging Face Upload Instructions
2
+
3
+ ## Step 1: Install Hugging Face Hub
4
+ ```bash
5
+ pip install huggingface_hub
6
+ ```
7
+
8
+ ## Step 2: Login to Hugging Face
9
+ ```bash
10
+ huggingface-cli login
11
+ ```
12
+
13
+ ## Step 3: Create Repository
14
+ ```bash
15
+ huggingface-cli repo create nse-lstm-model --type model
16
+ ```
17
+
18
+ ## Step 4: Upload Files
19
+ ```bash
20
+ cd nse-lstm-model-hf
21
+ git init
22
+ git add .
23
+ git commit -m "Initial commit: NSE LSTM Model"
24
+ git branch -M main
25
+ git remote add origin https://huggingface.co/YOUR_USERNAME/nse-lstm-model
26
+ git push -u origin main
27
+ ```
28
+
29
+ ## Alternative: Use Python API
30
+ ```python
31
+ from huggingface_hub import HfApi
32
+
33
+ api = HfApi()
34
+ api.upload_folder(
35
+ folder_path="./nse-lstm-model-hf",
36
+ repo_id="YOUR_USERNAME/nse-lstm-model",
37
+ repo_type="model"
38
+ )
39
+ ```
40
+
41
+ ## Step 5: Verify Upload
42
+ Visit: https://huggingface.co/YOUR_USERNAME/nse-lstm-model
43
+
44
+ ## Important Notes:
45
+ - Replace YOUR_USERNAME with your actual Hugging Face username
46
+ - Make sure you're logged in before uploading
47
+ - The repository will be public by default
48
+ - You can make it private in the repository settings if needed
model_card.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_name": "nse-lstm-model",
3
+ "model_type": "LSTM Neural Network",
4
+ "task": "Stock Price Prediction",
5
+ "dataset": "NSE Bhavcopy (2004-2025)",
6
+ "metrics": {
7
+ "training_mae": 0.0216,
8
+ "validation_mae": 0.0217
9
+ },
10
+ "architecture": {
11
+ "input_shape": [
12
+ 5,
13
+ 25
14
+ ],
15
+ "output_shape": [
16
+ 1
17
+ ],
18
+ "layers": [
19
+ "LSTM(32) + Dropout",
20
+ "LSTM(32) + Dropout",
21
+ "Dense(16)",
22
+ "Dense(1)"
23
+ ]
24
+ },
25
+ "features": [
26
+ "OHLCV data",
27
+ "Moving Averages",
28
+ "Bollinger Bands",
29
+ "RSI",
30
+ "MACD",
31
+ "Volume indicators"
32
+ ]
33
+ }
model_summary.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Model: "sequential"
2
+ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
3
+ ┃ Layer (type) ┃ Output Shape ┃ Param # ┃
4
+ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
5
+ │ lstm (LSTM) │ (None, 5, 32) │ 7,424 │
6
+ ├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
7
+ │ dropout (Dropout) │ (None, 5, 32) │ 0 │
8
+ ├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
9
+ │ lstm_1 (LSTM) │ (None, 32) │ 8,320 │
10
+ ├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
11
+ │ dropout_1 (Dropout) │ (None, 32) │ 0 │
12
+ ├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
13
+ │ dense (Dense) │ (None, 16) │ 528 │
14
+ ├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
15
+ │ dense_1 (Dense) │ (None, 1) │ 17 │
16
+ └──────────────────────────────────────┴─────────────────────────────┴─────────────────┘
17
+ Total params: 48,869 (190.90 KB)
18
+ Trainable params: 16,289 (63.63 KB)
19
+ Non-trainable params: 0 (0.00 B)
20
+ Optimizer params: 32,580 (127.27 KB)
21
+
nse_analysis_report.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "market_data_summary": {
3
+ "total_records": 0,
4
+ "symbols": 0,
5
+ "first_date": "N/A",
6
+ "last_date": "N/A"
7
+ },
8
+ "machine_learning": {
9
+ "lstm_results": {
10
+ "model": "LSTM",
11
+ "model_path": "models2/nse_lstm_model.keras",
12
+ "scaler_path": "models2/nse_lstm_scaler.pkl",
13
+ "train_loss": 0.0015773652121424675,
14
+ "train_mae": 0.02762329764664173,
15
+ "val_loss": 0.0015750526217743754,
16
+ "val_mae": 0.027563970535993576,
17
+ "history": {
18
+ "loss": [
19
+ 0.0015480784932151437,
20
+ 0.002932109171524644,
21
+ 0.009403415955603123,
22
+ 0.023545261472463608,
23
+ 0.04855493828654289,
24
+ 0.044199347496032715,
25
+ 0.0762166827917099,
26
+ 78.63263702392578,
27
+ 9692.16796875,
28
+ 36239.0546875,
29
+ 84249.0078125,
30
+ 7013.48095703125,
31
+ 10702.74609375,
32
+ 12723.4296875
33
+ ],
34
+ "mae": [
35
+ 0.02659163624048233,
36
+ 0.037797678261995316,
37
+ 0.05836370214819908,
38
+ 0.07535453885793686,
39
+ 0.1022288054227829,
40
+ 0.10583309829235077,
41
+ 0.10871369391679764,
42
+ 3.3740968704223633,
43
+ 73.62953186035156,
44
+ 139.64306640625,
45
+ 151.9230499267578,
46
+ 57.11256408691406,
47
+ 77.97837829589844,
48
+ 80.78185272216797
49
+ ],
50
+ "val_loss": [
51
+ 0.018675556406378746,
52
+ 0.0017560715787112713,
53
+ 0.04419953376054764,
54
+ 0.022364916279911995,
55
+ 0.005836417432874441,
56
+ 0.001575050177052617,
57
+ 0.0030426799785345793,
58
+ 634.7198486328125,
59
+ 19677.65234375,
60
+ 148614.546875,
61
+ 380.3380126953125,
62
+ 44098.953125,
63
+ 6205.689453125,
64
+ 1335.5394287109375
65
+ ],
66
+ "val_mae": [
67
+ 0.11402406543493271,
68
+ 0.031271662563085556,
69
+ 0.1806182712316513,
70
+ 0.12852078676223755,
71
+ 0.06497026234865189,
72
+ 0.027564017102122307,
73
+ 0.043761204928159714,
74
+ 19.872629165649414,
75
+ 122.6081314086914,
76
+ 301.1653137207031,
77
+ 12.19382381439209,
78
+ 190.978515625,
79
+ 71.1518783569336,
80
+ 29.952810287475586
81
+ ],
82
+ "lr": [
83
+ "0.001",
84
+ "0.001",
85
+ "0.001",
86
+ "0.001",
87
+ "0.001",
88
+ "0.001",
89
+ "0.001",
90
+ "0.001",
91
+ "0.001",
92
+ "0.001",
93
+ "0.001",
94
+ "0.0005",
95
+ "0.0005",
96
+ "0.0005"
97
+ ]
98
+ },
99
+ "training_samples": 1280968
100
+ },
101
+ "feature_matrix_shape": [
102
+ 0,
103
+ 0,
104
+ 0
105
+ ],
106
+ "target_shape": [
107
+ 0
108
+ ]
109
+ },
110
+ "portfolio_analysis": {
111
+ "current_metrics": {
112
+ "total_return": 2.3073407999465134,
113
+ "annualized_return": 0.36532566854144766,
114
+ "volatility": 0.0770446508288667,
115
+ "sharpe_ratio": 3.9629703718126237,
116
+ "max_drawdown": -0.0988339432662663,
117
+ "var_95": -0.006888707323040753,
118
+ "cvar_95": -0.010674858148910114,
119
+ "weights": "[0.0003 0.0003 0.0003 ... 0.0003 0.0003 0.0003]"
120
+ }
121
+ }
122
+ }
nse_lstm_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b5f0ec0075a2f175d6ea2b0611d66bfb09a31907b08eb159742c7a2d866e922a
3
+ size 276593
nse_lstm_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f7addaeba5f1aa94fe637337fae2308aead5c9950f85f6dbdb4e38794be30e01
3
+ size 1193
nse_lstm_summary.txt ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Model: "sequential"
2
+ _________________________________________________________________
3
+ Layer (type) Output Shape Param #
4
+ =================================================================
5
+ lstm (LSTM) (None, 5, 64) 24576
6
+
7
+ dropout (Dropout) (None, 5, 64) 0
8
+
9
+ lstm_1 (LSTM) (None, 64) 33024
10
+
11
+ dropout_1 (Dropout) (None, 64) 0
12
+
13
+ dense (Dense) (None, 32) 2080
14
+
15
+ dense_1 (Dense) (None, 16) 528
16
+
17
+ dense_2 (Dense) (None, 1) 17
18
+
19
+ =================================================================
20
+ Total params: 60225 (235.25 KB)
21
+ Trainable params: 60225 (235.25 KB)
22
+ Non-trainable params: 0 (0.00 Byte)
23
+ _________________________________________________________________
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ tensorflow>=2.10.0
2
+ numpy>=1.21.0
3
+ pandas>=1.3.0
4
+ scikit-learn>=1.0.0
5
+ pickle5>=0.0.11
usage_example.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NSE LSTM Model Usage Example
2
+
3
+ import tensorflow as tf
4
+ import pickle
5
+ import numpy as np
6
+ import pandas as pd
7
+
8
+ def load_model():
9
+ """Load the trained NSE LSTM model and scaler"""
10
+ model = tf.keras.models.load_model("nse_lstm_model.keras")
11
+ with open("nse_lstm_scaler.pkl", "rb") as f:
12
+ scaler = pickle.load(f)
13
+ return model, scaler
14
+
15
+ def prepare_features(data):
16
+ """Prepare features for prediction"""
17
+ # This is a simplified example - you'll need to implement
18
+ # the same feature engineering used during training
19
+
20
+ features = []
21
+ for i in range(len(data) - 4): # 5-day window
22
+ window = data[i:i+5]
23
+ # Calculate your 25 features here
24
+ # For now, using dummy data
25
+ feature_vector = np.random.randn(25)
26
+ features.append(feature_vector)
27
+
28
+ return np.array(features).reshape(-1, 5, 25)
29
+
30
+ def predict_stock_price(symbol_data):
31
+ """Predict next day's stock price"""
32
+ model, scaler = load_model()
33
+
34
+ # Prepare features
35
+ features = prepare_features(symbol_data)
36
+
37
+ # Make prediction
38
+ prediction = model.predict(features)
39
+
40
+ return prediction
41
+
42
+ # Example usage
43
+ if __name__ == "__main__":
44
+ # Load your stock data here
45
+ # data = pd.read_csv("your_stock_data.csv")
46
+
47
+ # For demonstration, using random data
48
+ dummy_data = np.random.randn(100, 5) # 100 days, 5 features
49
+
50
+ prediction = predict_stock_price(dummy_data)
51
+ print(f"Predicted price change: {prediction[0][0]}")