"CONSTRUCTION OF STOCK PORTFOLIOS BY MACHINE LEARNING METHODS" by Alfan Gehad Abulehia

Date of Award

4-2025

Document Type

Thesis

Degree Name

Master of Science in Mathematics

Department

Mathematical Sciences

First Advisor

Ho Hon Leung

Abstract

We study the theory and application of two machine learning (ML) algorithms: Long-Short Term Memory Network (LSTM) and Random Forest. The study begins by providing an overview of mathematical foundation, highlighting the significance of mathematics in machine learning. We study and explain the mathematical details involved in these two algorithms. We also study closely related subjects which include but not limited to gradient descent, automatic differentiation, and recurrent neural network. The main ideas behind these topics form the foundation of any ML algorithms.

As an application of the ML algorithms, we focus on the U.S. stock market. We build stock portfolios by various strategies which are primarily based on LSTM and Random Forest. This thesis can be viewed as an application of machine learning to the field of stock market analysis. The stock portfolios are constructed based on certain degree of diversification across diverse industries in the U.S. economy and fixing a specified number of stocks throughout the backtesting period we considered. We use either technical indicators or fundamental indicators as the input features to the ML algorithms for each stock. We predict the stock price of each stock based on various strategies. We rank the stocks based on the predicted return in a given trading year and select the top stocks as our porfolios for the year. We do re-balancing in each year based on the same strategies for all the stock portfolios during the backtesting period.

We compare how these stock portfolios perform against market indices like S&P 500. The performance of a stock portfolio is measured by its compounded annual growth rate (CAGR). We check and analyze whether the chosen machine learning algorithms can be valuable tools for picking stocks based on historical stock data. We determine if the stock portfolios constructed could consistently outperform the market benchmark over the chosen backtesting period. We present these results and analyze the strategies in details. We discuss possibilities of extending the main ideas contained in this thesis for future work.

Arabic Abstract


بناء محافظ الأسهم عن طريق التعلم الآلي

نحن ندرس نظرية وتطبيق خوارزميتين من خوارزميات التعلم الآلي (ML): شبكة الذاكرة طويلة وقصيرة المدى (LSTM) وغابة القرارات العشوائية (Random Forest). يبدأ البحث بتقديم لمحة عامة عن الأساس الرياضي، مسلطا الضوء على أهمية الرياضيات في التعلم الآلي. نقوم بدراسة وشرح التفاصيل الرياضية المتضمنة في هاتين الخوارزميتين. كما ندرس مواضيع ذات صلة وثيقة تشمل على سبيل المثال لا الحصر، نزول التدرج (Gradient Descent)، التفاضل التلقائي (Automatic Differentiation)، والشبكة العصبية المتكررة (Recurrent Neural Network). تشكل الأفكار الأساسية وراء هذه المواضيع الأساس لأي خوارزمية تعلم آلي.

كأحد تطبيقات خوارزميات التعلم الآلي نركز على سوق الأسهم الأمريكية. نقوم ببناء محافظ استثمارية باستخدام استراتيجيات مختلفة تعتمد بشكل أساسي على شبكة الذاكرة طويلة وقصيرة المدى (LSTM) وغابة القرارات العشوائية (Random Forest). يمكن اعتبار هذه الأطروحة كتطبيق للتعلم الآلي في مجال تحليل سوق الأسهم. يتم إنشاء المحافظ الاستثمارية بناءً على درجة معينة من التنويع عبر مختلف الصناعات في الاقتصاد الأمريكي، مع تثبيت عدد محدد من الأسهم خلال فترة الاختبار التاريخي التي تمت دراستها. نستخدم إما المؤشرات الفنية أو المؤشرات الأساسية كمدخلات لخوارزميات التعلم الآلي لكل سهم. نقوم بتوقع سعر كل سهم بناءً على استراتيجيات مختلفة، ثم نصنف الأسهم وفقًا للعائد المتوقع في سنة تداول معينة، ونختار أفضل الأسهم لتشكيل المحافظ الاستثمارية السنوية. نقوم بإعادة التوازن سنويًا وفقًا لنفس الاستراتيجيات لجميع المحافظ الاستثمارية خلال فترة الاختبار التاريخي.

نقارن أداء هذه المحافظ الاستثمارية مع مؤشرات السوق مثل 500 S&P. يتم قياس أداء المحفظة الاستثمارية من خلال معدل النمو السنوي المركب (CAGR). نتحقق من مدى فعالية خوارزميات التعلم الآلي المختارة في اختيار الأسهم بناءً على بيانات السوق التاريخية. نحدد ما إذا كانت المحافظ الاستثمارية التي تم إنشاؤها يمكن أن تتفوق باستمرار على المؤشر المرجعي للسوق خلال فترة الاختبار المختارة. نقدم هذه النتائج ونحلل الاستراتيجيات بالتفصيل. كما نناقش إمكانيات توسيع الأفكار الرئيسية الواردة في هذه الأطروحة للعمل المستقبلي.

Included in

Mathematics Commons

COinS