Git Product home page Git Product logo

lstm-initstates's Introduction

Modeling Financial Time Series using LSTM with Trainable Initial Hidden States

Architecture

This is the PyTorch implementation of "Modeling Financial Time Series using LSTM with Trainable Initial Hidden States" [arXiv].

Quick How-to

Requirements

This code was tested on an Ubuntu 18.04 system using PyTorch 1.5. See requirements.txt for the packages used in our conda environment (you probably won't need all of them, though).

Training a New Model

This repository contains the code and the dataset required for training. You can train a model using:

python lstm-initStates.py train

When the training completes, it saves the model parameters as model_best.tar in result directory.

Check the Training Results

After training, you can get the model's initial hidden states and output using:

python lstm-initStates.py eval

It saves the results in result directory:

  • initial hidden states: initStates_from_best.txt. It has N x M values where N is the number of sequences in the dataset and M is the number of initial hidden states (= number of LSTM cells).
  • model's output: predict_idxSeq_%d.txt/png for. This is the stock price change relative to the price of the first day (2019-01-01).

For convenience, the trained model is provided with the code (model_best.tar in result directory).

Data

The stock prices of the companies listed in Korea Composite Stock Price Index (KOSPI) from Jan 1st to Dec 31st, 2019 were used. The moving average filter with the window length of five days were applied to the adjusted closing price and some stocks with missing values were excluded. As a result, a total number of 735 stocks were used in our dataset. See kospi_listed_inKorean.csv for reference (in Korean).

In data directory, there are 3 directories:

  • 2019-01-01_2019-03-31: the 'short' dataset for comparison
  • 2019-01-01_2019-06-30: the 'long' dataset for comparison
  • 2019-01-01_2019-12-31: the dataset used in our main experiment

In each directory, stock prices are stored as a separate file for each company. See myDataloader.py for details on reading those files.

Architecture

Architecture

In this model, the initial (t=0) hidden states of LSTM h0are trained separately for each sequence. The model can reconstruct different sequences from the different initial hidden states without any external input. Consequently, the initial hidden states play a key role in capturing differences between the time series data. For details on the model and data, please see "Modeling Financial Time Series using LSTM with Trainable Initial Hidden States".

Citation

If you find this code useful, please consider citing our work:

@inproceedings{hwang2020modeling,
Author = {Hwang, Jungsik},
Title = {Modeling Financial Time Series using LSTM with Trainable Initial Hidden States},
Booktitle  = {arXiv preprint arXiv:2007.06848},
Year = {2020}
}

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.