Create a simulation to test 1 month of data in 30 mins
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from datetime import datetime, timedelta
|
||||
import os
|
||||
import sys
|
||||
import joblib
|
||||
@@ -13,13 +14,29 @@ def Predict():
|
||||
# Get the Symbol from ARGV
|
||||
Symbol = sys.argv[1]
|
||||
|
||||
# get the number of days ago to run the simulation for
|
||||
DaysBack = int(sys.argv[2])
|
||||
|
||||
print(f"Days back: {DaysBack}")
|
||||
|
||||
# calculate the time offsets
|
||||
end_date = datetime.now() - timedelta(days=DaysBack)
|
||||
start_date = end_date - timedelta(days=70)
|
||||
|
||||
# convert to string formats
|
||||
start_str = start_date.strftime('%Y-%m-%d')
|
||||
end_str = end_date.strftime('%Y-%m-%d')
|
||||
|
||||
print(f"Start Date: {start_str}")
|
||||
print(f"End Date: {end_str}")
|
||||
|
||||
# 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(Symbol, period="2mo", auto_adjust=True)
|
||||
df = yf.download(Symbol, start=start_str, end=end_str, auto_adjust=True, progress=False)
|
||||
if not df.empty:
|
||||
# Remove the horizontal ticker column
|
||||
df.columns = df.columns.get_level_values(0)
|
||||
|
||||
@@ -78,10 +78,11 @@ def MakeFeatures(df):
|
||||
df.drop(col, axis=1, inplace=True)
|
||||
|
||||
# Drop rows with null values
|
||||
df.dropna(inplace=True)
|
||||
feature_columns = [col for col in df.columns if col != 'Target_Close'] # Dont drop any Target_Close as we need this data for predictions
|
||||
df.dropna(subset=feature_columns, inplace=True)
|
||||
|
||||
# Replace Infinity with 0 -> This fixes the AI mental breakdown
|
||||
df = df.replace([np.inf, -np.inf], 0)
|
||||
df.replace([np.inf, -np.inf], 0, inplace=True)
|
||||
|
||||
# Replace Infinity with 0 -> This fixes the AI mental breakdown
|
||||
df['Volume_Chg'] = df['Volume_Chg'].replace([np.inf, -np.inf], 0)
|
||||
|
||||
Reference in New Issue
Block a user