Last active
August 8, 2017 02:55
-
-
Save karishmadudani/5de24a9d2fd46eab2a255f35427ecb0b to your computer and use it in GitHub Desktop.
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
#Calculate moving averages and normalize the below variables and add to the dataset 'df' | |
VolumeMA = df['Volume'].rolling(window=50).mean() | |
AdjClosedMA_50 = df['Adj. Close'].rolling(window=50).mean() | |
AdjClosedMA_200 = df['Adj. Close'].rolling(window=200).mean() | |
df['VolumeN']= ((df['Volume']-VolumeMA)/VolumeMA)*100 | |
df['AdjClosedN_50'] = ((df['Adj. Close']- AdjClosedMA_50)/AdjClosedMA_50)*100 | |
df['AdjClosedN_200'] = ((df['Adj. Close']- AdjClosedMA_200)/AdjClosedMA_200)*100 | |
#Converting numDays and minProfit to string for the purpose of exporting to csv files | |
numDaysF = float(numDays) | |
minProfitF = float(minProfit) | |
numDaysStr = "{:.0f}".format(numDaysF) | |
minProfitStr = "{:.0f}".format(minProfitF) | |
#Drop the irrelevant columns and NaN rows | |
df = df.drop(['Open','High','Low','Close','Volume'],axis = 1) | |
df = df[199:] | |
df = df[:(len(df)-40)] | |
#Export the above dataset | |
df.to_csv("C:\Users\lenovo\Desktop\Karishma\Stocks\Scripts\Datasets\\"+Tickers.iloc[n]["Symbol"]+numDaysStr+minProfitStr+".csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment