How to Implement a Multilayer Neural Network for Stock Return Prediction

Sep 25, 2020 | Data Science

Welcome to an enlightening journey into the realm of stock prediction using multilayer neural networks! In this guide, we’ll walk through the process of using an advanced implementation of stacked neural networks—essentially a multilayer model—to predict stock returns.

Overview

Engaging with machine learning in finance typically involves a systematic approach: acquiring data, preprocessing it, training models, testing them, and monitoring their performance. Here, we’ll enhance this workflow to suit our needs, especially when working with complex datasets such as tick data.

Quickstart

If you’re ready to dive in, here’s how to get the model up and running quickly:

bash
pip install -r requirements.txt
python run.py

Note: Due to file size restrictions on GitHub, only a portion of the data is available (1 million rows), which may result in discrepancies in the model output.

Bar Sampling

Directly using tick-level data often causes inaccurate results due to noise. Therefore, we utilize sampling methods (based on tick counts, trading volume, or dollar amounts) instead of conventional time sampling, which can lead to non-stationarities.

Feature Engineering

Once we have our sampled data (OHLCV), we can generate features that could enhance predictability. Features based on moving averages and rolling volatilities have been constructed to aid in our forecasting efforts.

Understanding Stacked Autoencoders

Consider this: you have a huge sketchbook full of diverse doodles, but you want to show only the best parts in a gallery. A stacked autoencoder acts as a highly selective curator for your data. When trained, it compresses this wealth of information into a more manageable form while retaining only the essential elements, creating valuable features for training other models.

Neural Network Model

In this implementation, a Long Short-Term Memory (LSTM) model harnesses its memory to predict future stock prices. There may be hurdles along the way, like the model settling into a constant due to local minima. To counteract this, try experimenting with different weight initializations and tuning hyperparameters.

Random Forest Model

Sometimes, simpler models outperform complex neural networks—especially when the dataset is relatively small. The Random Forest model classifies the direction of movement based on features derived from tick level data, ensuring robust predictions even with limited training data.

Results

The stacked neural network strategy has yielded interesting results. Here’s how the predictions match up with actual market prices:


EURUSD prices - R^2: 0.90

This showcases a performance tangent to our expectations!

Online Learning

In a traditional setup, training halts after the model processes historical data. However, an adapted approach allows the model to continue learning from new (prediction, actual) pairs, improving its accuracy over time.

What’s Next?

The beauty of this architecture lies in its adaptability; as we understand the core structure, interchangeable components can enhance performance. Future improvements may include sample weights, cross-validation, and ensemble techniques, all inspired by the insightful Advances in Financial Machine Learning.

Troubleshooting

If you encounter issues during implementation or have questions about the approach, here are a couple of ideas:

  • Ensure you’re using Python 3 to avoid compatibility issues.
  • Check your data format—mismatches can lead to erroneous results.
  • Consider adjusting the hyperparameters of the machine learning models if results are subpar.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

This journey through multilayer neural networks for stock return prediction has hopefully illuminated some enlightening concepts along the way. Engage, modify, and appreciate the intricacies of financial machine learning!

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox