File size: 1,488 Bytes
20dcc05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# NSE LSTM Model Usage Example

import tensorflow as tf
import pickle
import numpy as np
import pandas as pd

def load_model():
    """Load the trained NSE LSTM model and scaler"""
    model = tf.keras.models.load_model("nse_lstm_model.keras")
    with open("nse_lstm_scaler.pkl", "rb") as f:
        scaler = pickle.load(f)
    return model, scaler

def prepare_features(data):
    """Prepare features for prediction"""
    # This is a simplified example - you'll need to implement
    # the same feature engineering used during training
    
    features = []
    for i in range(len(data) - 4):  # 5-day window
        window = data[i:i+5]
        # Calculate your 25 features here
        # For now, using dummy data
        feature_vector = np.random.randn(25)
        features.append(feature_vector)
    
    return np.array(features).reshape(-1, 5, 25)

def predict_stock_price(symbol_data):
    """Predict next day's stock price"""
    model, scaler = load_model()
    
    # Prepare features
    features = prepare_features(symbol_data)
    
    # Make prediction
    prediction = model.predict(features)
    
    return prediction

# Example usage
if __name__ == "__main__":
    # Load your stock data here
    # data = pd.read_csv("your_stock_data.csv")
    
    # For demonstration, using random data
    dummy_data = np.random.randn(100, 5)  # 100 days, 5 features
    
    prediction = predict_stock_price(dummy_data)
    print(f"Predicted price change: {prediction[0][0]}")