original_docstring: 
      The main method to create the database
      :return: dataframe of features and labels
      
docstring: The main method to create the database
docstring_tokens: The main method to create the database
code: def build():
      """
      The main method to create the database
      :return: dataframe of features and labels
      """
      rootdir = '/Users/Hossein/Downloads/NYSE_2018/'
      query = pd.DataFrame()
      for subdir, dirs, files in os.walk(rootdir):
          for file in files:
              query = query.append(pd.read_csv(subdir + file))
      query = query.rename(columns={'<close>': 'Price', '<ticker>': 'Ticker'})
      query['Time'] = query['<date>'].apply(lambda x: datetime.datetime.strptime(str(x), '%Y%m%d'))
      dataset = query.set_index('Time')
      dataset = dataset[dataset['<vol>'] > 0]
      dataset['dummyindex'] = dataset.index
      dataset = dataset.sort_values(['Ticker', 'dummyindex'])
      dataset['Change'] = dataset['Price'].diff() / dataset['Price'].shift()
      dataset = dataset[abs(dataset['Change']) < .05]
      dataset['Label'] = dataset['Change'].apply(lambda x: 1 if x > .01 else 0)
      data = dataset.groupby('Ticker').max()['Price']
      dataset = dataset.merge(pd.DataFrame(data=data), left_on='Ticker', right_index=True)
      dataset['scaled'] = dataset.Price_x / dataset.Price_y
      dataset.drop(['<date>', '<high>', '<low>', '<open>', 'dummyindex', 'Price_x', 'Price_y'], inplace=True, axis=1)
      dataset['SMA60'] = dataset['scaled'].rolling(window=60, min_periods=0, center=False).mean()
      dataset['STD'] = dataset['scaled'].rolling(window=60, min_periods=0, center=False).std()
      dataset = dataset[dataset.STD > 0]
      dataset['N'] = (dataset['scaled'] - dataset['SMA60']) / dataset['STD']
      dataset['RSI'] = relative_strength_index(dataset, period=14, field='scaled')
      dataset['MACD'] = macd(dataset, 'scaled')
      dataset['Date'] = dataset.index.date
      dataset['Day'] = dataset['Date'].apply(lambda x: x.day)
      dataset['Month'] = dataset['Date'].apply(lambda x: x.month)
      dataset['Year'] = dataset['Date'].apply(lambda x: x.year)
      dataset = dataset.dropna()
  
      ticker_dummy = pd.get_dummies(dataset['Ticker'], prefix='ticker')
      data = dataset.join(ticker_dummy)
      le = preprocessing.LabelEncoder()
      le.fit(dataset['Ticker'].values)
      feature_list = ['N', 'RSI', 'MACD', 'Day', 'SMA60'] + ['ticker_' + i for i in le.classes_]
      data = data[feature_list + ['Label']]
  
      X_train, X_test, y_train, y_test = train_test_split(X, dataset[y], test_size=0.3, random_state=2)
      logreg = LogisticRegression()
      logreg.fit(X_train, y_train)
      y_pred = logreg.predict(X_test)
      print('Accuracy of logistic regression classifier on test set: {0}%'.format(logreg.score(X_test, y_test) * 100))
      from sklearn.metrics import confusion_matrix
      confusion_matrix = confusion_matrix(y_test, y_pred)
      print(confusion_matrix)
code_tokens: def build ( ) : rootdir = '/Users/Hossein/Downloads/NYSE_2018/' query = pd . DataFrame ( ) for subdir , dirs , files in os . walk ( rootdir ) : for file in files : query = query . append ( pd . read_csv ( subdir + file ) ) query = query . rename ( columns = { '<close>' : 'Price' , '<ticker>' : 'Ticker' } ) query [ 'Time' ] = query [ '<date>' ] . apply ( lambda x : datetime . datetime . strptime ( str ( x ) , '%Y%m%d' ) ) dataset = query . set_index ( 'Time' ) dataset = dataset [ dataset [ '<vol>' ] > 0 ] dataset [ 'dummyindex' ] = dataset . index dataset = dataset . sort_values ( [ 'Ticker' , 'dummyindex' ] ) dataset [ 'Change' ] = dataset [ 'Price' ] . diff ( ) / dataset [ 'Price' ] . shift ( ) dataset = dataset [ abs ( dataset [ 'Change' ] ) < .05 ] dataset [ 'Label' ] = dataset [ 'Change' ] . apply ( lambda x : 1 if x > .01 else 0 ) data = dataset . groupby ( 'Ticker' ) . max ( ) [ 'Price' ] dataset = dataset . merge ( pd . DataFrame ( data = data ) , left_on = 'Ticker' , right_index = True ) dataset [ 'scaled' ] = dataset . Price_x / dataset . Price_y dataset . drop ( [ '<date>' , '<high>' , '<low>' , '<open>' , 'dummyindex' , 'Price_x' , 'Price_y' ] , inplace = True , axis = 1 ) dataset [ 'SMA60' ] = dataset [ 'scaled' ] . rolling ( window = 60 , min_periods = 0 , center = False ) . mean ( ) dataset [ 'STD' ] = dataset [ 'scaled' ] . rolling ( window = 60 , min_periods = 0 , center = False ) . std ( ) dataset = dataset [ dataset . STD > 0 ] dataset [ 'N' ] = ( dataset [ 'scaled' ] - dataset [ 'SMA60' ] ) / dataset [ 'STD' ] dataset [ 'RSI' ] = relative_strength_index ( dataset , period = 14 , field = 'scaled' ) dataset [ 'MACD' ] = macd ( dataset , 'scaled' ) dataset [ 'Date' ] = dataset . index . date dataset [ 'Day' ] = dataset [ 'Date' ] . apply ( lambda x : x . day ) dataset [ 'Month' ] = dataset [ 'Date' ] . apply ( lambda x : x . month ) dataset [ 'Year' ] = dataset [ 'Date' ] . apply ( lambda x : x . year ) dataset = dataset . dropna ( ) ticker_dummy = pd . get_dummies ( dataset [ 'Ticker' ] , prefix = 'ticker' ) data = dataset . join ( ticker_dummy ) le = preprocessing . LabelEncoder ( ) le . fit ( dataset [ 'Ticker' ] . values ) feature_list = [ 'N' , 'RSI' , 'MACD' , 'Day' , 'SMA60' ] + [ 'ticker_' + i for i in le . classes_ ] data = data [ feature_list + [ 'Label' ] ] X_train , X_test , y_train , y_test = train_test_split ( X , dataset [ y ] , test_size = 0.3 , random_state = 2 ) logreg = LogisticRegression ( ) logreg . fit ( X_train , y_train ) y_pred = logreg . predict ( X_test ) print ( 'Accuracy of logistic regression classifier on test set: {0}%' . format ( logreg . score ( X_test , y_test ) * 100 ) ) from sklearn . metrics import confusion_matrix confusion_matrix = confusion_matrix ( y_test , y_pred ) print ( confusion_matrix )
short_docstring: The main method to create the database
short_docstring_tokens: The main method to create the database
comment: """
      The main method to create the database
      :return: dataframe of features and labels
      """