Creation and deployment of an LSTM model which predicts the optimal Sharpe ratio of a given stock universe

Use Case: Predicting Optimal Sharpe Maximized Stock Selection for Vios Investing

Client: Vios Investing (Taiwan)

Overview:

Vios Investing, a leading investment firm in Taiwan, sought to enhance their stock selection strategy by predicting the optimal Sharpe maximized selection of stocks listed on the Taiwan Stock Exchange (TWSE). By leveraging advanced statistical techniques and deep learning models, the goal was to improve their investment returns and achieve superior risk-adjusted performance.

Objective:

To develop a predictive model using LSTM (Long Short-Term Memory) networks to forecast future stock weights that maximize the Sharpe ratio, thereby enhancing investment decisions. The solution needed to be robust, scalable, and deployable within Vios Investing’s existing infrastructure.


Solution Design Process:

  1. Requirement Analysis:
    • Collaborated with Vios Investing’s financial analysts and IT team to understand their specific requirements and objectives.
    • Identified key performance metrics, including the Sharpe ratio, and the constraints of the TWSE market.
  2. Data Preparation:
    • Collected historical stock data from the TWSE, focusing on price movements, trading volumes, and other relevant financial indicators.
    • Applied statistical enhancements and denoising techniques to clean and preprocess the data, ensuring high-quality inputs for the model.
  3. Model Development:
    • Developed an LSTM model to predict future stock weights aimed at maximizing the Sharpe ratio.
    • Implemented the model using Python and deep learning libraries, ensuring robustness and accuracy.
  4. Backtesting and Validation:
    • Conducted extensive backtesting using historical data to validate the model’s performance.
    • Evaluated the model’s ability to achieve superior risk-adjusted returns, with a particular focus on achieving a high alpha over the TWSE index.
  5. Deployment:
    • Packaged the final model into a Docker image for easy deployment.
    • Deployed the Dockerized model on a Kubernetes cluster, leveraging GPU acceleration for efficient model inference.
    • Ensured the solution was scalable and could handle real-time data inputs for ongoing predictions.

Implementation:

  1. Infrastructure Setup:
    • Set up a Kubernetes cluster with GPU support to provide the necessary computational power for the LSTM model.
    • Deployed the Docker image containing the predictive model to the Kubernetes cluster, ensuring seamless integration with Vios Investing’s existing infrastructure.
  2. Model Training and Tuning:
    • Trained the LSTM model on preprocessed historical data, fine-tuning hyperparameters to optimize performance.
    • Incorporated feedback from initial test runs to refine the model and improve prediction accuracy.
  3. Backtesting Results:
    • Ran extensive backtests using demo data to simulate real-world trading scenarios.
    • Achieved an alpha of 22 points per year over the TWSE index, indicating a promising enhancement in investment performance.
  4. Ongoing Testing:
    • Provided Vios Investing with the deployed model for further testing and validation on live data.
    • Established a feedback loop to continuously monitor model performance and make necessary adjustments.

Results and Impact:

  • Alpha Generation: The backtesting results demonstrated an impressive alpha of 22 points per year over the TWSE index, highlighting the model’s potential to significantly enhance investment returns.
  • Sharpe Ratio Optimization: Successfully developed a predictive model that optimizes stock weights to maximize the Sharpe ratio, providing superior risk-adjusted returns.
  • Scalable Deployment: Deployed the model using Docker and Kubernetes, ensuring scalability, reliability, and efficient use of computational resources.
  • Real-Time Predictions: Enabled Vios Investing to leverage real-time data for ongoing predictions, enhancing their trading strategies and decision-making process.

Conclusion:

