The prediction of stock performance is a crucial component in formulating investment portfolios and optimizing portfolios within the realm of quantitative trading. However, the inherent unpredictability and volatility of the stock market pose significant obstacles for investors in accurately predicting stock performance. To build an optimal portfolio, the LSTM model is selected as a forecasting technique. Subsequently, data sourced from Yahoo Finance is acquired for training and testing purposes. Based on the prediction data, the paper applies the maximum Sharpe ratio model and the minimum variance model to reach portfolio optimization. Finally, the paper uses the S&P 500 index as a standard to evaluate the constructed portfolio. The results indicate that the LSTM prediction model has effective functionality and exhibits superior performance in the domain of data forecasting. In addition, the minimum-variance optimization and the maximum Sharpe ratio models explore optimized return and minimized risk in portfolio construction. The constructed portfolio outperforms the S&P 500 in terms of risks and returns. Therefore, the results in the paper are good for investors to reduce risk and increase return in portfolio construction.