Try to fix the AI some more
This commit is contained in:
@@ -11,37 +11,25 @@ def MakeFeatures(df):
|
||||
df['Body_Size'] = (df['Close'] - df['Open']).abs() / (df['High'] - df['Low'])
|
||||
df['Upper_Shadow'] = (df['High'] - candle_top) / (df['High'] - df['Low'])
|
||||
|
||||
# Remove Unused Symbols to save ram
|
||||
df.drop('Open', axis=1, inplace=True)
|
||||
df.drop('High', axis=1, inplace=True)
|
||||
df.drop('Low', axis=1, inplace=True)
|
||||
|
||||
# Is volume 2x higher than the 20-day average?
|
||||
df['Vol_Intensity'] = df['Volume'] / df['Volume'].shift(1).rolling(20).mean()
|
||||
# Volume Change
|
||||
df['Volume_Chg'] = df['Volume'].pct_change()
|
||||
|
||||
# Remove Unused Symbols to save ram
|
||||
df.drop('Volume', axis=1, inplace=True)
|
||||
|
||||
# Moving Average Crossover (Golden/Death Cross logic)
|
||||
df['Moving_Average_5'] = df['Close'].shift(1).rolling(window=20).mean()
|
||||
df['Moving_Average_20'] = df['Close'].shift(1).rolling(window=20).mean()
|
||||
df['Moving_Average_5'] = df['Close'].rolling(window=5).mean()
|
||||
df['Moving_Average_20'] = df['Close'].rolling(window=20).mean()
|
||||
# if short term > long term (bullish), else 0
|
||||
df['Trend_Signal'] = (df['Moving_Average_5'] > df['Moving_Average_20']).astype(int)
|
||||
# Distance from MA (How overextended are we?)
|
||||
df['Dist_From_MA20'] = (df['Close'] / df['Moving_Average_20']) - 1
|
||||
|
||||
# Bollinger Band Position (Where are we relative to volatility?)
|
||||
std_20 = df['Close'].shift(1).rolling(20).std()
|
||||
std_20 = df['Close'].rolling(20).std()
|
||||
upper_band = df['Moving_Average_20'] + (std_20 * 2)
|
||||
lower_band = df['Moving_Average_20'] - (std_20 * 2)
|
||||
df['BB_Pos'] = (df['Close'] - lower_band) / (upper_band - lower_band)
|
||||
|
||||
# Remove Unused Symbols to save ram
|
||||
df.drop('Moving_Average_5', axis=1, inplace=True)
|
||||
df.drop('Moving_Average_20', axis=1, inplace=True)
|
||||
|
||||
# Add feature for Returns
|
||||
df['Return'] = df['Close'].pct_change()
|
||||
# Log Returns (Better for AI than pct_change for statistical normality)
|
||||
@@ -65,10 +53,17 @@ def MakeFeatures(df):
|
||||
df[f'Vol_Lag_{lag}'] = df['Volume_Chg'].shift(lag)
|
||||
|
||||
# This is our training metric of price difference 5 days ahead
|
||||
df['Target_Close'] = np.log(df['Close'].shift(-5) / df['Close']) / df['Volatility_5']
|
||||
df['Target_Close'] = (np.log(df['Close'].shift(-5) / df['Close']) / df['Volatility_5']).clip(-10, 10)
|
||||
|
||||
# Remove Unused Symbols to save ram
|
||||
df.drop('Close', axis=1, inplace=True)
|
||||
# Save the overall trend to predict based off of later
|
||||
with open("Target_Close_Average.txt", "w") as file:
|
||||
file.write(str(df["Target_Close"].mean()))
|
||||
|
||||
# Drop every column that is a raw price or an unscaled average
|
||||
cols_to_drop = ['Open', 'High', 'Low', 'Volume', 'Close', 'Moving_Average_5', 'Moving_Average_20']
|
||||
for col in cols_to_drop:
|
||||
if col in df.columns:
|
||||
df.drop(col, axis=1, inplace=True)
|
||||
|
||||
# Drop rows with null values
|
||||
df.dropna(inplace=True)
|
||||
|
||||
Reference in New Issue
Block a user