39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import os
|
|
import yfinance as yf
|
|
import features
|
|
import matplotlib
|
|
matplotlib.use("Agg")
|
|
|
|
def Predict():
|
|
# Define paths (consistent with your previous script)
|
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
DATA_DIR = os.path.join(SCRIPT_DIR, "data")
|
|
MODEL_PATH = os.path.join(DATA_DIR, "model.keras")
|
|
|
|
# Pull 1 month of current data to make prediction against | for volatility 20
|
|
df = yf.download("SPY", period="2mo", auto_adjust=True)
|
|
if not df.empty:
|
|
df = features.MakeFeatures(df, 1)
|
|
df = features.CleanDF(df)
|
|
|
|
# Drop our predictor
|
|
df.drop('Target_Close_Tomorrow', axis=1, inplace=True)
|
|
|
|
# Lazy load this so it doesnt interfere with yfinance
|
|
from keras.models import load_model
|
|
|
|
# Load the model
|
|
reconstructed_model = load_model(MODEL_PATH)
|
|
|
|
# Verify it loaded correctly
|
|
reconstructed_model.summary()
|
|
|
|
# Predict
|
|
predictions = reconstructed_model.predict(df)
|
|
|
|
# 'predictions' will be a 2D array, flatten it if you want a simple list
|
|
flat_predictions = predictions.flatten()
|
|
|
|
print(f"Predicted Target_Close_Tomorrow: {flat_predictions}")
|
|
|
|
return flat_predictions |