Skip to content

alessandrozamberletti/sp500-forecaster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sp500-forecaster

Predict if the next 30 days mean close price of a certain stock will be higher/lower than it was during the past 30 days.

margi

create.py: create+train+evaluate+save forecaster

algorithm details (click to expand)

  1. gather S&P500 OHLCV data and split into train/test
sp500forecaster [DEBUG]: collected 404 train, 101 test sp500 stocks
sp500forecaster [DEBUG]: building train time windows
  1. transform normalized OHLCV train data into visual time windows
  1. train CNN forecaster
  1. evaluate on test time windows


usage: create.py [-h] [-o OUTPUT] [-v] [-d] stocknum epochs

Create a model to predict future stock trends.

positional arguments:
  stocknum              number of sp500 stocks to retrieve (0=all)
  epochs                number of training epochs

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT,            path to output directory (default ./out)
  -v, --verbose         verbose output, default true
  -d, --debug           visual train info, default false

Pretrained weights:

weights backtest_oa stocknum epochs samples
n0_acc0.75_20180918231542.h5 0.79 0 (all) 10 ~259k train, ~65k val, ~85k test

predict.py: load h5 model weights and predict future prices

usage: predict.py [-h] [-o OUTPUT] [-v] weights symbols [symbols ...]

Predict future stock trends using a pretrained forecaster.

positional arguments:
  weights               path to h5 forecaster weights
  symbols               list of 1 or more iex-supported tickers

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        path to output directory (default ./out)
  -v, --verbose         verbose output, default true

Example:

$ python predict.py res/n0_acc0.75_20180918231542.h5 AAPL MMM
Using TensorFlow backend.
sp500forecaster [DEBUG]: symbols: ['AAPL', 'MMM']
sp500forecaster [DEBUG]: processing AAPL
sp500forecaster [DEBUG]: positive future prediction for symbol AAPL
sp500forecaster [DEBUG]: processing MMM
sp500forecaster [DEBUG]: positive future prediction for symbol MMM

Requirements

$ cat /etc/issue*
Ubuntu 16.04.4 LTS
$ python --version
Python 2.7.12
$ pip install -r requirements.txt
...