示例#1
0
    def get_predicts(self, comp_code, tp):
        learning = Learning(self.params)
        investX = tp.data_params.investX
        #print(investX)

        graph_params = learning.get_train_model()
        X = graph_params.X
        Y_pred = graph_params.Y_pred
        training = graph_params.training
        output_keep_prob = graph_params.output_keep_prob

        saver = tf.train.Saver()
        session_path = learning.get_session_path(comp_code)

        with tf.Session() as sess:
            sess.run(tf.global_variables_initializer())
            saver.restore(sess, session_path)

            invest_predicts = None
            if len(investX) > 0:
                invest_predicts = sess.run(Y_pred,
                                           feed_dict={
                                               X: investX,
                                               output_keep_prob: 1.0,
                                               training: False
                                           })
            last_predict = sess.run(Y_pred,
                                    feed_dict={
                                        X: tp.dataX_last,
                                        output_keep_prob: 1.0,
                                        training: False
                                    })
        return invest_predicts, last_predict[0]
示例#2
0
 def restore(self) -> bool:
     learning = Learning(self._params)
     if learning.exist_learning_image(self._corp_code, True, self._name):
         saver = tf.train.Saver()
         saved_session_path = learning.get_session_path(
             self._corp_code, True, self._name)
         saver.restore(self.sess, saved_session_path)
         return True
     return False
    def let_invest(self, comp_code, dataX_last, data_params):
        """학습 후 모의 주식 거래를 한다."""
        stacked_rnn = StackedRnn(self.params)
        learning = Learning(self.params)
        invest_count = self.params.invest_count
        invest_money = self.params.invest_money
        investCloses = data_params['investCloses']
        investRealCloses = data_params['investRealCloses']
        investX = data_params['investX']

        graph_params = stacked_rnn.get_stacted_rnn_model()
        X = graph_params['X']
        Y_pred = graph_params['Y_pred']
        output_keep_prob = graph_params['output_keep_prob']
        session_file_path = learning.get_session_path(comp_code)
        now_stock_cnt = 0
        all_invest_money = invest_money
        all_stock_count = now_stock_cnt
        predicts = []
        now_close = 0
        saver = tf.train.Saver()

        with tf.Session() as sess:
            init = tf.global_variables_initializer()
            sess.run(init)
            saver.restore(sess, session_file_path)

            for i in range(invest_count):
                invest_predicts = sess.run(Y_pred,
                                           feed_dict={
                                               X: investX[i:i + 1],
                                               output_keep_prob: 1.0
                                           })
                predicts.append(invest_predicts[0])

                invest_predict = invest_predicts[0][0]
                now_scaled_close = investCloses[i][0]
                now_close = investRealCloses[i]
                #print(invest_predict, now_scaled_close, now_close)
                invest_money, now_stock_cnt = self.let_invest_money(
                    invest_predict, now_scaled_close, now_close, invest_money,
                    now_stock_cnt)
                if i == 0:
                    all_invest_money, all_stock_count = self.let_invest_money(
                        10.0, now_scaled_close, now_close, all_invest_money,
                        all_stock_count)

            invest_money += self.to_money(now_stock_cnt, now_close)
            all_invest_money += self.to_money(all_stock_count, now_close)

            last_predict = sess.run(Y_pred,
                                    feed_dict={
                                        X: dataX_last,
                                        output_keep_prob: 1.0
                                    })
        # print(now_money)
        return invest_money, last_predict, predicts, all_invest_money
    def _get_predict(self, params, comp_code, investX):
        stacked_rnn = StackedRnn(params)
        graph_params = stacked_rnn.get_stacted_rnn_model()
        Y_pred = graph_params['Y_pred']
        output_keep_prob = graph_params['output_keep_prob']
        X = graph_params['X']
        learning = Learning(params)
        file_path = learning.get_session_path(comp_code)

        saver = tf.train.Saver()
        with tf.Session() as sess:
            init = tf.global_variables_initializer()
            sess.run(init)
            saver.restore(sess, file_path)
            last_predict = sess.run(Y_pred,
                                    feed_dict={
                                        X: investX,
                                        output_keep_prob: 1.0
                                    })
        return last_predict