camel2012 / StockformerEric

This paper, StockFormer: A Swing Trading Strategy Based on STL Decomposition and Self-Attention Networks, is currently under consideration for publication in the [Neurocomputing](https://www.sciencedirect.com/journal/neurocomputing).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StockFormer Data File Explanation and Execution Method

Overview of "StockFormer" Code

This is the code accompanying the paper titled "StockFormer: A Swing Trading Strategy Based on STL Decomposition and Self-Attention Networks," which is currently under consideration for publication in the International Journal of Forecasting. The preprint of this paper is available on SSRN. The code provides a comprehensive framework for implementing the StockFormer model, including data preparation, model training, and backtesting. You can access the preprint at: SSRN Preprint.

Original Data

Due to the large size of the original data, the author has stored it on a cloud drive for readers to use. The link to the original data is as follows: raw_data

File Description

  • data_cleaned.ipynb: Data cleaning for raw data.

  • Stockformermodel

    • The neural network architecture of Stockformer.
  • data/STOCK

    • corr_adj.npy: The correlation matrix for input data (used for generating high-dimensional vector expressions with Struc2vec; see struc2vec for the generation method).
    • corr_struc2vec_adjgat.npy: High-dimensional vectors generated by Struc2vec, ready for direct network input.
    • flow.npz: The processed real input data.
  • log/STOCK

    • logV4: Log files output by the neural network.
  • lib

    • smallStockutils.py: Preprocessing for Stockformer input data and establishment of evaluation metrics.
  • output: Folder for output result files.

  • config: Configuration files for the network.

  • cpt/STOCK

    • saved_modelV4_2: Saved trained neural network models.
  • Stockformer_train.py: The model training file.

  • backtest

    • my_us_backtest.ipynb: Code used for backtesting stock returns.
    • us_data_21-23: The dataset constructed for backtesting based on qlib.
    • baseline: The state-of-the-art (SOTA) used for comparison with the models in this study.

How to Run

Execute the following command in the terminal to run the model:

python Stockformer_train.py --config STOCKV4.conf

How to Cite

To cite the "StockFormer" paper and code in your research or publications, please use the following formats:

APA Style: Ma, B., Wang, Y., Lu, Y., Hu, T., Xu, J., & Houlihan, P. (Year). StockFormer: A Swing Trading Strategy Based on STL Decomposition and Self-Attention Networks. SSRN Electronic Journal. Advance online publication. https://doi.org/10.2139/ssrn.4648073

MLA Style: Ma, Bohan, et al. "StockFormer: A Swing Trading Strategy Based on STL Decomposition and Self-Attention Networks." SSRN Electronic Journal, SSRN Scholarly Paper ID 4648073, Social Science Research Network, Year, https://doi.org/10.2139/ssrn.4648073.

Chicago Style: Ma, Bohan, Wang Yiheng, Lu Yuchao, Hu Tianzixuan, Xu Jinling, and Houlihan Patrick. "StockFormer: A Swing Trading Strategy Based on STL Decomposition and Self-Attention Networks." SSRN Electronic Journal. Year. https://doi.org/10.2139/ssrn.4648073.

Replace "Year" with the year of publication once it becomes available. If the paper is part of a specific issue or volume, include those details as well.

About

This paper, StockFormer: A Swing Trading Strategy Based on STL Decomposition and Self-Attention Networks, is currently under consideration for publication in the [Neurocomputing](https://www.sciencedirect.com/journal/neurocomputing).


Languages

Language:Jupyter Notebook 51.0%Language:Python 49.0%