Title: LSTMs in Predicting Financial Time Series Data
Who: Beenish Valliani (bvallian), Connie Ortiz (ceortiz), Isaac Calderon (iacalder), Kevin Zhu (ktzhu), Oliver Tu (ostu)
Introduction: We are seeking to build a trading system that provides recommendations as to whether one should buy or sell a particular stock or index (i.e. binary classification task). The model can be leveraged to construct a portfolio that ideally, results in consistent positive returns. We are implementing a variation of the architecture specified in the paper "Long Short-Term Memory Neural Network for Financial Time Series" (link: https://arxiv.org/pdf/2201.08218.pdf). The objective of the paper is to apply the model to data provided by the OMX Stockholm 30 index to "explore what advantages an LSTM-based approach can provide for a smaller, less perfect market" (Fjellström 2). We chose this paper because it provides a manageable baseline framework that (1) appears reasonable to implement given the computing power available to us and (2) can be leveraged to produce a more complex architecture and consequently, more accurate predictions.
Related Work: (1) Deep learning with long short-term memory networks for financial market predictions.
- Link: https://www.sciencedirect.com/science/article/pii/S0377221717310652
- Summary: By benchmarking against 3 memory free memory-classification methods, Fischer and Krauss demonstrate the effectiveness of an LSTM model for creating a profit margin off of pre-2010 S&P 500 trading. They also dive into the methods for deriving model interpretability and finding portfolio-stock characteristics and patterns.
(2) Predicting Short-Term Stock Movements with Quantitative Finance and Machine Learning in Python
- Link: https://towardsdatascience.com/predicting-short-term-stock-movements-with-quantitative-finance-and-machine-learning-in-python-e6e04e3e0337
- NOTE: This is a blog post that is not deep learning-specific, but it has a code base that may be helpful to refer to.
Data: We'll likely use S&P 500 data or lesser research data that can bring us a technical advantage.
Price Data: Specifically, the type of metrics or aspects of the stock that we will focus on include information such as the price data including the low/high and open/close prices.
Volume Data: We will also look at the volume at which a given stock is being traded. This is another very insightful metric related to stocks as this is related to price fluctuations and movements leading us to be able to further classify a stock’s riskiness and stability over time.
Market Breadth Indicators: Another important aspect of a stock’s inherent value is the overall health and stability of the stock market and a given stock’s performance relative to the stock market’s overall performance. In order to take market performance into account, we will analyze the number of advancing and declining shares, the highs and lows, and the price of stock market indexes (e.g. Dow Jones Industrial Average, Nasdaq Composite).
Volatility Measures: A stock’s volatility is a very important measure in a stock’s performance. We can look at the volatility of specific stocks and indexes and they provide insight into market sentiment and expectations for future price movements. Higher volatility can indicate increased uncertainty and risk in the market.
Potential Sources for Relevant Data Financial Data APIs: Alpha Vantage: Provides data such as stock prices, technical indicators, and fundamental data. Quandl: Stock prices, futures, options, economic indicators. Yahoo Finance: Historical price data, volume data, market breadth indicators. GitHub: Search for financial datasets used by other individuals with similar goals and do any necessary preprocessing.
Data Preprocessing Missing Data: Delete rows or columns with missing data or replace with reasonable estimate. Data Cleaning: Remove outliers or anomalies as well as anything that doesn’t seem very realistic. Data Normalization: Standardize data for easier model training and convergence. Links: https://www.kaggle.com/code/vuqarxxx/starter-huge-stock-market-dataset-cf10d29c-2/input
Methodology: Assume we are predicting the price of the S&P 500 index (or alternatively, whether it goes up or down). Then, each input is a 500-dimensional vector. We pass each input into a feed-forward layer to produce an embedding. Note that this isn’t entirely necessary because unlike in NLP tasks, the original input already exists in Euclidean space, but allowing the model to produce an embedding may result in it learning a more concise representation of the data.
Next, we pass each embedding through a masked multi-headed self-attention layer in order to determine the amount of attention each day’s price should pay to the preceding days’ prices. The output of this layer can either serve as the new embedding for each input, or it can serve as the context vector into each LSTM cell. It is unclear whether this will prove to be a useful approach because one could argue that the current price (and consequently, its embedding) is already an accumulation of the outcomes of the preceding days. However, a self-attention layer could help the model learn trends within the data and provide additional tunable parameters.
The output of the self-attention layer will then be fed into a series of standard LSTM layers. Between each layer will be an attention layer so that the model can, once again, pay attention to the relevant LSTM cells (i.e. relevant days) in predicting the next price. Finally, if we decide to frame the problem as a classification task, the output of the final LSTM layer will pass through a Softmax layer to provide a probability distribution over the two classes, namely whether the relevant stock/index price (e.g. S&P 500) will increase or decrease.
The paper we reference uses the Adam optimizer with a learning rate of 0.075, but we can tune based on our results. Our loss function will likely be categorical cross-entropy.
If the approach detailed above proves to be untenable, we may revert to a version closer to the one proposed in our reference paper, namely building a simplistic ensemble of LSTM layers. Alternatively, we could develop two versions of the model (i.e. the one described above and the one outlined in the paper) in order to determine the improvement incorporating attention has with respect to accuracy.
Metrics: Success Criteria
- Being able to accurately predict the stock direction (up or down) in order to use these predictions to signal profitable buy/sell decisions.
- Determining an estimate of how much the price will increase/decrease to optimize portfolio performance.
- Surpassing the Russell Benchmark Sharpe Ratio by 0.5% - 1%.
Experiments
- Experiment with various deep learning models and algorithms to compare performance in terms of accuracy.
- Experiment with different features and data sources to determine which is best for optimizing the prediction accuracy
- Conduct backtests using historical data to evaluate performance under different market conditions.
The optimization of our stock portfolio relies on the bot’s capacity for accurate stock price prediction, enabling us to make informed investment decisions for potential profit.
Base goals
- Accuracy: Achieve a minimum acceptable hit rate of 60% for buy/sell signals that ensures statistically significant outperformance (p-value < 0.05) compared to a random strategy.
- Design the bot to adapt to changing market conditions by incorporating mechanisms for model retraining and performance evaluation over time.
- Implement safeguards to prevent unintended consequences such as market manipulation or exploitation of vulnerability.
- Include a comprehensive documentation of the entire project lifecycle including model architecture and trading strategies.
Target Goal (Risk-Adjusted Return)
- Sharpe Ratio: Achieve a target Sharpe Ratio of 2.8 (exceeding the Russell 3000 benchmark by 0.49) with a 95% confidence interval of [2.6,3.0].
- For reference: --> The US Benchmark: Russell 3000 = 2.31% --> Global Benchmark: MSCI World = 3.15%
- Being within the average range is an indication of good strategy performance returns and demonstrates the bot’s ability to generate positive returns while managing risk effectively.
- Bot should be able to adjust portfolio composition based on market conditions and risk exposure, optimizing the diversification and hedging strategies.
Stretch Goals
- Outperformance: Consistently outperform the benchmark (Russell 3000 or MSCI) by %1.5 and indices over a period of time with a statistical significance of p-value < 0.03 This demonstrates the bot’s ability to generate alpha (excess return compared to the market).
- Incorporate Alternative Assets: Integrate other assets like cryptocurrencies for potential diversification benefits and risk management.
- Tax Optimization: Implement strategies to minimize tax liabilities.
- The bot can be programmed to be aware of the current tax bracket.
- If it’s nearing a higher tax bracket due to large gains, the bot could prioritize selling assets with losses to offset gains and stay in a lower bracket.
- It should be aware that if it’s near the end of the year and it’s sitting in a low bracket, the bot should realize some capital gains to maximize tax efficiency.
- Tracking the holding period allows for prioritizing the sale of assets that will qualify for long-term capital gains tax rates and balancing short-term and long-term gains to minimize tax impact.
- The bot should be aware of the Wash Sale Rule that doesn’t allow claiming of tax deduction for losses on security if one repurchases the same or substantially identical security within 30 days (before or after the sale). Essentially the bot should avoid repurchasing recently sold assets at a loss within this window.
Ethics: Why is Deep Learning a good approach to this problem?
LSTMs in particular have been shown to be effective with financial time series, with their ability to store long term information much better than other models. One of our possible plans, which is to use an ensemble of neural networks, will also help reduce variance significantly and allow our model to be more consistent. There are many examples of literature with similar ideas, such as our first link in related works.
What is your dataset? Are there any concerns about how it was collected, or labeled? Is it representative?
Our dataset is going to be the S&P 500. The data is readily available publicly and concerns about labeling are minimal. Although it makes up 80% of the total US equity market capitalization, it does provide less variety compared to the total market due to the lack of presence of smaller stocks. Overall, the S&P 500 does represent the market relatively well and gets rid of much of the variability that is present in small stocks, which are often boom or bust. It is also much easier to obtain data for than many of the smaller stocks in the total market share.
Division of Labor: Beenish: Model and architecture research. Will aid in researching how we can leverage the different architectures we have learned throughout the semester in order to make the best use of the data. This includes making decisions on things such as using an RNN over a CNN or using an LSTM rather than a GRU, coming up with which layers to use as well as how to stack and combine them for optimal performance.
Kevin: Data handling and accessing as well as any relevant preprocessing. Will deal with actually importing the relevant data that will be used for the model such as open/close prices, index performance, volume data, and market breadth indicators. Make sure that the API is correctly accessing the data. Works on feature engineering and coming up with which metrics are important for the model to take into account when deciding whether a stock will be bought or sold.
Oliver: Optimization expert. Helps determine which optimization algorithm to use as well as other techniques used to optimize deep learning models. Works with Kevin to come up with the best ways to preprocess the data for model performance, such as using normalization and standardization and other forms of testing model performance through the use of Monte Carlo simulations to optimize and refine trading strategies with regard to buy/sell signals.
Connie: Compilation of findings into paper and working on the presentation of our methodology, implementation, model performance, findings and more into our final write-up and slides/poster. Includes determining which metrics are appropriate for our specific model.
Isaac: Creation of GitHub repository as well as maintenance of working branches. Primarily in charge of writing the code for our implementation of our model using Python and its related libraries such as Tensorflow/Keras and Pandas. Works closely with Kevin, Oliver, and Beenish in order to implement model architecture, access and preprocess data, and test model in order to update weights and biases.
Log in or sign up for Devpost to join the conversation.