Git Product home page Git Product logo

stocks_rnn's Introduction

Stock Price Prediction using LSTM

Downloads adjusted daily returns of a configurable date range and set of stocks from Yahoo Finance, concatenates them all into a long sequence, and trains an LSTM to predict future returns based on the sequence of past returns.

Specifics

  • Implemented in TensorFlow, adapted from Google's PTB RNN prediction example
  • Returns are normalized using standard deviation (lookback configurable). Positive drift should be negligible.
  • Train / validation / test sets are organized in chronological order.

Dependencies

  • TensorFlow
  • pandas_datareader
  • numpy

Does it work?

Not really, current results aren't much better than chance. The data might be too noisy for this method, or there might be something wrong in the code or model.

stocks_rnn's People

Contributors

tencia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stocks_rnn's Issues

ImportError: This module is deprecated. Use tf.nn.rnn_* instead.

Can anyone provide a new version code?

(tensorflow) dhcp-v097-009:stocks_rnn-master Gene$ python train_stock_lstm.py
Traceback (most recent call last):
File "train_stock_lstm.py", line 13, in
from tensorflow.models.rnn import rnn
File "/Users/Gene/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/models/rnn/rnn.py", line 21, in
raise ImportError("This module is deprecated. Use tf.nn.rnn_* instead.")
ImportError: This module is deprecated. Use tf.nn.rnn_* instead.

new

My name is Luis, I'm a big-data machine-learning developer, I'm a fan of your work, and I usually check your updates.

I was afraid that my savings would be eaten by inflation. I have created a powerful tool that based on past technical patterns (volatility, moving averages, statistics, trends, candlesticks, support and resistance, stock index indicators).
All the ones you know (RSI, MACD, STOCH, Bolinger Bands, SMA, DEMARK, Japanese candlesticks, ichimoku, fibonacci, williansR, balance of power, murrey math, etc) and more than 200 others.

The tool creates prediction models of correct trading points (buy signal and sell signal, every stock is good traded in time and direction).
For this I have used big data tools like pandas python, stock market libraries like: tablib, TAcharts ,pandas_ta... For data collection and calculation.
And powerful machine-learning libraries such as: Sklearn.RandomForest , Sklearn.GradientBoosting, XGBoost, Google TensorFlow and Google TensorFlow LSTM.

With the models trained with the selection of the best technical indicators, the tool is able to predict trading points (where to buy, where to sell) and send real-time alerts to Telegram or Mail. The points are calculated based on the learning of the correct trading points of the last 2 years (including the change to bear market after the rate hike).

I think it could be useful to you, to improve, I would like to share it with you, and if you are interested in improving and collaborating I am also willing, and if not file it in the box.

If tou want, Please read the readme , and in case of any problem you can contact me ,
If you are convinced try to install it with the documentation.
https://github.com/Leci37/LecTrade/tree/develop I appreciate the feedback

How to provide input of [x,x**2]?

Hi,

I am learning tensorflow and your example of stock prediction seems very interesting. I wonder, if you could guide in extending this example to provide vector of inputs. I made the following changes, but get error in matmul step.

I tried to change the code to input [x,x^2] instead of x, with following two lines of changes. But I get error.

in STOCKLSTM: self._input_data = tf.placeholder(tf.float32, [2, batch_size, num_steps])

In main/Epoch cost, state, _ = session.run([m.cost, m.final_state, eval_op], {m.input_data: (x,x**2), m.targets: y, m.initial_state: state})

ERROR:
ValueError: Cannot feed value of shape (2, 30, 10) for Tensor u'model/Placeholder:0', which has shape '(30, 10)'

Best,

rnn.rnn is removed since Tensorflow 1.0, the demo doesn't work on it.

After a little modification to the source code as to adapt to the Tensorflow 1.0, I found the following error:

ValueError: Attempt to reuse RNNCell <tensorflow.contrib.rnn.python.ops.core_rnn_cell_impl.BasicLSTMCell object at 0x1170bb710> with a different variable scope than its first use. First use of cell was with scope 'model/rnn/multi_rnn_cell/cell_0/basic_lstm_cell', this attempt is with scope 'model/rnn/multi_rnn_cell/cell_1/basic_lstm_cell'. Please create a new instance of the cell if you would like it to use a different set of weights. If before you were using: MultiRNNCell([BasicLSTMCell(...)] * num_layers), change to: MultiRNNCell([BasicLSTMCell(...) for _ in range(num_layers)]). If before you were using the same cell instance as both the forward and reverse cell of a bidirectional RNN, simply create two instances (one for forward, one for reverse). In May 2017, we will start transitioning this cell's behavior to use existing stored weights, if any, when it is called with scope=None (which can lead to silent model degradation, so this error will remain until then.)

And yet I have no idea how to fix it, hope anyone would hint me a little.
Below is my modification to the source.

    from tensorflow.contrib import rnn

    lstm_cell = rnn.BasicLSTMCell(hidden_size, forget_bias=0.0, state_is_tuple=True)
    
    if is_training and config.keep_prob < 1:
        lstm_cell = rnn.DropoutWrapper(lstm_cell, output_keep_prob=config.keep_prob)
    cell = rnn.MultiRNNCell([lstm_cell for _ in range(config.num_layers)], state_is_tuple=True)

    self._initial_state = cell.zero_state(batch_size, tf.float32)

    iw = tf.get_variable("input_w", [1, hidden_size])
    ib = tf.get_variable("input_b", [hidden_size])
    inputs = [tf.nn.xw_plus_b(i_, iw, ib) for i_ in tf.split(self._input_data, num_steps, 1)]

    if is_training and config.keep_prob < 1:
        inputs = [tf.nn.dropout(input_, config.keep_prob) for input_ in inputs]
    
    outputs, states = rnn.static_rnn(cell, inputs, initial_state=self._initial_state)

m.initial_state.eval()

state = m.initial_state.eval()
AttributeError: 'tuple' object has no attribute 'eval'

when the code runs here, it got the error as above, can't understand what does the author want to do here.
m.initial_state returns a tuple

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.