The project resulted in a highly effective predictive model for Vios Investing, leveraging advanced statistical techniques and deep learning to optimize stock selection on the TWSE. By achieving a significant alpha over the index, the solution promises to enhance the firm’s investment performance. The scalable deployment on Kubernetes with GPU support ensures that Vios Investing can continue to leverage cutting-edge technology for superior investment outcomes.

    Did you know, that we are sending out a bi-weekly newsletter with the newest Data Engineering, DevOps and AI tips that we are working on? Be the first to be notified of how we have solved a problem. Unsubscribe at any time.

    Are you planning on employing machine learning to predict time series models? Contact us now for a free consultation.

      Open Source contributions on Github to the Google Research "TimesFM" project.

      https://github.com/google-research/timesfm

      https://research.google/blog/a-decoder-only-foundation-model-for-time-series-forecasting/

      Project Summary: Enhancing the Google Research TimesFM Project with CI/CD and Python Poetry

      Open Source Contribution: Continuous Integration/Continuous Deployment (CI/CD) and Dependency Management for TimesFM

      Project Overview:

      TimesFM is an advanced forecasting model developed by Google Research, pre-trained on a vast corpus of 100 billion real-world time-points. It delivers impressive zero-shot performance across various public benchmarks from multiple domains and granularities. This model stands out in time-series forecasting, which is critical in industries such as retail, finance, manufacturing, healthcare, and natural sciences. TimesFM is particularly impactful in retail, where accurate demand forecasting can significantly reduce inventory costs and boost revenue.

      Despite its robust performance, TimesFM faced challenges common to many deep learning (DL) models: the need for extensive training and validation cycles before deployment. To address this, TimesFM was designed as a foundation model that offers strong out-of-the-box forecasting capabilities on new time-series data without additional training. This allows users to quickly implement and refine forecasts for specific tasks, such as retail demand planning.

      My Contributions:

      To further enhance the usability and accessibility of TimesFM, I contributed to the project by implementing a Continuous Integration/Continuous Deployment (CI/CD) pipeline using GitHub Actions and integrating Python Poetry for dependency management and packaging. These contributions aimed to simplify the installation process and streamline development workflows.

      Key Enhancements:

      1. CI/CD Pipeline with GitHub Actions:
        • Automation: Automated the testing, building, and deployment processes, ensuring that any changes to the codebase are verified through a consistent and reliable workflow.
        • Quality Assurance: Enhanced code quality by running automated tests on each pull request, catching issues early in the development cycle.
        • Deployment: Streamlined the deployment process, allowing for faster and more reliable updates to the TimesFM model.
      2. Python Poetry Integration:
        • Simplified Installation: Enabled users to install TimesFM more easily with a single command (pip install timesfm), reducing the friction for new users and developers.
        • Dependency Management: Improved dependency management by using Poetry, which handles package dependencies more efficiently and ensures that the correct versions are used.
        • Reproducibility: Enhanced the reproducibility of the development environment, making it easier for contributors to set up and maintain their development setups.

      Impact of Contributions:

      • Ease of Use: Lowered the barrier to entry for new users and contributors, making it simpler to get started with TimesFM.
      • Improved Productivity: By automating routine tasks and ensuring a consistent development environment, developers can focus more on innovation and less on setup and maintenance.
      • Enhanced Collaboration: The automated CI/CD pipeline fosters a more collaborative and efficient development process, where code changes are continuously integrated and tested.

      About TimesFM:

      TimesFM represents a significant advancement in time-series forecasting. It is much smaller than the latest large language models (200M parameters) yet achieves near state-of-the-art performance on a variety of unseen datasets. This makes it a powerful tool for industries that rely on accurate time-series predictions.

      For more information and to access the model, please visit the HuggingFace and GitHub repositories.


      Conclusion:

      My contributions to the TimesFM project have significantly enhanced its usability and development efficiency. By implementing a CI/CD pipeline and integrating Python Poetry, I have helped streamline workflows and make the model more accessible to users and developers. These improvements support the ongoing success of TimesFM in providing robust, zero-shot forecasting capabilities across various domains.

        Did you know, that we are sending out a bi-weekly newsletter with the newest Data Engineering, DevOps and AI tips that we are working on? Be the first to be notified of how we have solved a problem. Unsubscribe at any time.

        Contact us for a free 15 minute consultation