Share prices are a critical factor in a stock index’s worth but are never constant. Thus, an effective method of predicting share prices is needed. This is where machine learning comes in. This research discusses the applicability of machine learning algorithms, precisely long short-term memory, artificial neural networks, and linear regression in predicting share prices. Additionally, this research goes in-depth, explaining how each algorithm functions. These three algorithms were implemented using the financial dataset of the S&P 500, one of the more known stock indices out there. Data was collected from Yahoo Finance for 34 years, from 1990 to 2023. Then, the algorithms mentioned were used to train a model using the collected dataset. All three algorithms were measured using three performance metrics: mean absolute error, R-squared score, and mean absolute percentage error. The final implementation involved training them by only using 1-day lagged features to create a model that can predict the next day's closing price. All the algorithms performed considerably well, with linear regression being the best, followed by artificial neural networks and long short-term memory being the worst. Finally, the implemented algorithms were used to predict the closing prices of other stock indices, NASDAQ and Hang Seng Index. All algorithms performed well and followed the same trend, wherein linear regression performed the best and long- and short-term memory the worst. Future research should be conducted to explore the possibilities of utilizing lagged features along with external features like GDP growth rate, political trends, etc.