Portfolio optimization involves finding the optimal allocation for a portfolio tomaximize return while minimizing risk. This process varies assets across differentsectors, causing low correlation between them and thus reducing overall risk whilesacrificing only a small portion of the return. This thesis focuses on risk control,aiming to find the minimum risk for a specified return. We accomplish this using twomodels. Model 1 solves a deterministic mean-variance problem, while Model 2 solvesa stochastic problem consisting of sampled scenarios. Both models are designed todetermine the optimal composition of stocks under various constraints. The modelsare implemented in Python using the Gurobi API, and data are collected usingthe Yahoo Finance Python API. We will explain theoretical topics in optimizationtheory, including Mixed Integer Quadratic Programming, the Big-M method, andstochastic portfolio optimization problems. We also examine financial theory, suchas the efficient frontier. Finally, we analyze and discuss different variables and theireffects to provide a clear picture of model performance, thereby illustrating theapplication of optimization theory and its importance in various areas.