Created
August 27, 2018 09:39
-
-
Save sam-thecoder/812712a2f205a8a983da24deab133e57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_drop(numbers): | |
return len([x for x in numbers if x < 0]) | |
def count_up(numbers): | |
return len([x for x in numbers if x > 0]) | |
def actual_calc(row): | |
if row['Value'] > row['Open 2']: | |
return 0 | |
return 1 | |
def decider(row): | |
if row['Drop 7'] < row['Up 7'] and row['Mean Change 7'] > 0 and row['Change'] >= 0: | |
return 1 | |
elif row['Drop 7'] > row['Up 7'] and row['Mean Change 7'] < 0 and row['Change'] >= 0: | |
return 0 | |
elif row['Drop 7'] < row['Up 7'] and row['Mean Change 7'] > 0 or row['Change'] >= 0: | |
return -1 | |
elif row['Drop 7'] < row['Up 7'] and row['Mean Change 7'] < 0 or row['Change'] < 0: | |
return -2 | |
elif row['Drop 7'] < row['Up 7'] and row['Mean Change 7'] > 0 and row['Change'] < 0: | |
return -3 | |
elif row['Drop 7'] > row['Up 7'] and row['Mean Change 7'] < 0 and row['Change'] < 0: | |
return -4 | |
def prediction(value): | |
if value > 0: | |
return 1 | |
return 0 | |
df['Open 2'] = df['Value'].shift(-1) | |
df['Max 7'] = df['Value'].rolling(7).max() | |
df['Min 7'] = df['Value'].rolling(7).min() | |
df['Change'] = df['Value'] - df['Open 2'] | |
df['Mean Change 7'] = df['Change'].rolling(7).mean() | |
df['Drop 7'] = df['Change'].rolling(7).apply(count_drop) | |
df['Up 7'] = df['Change'].rolling(7).apply(count_up) | |
df['Predict'] = df.apply(decider, axis=1) | |
df['Prediction'] = df['Predict'].apply(prediction) | |
df['Actual'] = df.apply(actual_calc, axis=1) | |
df.head(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment