GithubHelp home page GithubHelp logo

satnami / tensorflow-for-stock-prediction Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kimber-chen/tensorflow-for-stock-prediction

0.0 2.0 0.0 5.2 MB

Use Tensorflow to run CNN for predict stock movement. Hope to find out which pattern will follow the price rising.

Jupyter Notebook 71.89% Python 28.11%

tensorflow-for-stock-prediction's Introduction

Tensorflow work for stock prediction

Use Tensorflow to run CNN for predict stock movement. Hope to find out which pattern will follow the price rising. Different implement codes are in separate folder.

Feature include daily close price, MA, KD, RSI, yearAvgPrice..... Detail described as below. This work is just an sample to demo deep learning. The result is not well estimated.

All of the work are done by using the same stock(2330 in Taiwan stock) which are collected from yahoo.finance. Please notice that this stock perform a stable rise these years. But our result get a little better than just random guess.

For Brief tutorial slider please check (Distributed Tensorflow & Stock prediction)

For Chinese outline slider please check HERE(中文簡介)

##requirement

  • Tensorflow
  • yahoo_finance
  • numpy If you run DQN_KD_value, DQN_cnn_image you'll need extra
  • matplotlib
  • cv2

##1.DQN_CNN_image The major work of this project. We feed data(yearline,monthline, closePrice) as image and use CNN to recognize their pattern. Some resources really help a lot while building DQN. The main difference is how to set the reward function and way to train Q_network.

File:

  • DQN_draw_yearline.py :use for making yearline img and closeprice img, and then build model.
  • DQN_yearline_reward.py :to build model which should be train for about 24hr. //run DQN_draw_yearline.py first
  • Test model by yearline.ipynb : There is one model exsit in saved_year_r. The code create some img to test on that.
  • DQN_img_closePrice.py: build a model by closeprice img and do evaluation.

Performance

exp 1

  • Training: 2011~2014 15-day image with only daily close price.
  • Testing : 2016/01 ~2016/08
  • Trading strategy: Reward=(Tomorrow's close price)-(today's close price) if predict buy. Negate the number while predicting sell.
  • Bad performance.

alt tag

exp 2

  • Trading strategy: sell while meet +10% profit or -5% loss.
  • Baseline: Considering of the rising stock price, the baseline is the average profit takes buying times into account.
  • We get more profit then baseline. And the testing file can be used for evaluating whether to believe in the model.

alt tag

##2.CNN_tsc The model is originated from RobRomijnders 's work used for time series data (http://robromijnders.github.io/CNN_tsc/) I've change some parameter and use different indicators to find out when to buy the stock is good.

Performance

####Part 1. Indicators Feature MA can drop the loss compare with RSI and ClosePrice at training step.

alt tag ####Part 2. When To Buy With 10 days MA5 as an instance.

  • Training data (2330_train_15) : 2001~2014 2330.tw. Instance labeled as 1 when it rising dramatically up to 15% in 90 days. And mix with 4 times instance labeled as 0
  • Testing data (2330_test) : 2015/07 ~ 2016/08 MA5.

After running CNN_Classifier.ipynb, Result will be visualized.

alt tag

##3.DQN_MLP_closePrice

My implement is under close price. This could be change to other features like RSI,KD,MA....Or, use all of them. There is CNN code that could be edit to meet the requirement (size of batch).

Performance

Not work in closePrice. Better with other feature. ##4.DQN_KD_value Use KD value picture to predict.

python DQN_kd_pic.py //this call KD_draw.py and build model.

Performance

  • Training: 2011~2014 15-day K value and D value image
  • Testing : 2015/07 ~2016/07
    alt tag

tensorflow-for-stock-prediction's People

Contributors

kimber-chen avatar

Watchers

James Cloos avatar Mhd Sami Al Mouhtaseb avatar

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.