4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

tensorflowで株価予測のつづき

Last updated at Posted at 2017-01-29

http://qiita.com/northriver/items/81b79e7e6785f2b89b95
でとりあえず、DNNに株価をぶち込んで予測させた。そこで、RNN/LSTMを使ったらというアドバイスをいただき、RNNでやってみたのを書きます。

outputをx%上がったかに戻し、
inferenceを以下に変えてやってみた。

def inference(input_ph, istate_ph):
     with tf.name_scope("inference") as scope:
        weight1_var = tf.Variable(tf.truncated_normal([num_of_input_nodes, num_of_hidden_nodes], stddev=0.1), name="weight1")
        weight2_var = tf.Variable(tf.truncated_normal([num_of_hidden_nodes, num_of_output_nodes], stddev=0.1), name="weight2")
        bias1_var   = tf.Variable(tf.truncated_normal([num_of_hidden_nodes], stddev=0.1), name="bias1")
        bias2_var   = tf.Variable(tf.truncated_normal([num_of_output_nodes], stddev=0.1), name="bias2")

        mean1, variance1 = tf.nn.moments(input_ph,[0])
        bn1 = tf.nn.batch_normalization(input_ph, mean1, variance1, None, None, 1e-5)

        in1 = tf.transpose(bn1, [1, 0, 2]) 
        in2 = tf.reshape(in1, [-1, num_of_input_nodes]) 
        in3 = tf.matmul(in2, weight1_var) + bias1_var
        in4 = tf.split(0, length_of_sequences, in3)   

        cell = rnn_cell.BasicLSTMCell(num_of_hidden_nodes, forget_bias=forget_bias)
        rnn_output, states_op = rnn.rnn(cell, in4, initial_state=istate_ph)
        output_op = tf.matmul(rnn_output[-1], weight2_var) + bias2_var
        
        return output_op, states_op

訓練データの正解率は5割をちょっと超えるぐらい。20%枠を作り、そこと同じ幅かどうかで見ています。
まあまあいいのかな?

で、2017/2/5までの120日間のデータを使って、1ヶ月後何%上がるかを3000銘柄すべてで予測させてた。高いのは以下みたい

名称未設定.png

(株への投資はご自身の責任で行いください。等記事は一切の責任を持ちません)

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?