def test_ohlc_add_all_feature(self): data = pd.read_csv('d:/stock/new-data/SH600741.TXT', sep='\t') ohlc = OHLCVD(data.values) ohlc.add_all_ta_feature() data = ohlc.get_dataframe() result = data.replace(np.nan, -1.0).replace(np.inf, -2.0).replace(-np.inf, -3.0) sql_line = '''insert into stock_with_feature values('sh600741', '%s', %s )'''%(result.values[1, 0], ','.join([str(x) for x in result.values[1, 1:]]), ) print sql_line db = MySQLUtils('root', '1988', 'stock', 'stock_with_feature') db.execute_sql(sql_line) self.assertEqual(ohlc.data.shape[1], 149)
def test_ohlc_add_all_feature(self): data = pd.read_csv('d:/stock/new-data/SH600741.TXT', sep='\t') ohlc = OHLCVD(data.values) ohlc.add_all_ta_feature() data = ohlc.get_dataframe() result = data.replace(np.nan, -1.0).replace(np.inf, -2.0).replace(-np.inf, -3.0) sql_line = '''insert into stock_with_feature values('sh600741', '%s', %s )''' % ( result.values[1, 0], ','.join([str(x) for x in result.values[1, 1:]]), ) print sql_line db = MySQLUtils('root', '1988', 'stock', 'stock_with_feature') db.execute_sql(sql_line) self.assertEqual(ohlc.data.shape[1], 149)
raise_rate = (second_day-first_day)/first_day*100 result = pd.DataFrame(data=raise_rate, index=data_frame.date.values[1:]) return result def window_similarity(data_frame, frame_len=20, frame_move=10): result = [] value = data_frame.values for i in range(0, value.shape[0]-frame_len, frame_move): tmp_value = value[i:i+frame_len, :] cor_value = correlation(tmp_value[:, 0], tmp_value[:, 1]) result.append(cor_value) return result db = MySQLUtils('root', '1988', 'test', 'stock') stock_lists = db.execute_sql("SELECT DISTINCT ID FROM STOCK") stock_lists = [x[0] for x in stock_lists] def iter_over_stocks(stock_lists, db): final_result = {} for x in stock_lists: for y in stock_lists: data1 = db.select_data(stock_lists[0], begin='2010-01-01', end='2015-12-30') data_frame = db.get_dataframe('sh600741', begin='2010-01-01', end='2015-12-30') data_frame = data_frame.set_index(data_frame.date) data_frame1 = db.get_dataframe('sh601668', begin='2010-01-01', end='2015-12-30') data_frame1 = data_frame1.set_index(data_frame1.date.values)
result = pd.DataFrame(data=raise_rate, index=data_frame.date.values[1:]) return result def window_similarity(data_frame, frame_len=20, frame_move=10): result = [] value = data_frame.values for i in range(0, value.shape[0] - frame_len, frame_move): tmp_value = value[i:i + frame_len, :] cor_value = correlation(tmp_value[:, 0], tmp_value[:, 1]) result.append(cor_value) return result db = MySQLUtils('root', '1988', 'test', 'stock') stock_lists = db.execute_sql("SELECT DISTINCT ID FROM STOCK") stock_lists = [x[0] for x in stock_lists] def iter_over_stocks(stock_lists, db): final_result = {} for x in stock_lists: for y in stock_lists: data1 = db.select_data(stock_lists[0], begin='2010-01-01', end='2015-12-30') data_frame = db.get_dataframe('sh600741', begin='2010-01-01', end='2015-12-30') data_frame = data_frame.set_index(data_frame.date)