<jupyter_start><jupyter_text>This is my capstone project for the Udacity Machine Learning Nanodegree. Import the libraries needed.<jupyter_code>import pandas as pd
import numpy as np
import keras as kr
import tensorflow as tf
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
from os import listdir<jupyter_output>Using TensorFlow backend.<jupyter_text>Get the data. Since we already know the name of the specific stock we are trying to get from the name of the file, we can drop that column in the dataframe.<jupyter_code>directory = 'sandp500/individual_stocks_5yr'
dir_listing = listdir(directory)
symbols_list = []

for symbol in dir_listing:
    symb = symbol.split('_')[0]
    symbols_list.append(symb)
    
csv_file = '{}/{}_data.csv'.format(directory, symbols_list[0])
dataset = pd.read_csv(csv_file)<jupyter_output><empty_output><jupyter_text>Transform Data for suitable LSTM analysis<jupyter_code>dataset = dataset.assign(trading_date = pd.to_datetime(dataset['Date']))
dataset = dataset.drop('Name', 1)
dataset = dataset.drop('Date', 1)
dataset.set_index(['trading_date'], inplace=True)
dataset['NextDayClose'] = dataset['Close'].shift(-1)
dataset.head(10)
#below is the Daily Returns calculation to put into the Sharpe Ratio. 
df = dataset.assign(Daily_Returns = np.divide((dataset.Open - dataset.Close), dataset.Close) * 100)

#Below is the calculation for the Sharpe Ratio column. 
df = df.assign(Sharpe_Ratio = np.divide((df.Daily_Returns - 0.046), np.std(np.array([df.Open, df.High, df.Low, df.Close]))))

#Below is the rate of change (momentum) for the specific stock. 
df = df.assign(Rate_of_Change = (np.divide(df.Close, df.Open) - 1) * 100)

df = df.assign(Difference_of_Close = df['Close'].diff())

df.head(10)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11093418259023355, 'fraction_numerical': 0.012738853503184714, 'mean_word_length': 5.955719557195572, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '347425', 'license': 'OML', 'n_tokens_mistral': 642, 'n_tokens_neox': 607, 'n_words': 173, 'path': 'UdacityMachineLearningNanodegreeCapstoneProject-Copy3.ipynb', 'repo_name': 'kwrjcr/machinelearningnanodegreecapstone', 'size': '1884'}