split_date = datetime.datetime.strptime('2016-06-01', '%Y-%m-%d')
x_train = []
train_y = []
x_test = []
test_y = []
train_input = []
train_output = []
test_input = []
test_output = []
###############################
data_ = D.features(instruments, start_date='2008-01-01', end_date='2016-10-01',
fields=['fs_operating_revenue_yoy_0','amount_0',
'close_0','fs_deducted_profit_0','fs_net_profit_0','market_cap_float_0',
'fs_common_equity_0','fs_cash_equivalents_0','fs_account_receivable_0','fs_fixed_assets_0','fs_proj_matl_0',
'fs_construction_in_process_0','fs_fixed_assets_disp_0','fs_account_payable_0', 'fs_total_liability_0',
'fs_paicl_up_capital_0','fs_capital_reserves_0','fs_surplus_reserves_0', 'fs_undistributed_profit_0',
'fs_eqy_belongto_parcomsh_0',
'fs_total_equity_0','fs_gross_revenues_0', 'fs_total_operating_costs_0','fs_selling_expenses_0',
'fs_financial_expenses_0',
'fs_general_expenses_0', 'fs_operating_profit_0','fs_total_profit_0','fs_income_tax_0',
'fs_net_income_0', 'fs_cash_ratio_0','fs_non_current_liabilities_0','fs_current_liabilities_0',
'fs_non_current_assets_0',
'fs_current_assets_0','fs_net_cash_flow_0','fs_free_cash_flow_0','fs_operating_revenue_0'])
p_data = D.history_data(['000001.SHA'], '2013-09-01', '2016-10-01', ['close', 'amount','turn'])
p_data=p_data.sort_index(ascending=False)
p_data.dropna(inplace=True)
p_data.reset_index(drop=True, inplace=True)
data = D.history_data(instruments, '2013-09-01', '2016-10-01', ['close', 'amount','turn'])
#######################################################################################################################33
#################################3333
for i in range(len(instruments)):
instrument = instruments[i]
print(instrument )
mb=D.history_data(instrument, '2016-09-30', '2016-09-30',['industry_sw_level1'])
mdd=str(mb.industry_sw_level1[0])
Str='SW'+mdd+'.SHA'
h_data = D.history_data([Str], '2013-09-01', '2016-10-01', ['close', 'amount','turn'])
h_data=h_data.sort_index(ascending=False)
h_data.dropna(inplace=True)
h_data.reset_index(drop=True, inplace=True)
#print(h_data)
data1 = data[data.instrument==instrument]
data1=data1.sort_index(ascending=False)
data1.dropna(inplace=True)
data1.reset_index(drop=True, inplace=True)
data1['CLOSE']=p_data['close']
data1['AMOUNT']=p_data['amount']
data1['TURN']=p_data['turn']
data1['h_close']=h_data['close']
data1['h_amount']=h_data['amount']
data1['h_turn']=h_data['turn']
############################################################################################################3333
data0 = data_[data_.instrument==instrument]
data0=data0.fillna(value=0.0001)
data0=data0.sort_index(ascending=False)
data0.dropna(inplace=True)
data0.reset_index(drop=True, inplace=True)
#################################################################
x, y, z = no.train_data(data0,data1, future_len=60)
x_train =x_train + list(x[z<split_date])
train_y =train_y+ list(y[z<split_date])
#######################################################################
#print(np.array(x_train).shape)
#############################################################
x_test =x_test+ list(x[z>=split_date])
test_y = test_y+ list(y[z>=split_date])
x=[]
if (i+1) % 2== 0:
print(i)