Last active
July 12, 2020 04:55
-
-
Save cameronShadmehry/27f6b8bcc489e2b1f349f9f0cd686e29 to your computer and use it in GitHub Desktop.
Rank the saved stocks
This file contains 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
Compare_Stocks = pd.read_csv("<Your Path>\\SMA_Analysis\\All_Stocks.csv") # Read in the All_Stocks data to a dataframe | |
# Delete companies that don't have enough crosses observed. I am using 50 crosses as my cuttoff: | |
Not_Enough_Records = [] | |
Row = 0 | |
while Row < (len(Compare_Stocks)): | |
if Compare_Stocks.iloc[Row, 2] < 50: | |
Not_Enough_Records.append(Row) | |
Row += 1 | |
Compare_Stocks = Compare_Stocks.drop(Not_Enough_Records) # Remove records that do not have enough crosses for us to observe | |
Avg_Accuracy = [] # List to hold the accuracy of each stock | |
i=0 | |
while i < (len(Compare_Stocks)): | |
Avg_Accuracy.append(Compare_Stocks.iloc[i,9]) | |
i += 1 | |
# Create a dataframe from Compare_Stocks | |
df = Compare_Stocks[['Company','Days_Observed', 'Crosses', 'True_Positive', 'False_Positive', 'True_Negative', 'False_Negative', 'Sensitivity', 'Specificity', 'TPR', 'FPR', 'Accuracy']] | |
df["Companies_Ranked"] = df["Accuracy"].rank(ascending = False) # Rank the stocks by their Accuracy | |
df.sort_values("Accuracy", inplace = True, ascending = False) # Sort the ranked stocks | |
df.to_csv("<Your Path>\\SMA_Analysis\\5_Day_Avg_26_12_MACD.csv", index = False) # Save the dataframe to a csv | |
# We now have a list of stocks ranked by how well the MACD indicator predicts their price change. | |
print("The average accuracy of all stocks observed: " + str(mean(Avg_Accuracy))) # The overall accuracy of the MACD. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment