When you invest in stocks you want to get a high return, but a low risk. There's also going to be a few constraints. That sounds like a job for cvxpy.
If you appreciate a reminder on how to calculate the variance, feel free to check this wikipedia article.
Feedback? See an issue? Feel free to mention it here.
If you want to be kept up to date, consider getting the newsletter.