bgithub1 / da_rnn

RNN based on Chandler Zuo's implementation of the paper: A Dual-Stage Attention-Based Recurrent Neural Network for Time Series Prediction
18 stars 1 forks source link

da_rnn_fromcsv (see below if the ipynb notebooks do not render in github)_

(Only tested with python 3.5 and above)


This version of da_rnn is derived from Chandler Zuo's implementation of the paper:
A Dual-Stage Attention-Based Recurrent Neural Network for Time Series Prediction
which he details in his blog post
A PyTorch Example to Use RNN for Financial Prediction

My implementation does the following:


Use of da_rnn_from_csv.ipynb:


To use the da_rnn_from_csv.ipynb notebook, run all of the notebook's cells.
In section 4.0, you can change the data from nasdaq100 component data to uso 1-minute time bars.

The cell with the if __name__=='__main___ code (in section 4.0) will launch:


Data:

The folder data contains several csv files:

You can train the model using any of these csv files, or any other csv whose columns conform to those examples. Other time series csv files should only contain numeric columns. One of those numeric columns should be used as the label/y-value for the x-values of the preceeding row.


Structure of the csv/DataFrame:

The data in the csv/DataFrame can contain rows like:

  1. the returns data for the components of an index like NDX (as in Chandler Zuo's version) as in the csv file ./data/nasdaq100_padding.csv, or
  2. intra-day bar data with columns like year, month, day, hour, minute open, high, low, close, as in the csv file ./data/uso_full.csv

The main() method in section 3.0

The actual model training takes place in the main() method in the cell below heading 3.01, with the code:

    logger = setup_log()
    m = da_rnn(df_partial, logger = logger, parallel = False, learning_rate = .001)
    m.execute_training(n_epochs=100)

Using pdb

To use the pdb debuger, add pdb.set_trace() statements to the code.
See this cheatsheet for a quick reference to pdb commands

If you cannot view the ipynb notebooks in this project, see:

  1. https://nbviewer.jupyter.org/github/bgithub1/da_rnn/blob/master/da_rnn_from_csv.ipynb
  2. https://nbviewer.jupyter.org/github/bgithub1/da_rnn/blob/master/sine_curve_test.ipynb